Skip to content

Commit

Permalink
graphql: isomorphlink
Browse files Browse the repository at this point in the history
  • Loading branch information
mimecuvalo committed Nov 3, 2023
1 parent 732b653 commit 4c4e093
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion app/apollo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import { ApolloClient, ApolloLink, HttpLink, InMemoryCache, NormalizedCacheObjec
import { clientCache, dataIdFromObject } from 'data/localState';

import { BatchHttpLink } from '@apollo/client/link/batch-http';
import { SchemaLink } from '@apollo/client/link/schema';
import isEqual from 'lodash/isEqual';
import merge from 'deepmerge';
import { onError } from '@apollo/client/link/error';
import resolvers from 'data/resolvers';
import schema from 'data/schema';
import { useMemo } from 'react';
import { makeExecutableSchema } from '@graphql-tools/schema';

export const APOLLO_STATE_PROP_NAME = '__APOLLO_STATE__';

Expand Down Expand Up @@ -42,7 +45,20 @@ function createApolloClient(headers?: { [key: string]: string }) {
httpLink, // if test is true, debatch
batchHttpLink // otherwise, batch
);
const link = ApolloLink.from([errorLink, splitLink]);

function createIsomorphLink() {
if (typeof window === 'undefined') {
const executableSchema = makeExecutableSchema({
typeDefs: schema,
resolvers,
});
return new SchemaLink({ schema: executableSchema });
} else {
return ApolloLink.from([errorLink, splitLink]);
}
}

const link = createIsomorphLink();

return new ApolloClient({
ssrMode: typeof window === 'undefined',
Expand Down

1 comment on commit 4c4e093

@vercel
Copy link

@vercel vercel bot commented on 4c4e093 Nov 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.