diff --git a/examples/app-dir-experiments/app/ApolloClient.ts b/examples/app-dir-experiments/app/ApolloClient.ts index c9b7b553..7db89de6 100644 --- a/examples/app-dir-experiments/app/ApolloClient.ts +++ b/examples/app-dir-experiments/app/ApolloClient.ts @@ -1,14 +1,11 @@ -import { ApolloClient, HttpLink, InMemoryCache } from "@apollo/client"; +import { ApolloClient, InMemoryCache } from "@apollo/client"; +import { SchemaLink } from "@apollo/client/link/schema"; import { registerApolloClient } from "@apollo/experimental-nextjs-app-support/rsc"; +import { schema } from "./api/graphql/route"; export const { getClient } = registerApolloClient(() => { return new ApolloClient({ cache: new InMemoryCache(), - link: new HttpLink({ - uri: "http://localhost:3000/api/graphql", - // you can disable result caching here if you want to - // (this does not work if you are rendering your page with `export const dynamic = "force-static"`) - // fetchOptions: { cache: "no-store" }, - }), + link: new SchemaLink({ schema }), }); }); diff --git a/examples/app-dir-experiments/app/api/graphql/route.ts b/examples/app-dir-experiments/app/api/graphql/route.ts index 6842883a..1d8726f0 100644 --- a/examples/app-dir-experiments/app/api/graphql/route.ts +++ b/examples/app-dir-experiments/app/api/graphql/route.ts @@ -1,5 +1,6 @@ import { startServerAndCreateNextHandler } from "@as-integrations/next"; import { ApolloServer } from "@apollo/server"; +import { makeExecutableSchema } from "@graphql-tools/schema"; import { gql } from "graphql-tag"; const typeDefs = gql` @@ -37,9 +38,13 @@ const resolvers = { }, }; -const server = new ApolloServer({ - resolvers, +export const schema = makeExecutableSchema({ typeDefs, + resolvers, +}); + +const server = new ApolloServer({ + schema, }); const handler = startServerAndCreateNextHandler(server); diff --git a/examples/app-dir-experiments/app/ssr/ApolloWrapper.tsx b/examples/app-dir-experiments/app/ssr/ApolloWrapper.tsx index cb52c1f9..35b0893a 100644 --- a/examples/app-dir-experiments/app/ssr/ApolloWrapper.tsx +++ b/examples/app-dir-experiments/app/ssr/ApolloWrapper.tsx @@ -6,21 +6,18 @@ import { HttpLink, SuspenseCache, } from "@apollo/client"; +import { SchemaLink } from "@apollo/client/link/schema"; import { ApolloNextAppProvider, NextSSRInMemoryCache, SSRMultipartLink, } from "@apollo/experimental-nextjs-app-support/ssr"; import { setVerbosity } from "ts-invariant"; +import { schema } from "../api/graphql/route"; setVerbosity("debug"); function makeClient() { - const httpLink = new HttpLink({ - uri: "http://localhost:3000/api/graphql", - fetchOptions: { cache: "no-store" }, - }); - return new ApolloClient({ cache: new NextSSRInMemoryCache(), link: @@ -29,9 +26,14 @@ function makeClient() { new SSRMultipartLink({ stripDefer: true, }), - httpLink, + new SchemaLink({ + schema, + }), ]) - : httpLink, + : new HttpLink({ + uri: "http://localhost:3000/api/graphql", + fetchOptions: { cache: "no-store" }, + }), }); }