36 lines
726 B
TypeScript
36 lines
726 B
TypeScript
import {
|
|
ApolloClient,
|
|
ApolloLink,
|
|
HttpLink,
|
|
InMemoryCache,
|
|
} from "@apollo/client";
|
|
import {
|
|
NextSSRApolloClient,
|
|
NextSSRInMemoryCache,
|
|
SSRMultipartLink,
|
|
} from "@apollo/experimental-nextjs-app-support/ssr";
|
|
|
|
export const apolloClient = new ApolloClient({
|
|
uri: "/api/graphql",
|
|
cache: new InMemoryCache(),
|
|
});
|
|
|
|
export function makeApolloClient() {
|
|
const httpLink = new HttpLink({
|
|
uri: "/api/graphql",
|
|
});
|
|
|
|
return new NextSSRApolloClient({
|
|
cache: new NextSSRInMemoryCache(),
|
|
link:
|
|
typeof window === "undefined"
|
|
? ApolloLink.from([
|
|
new SSRMultipartLink({
|
|
stripDefer: true,
|
|
}),
|
|
httpLink,
|
|
])
|
|
: httpLink,
|
|
});
|
|
}
|