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 10fc4a6 commit 908c05e
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 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 @@ -38,7 +41,21 @@ function createApolloClient() {
httpLink, // if test is true, debatch
batchHttpLink // otherwise, batch
);
const link = ApolloLink.from([errorLink, splitLink]);

function createIsomorphLink() {
if (typeof window === 'undefined') {
console.log('blah');
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 908c05e

@vercel
Copy link

@vercel vercel bot commented on 908c05e Nov 3, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

all-the-things – ./

all-the-things-git-main-mimecuvalo.vercel.app
all-the-things.vercel.app
all-the-things-mimecuvalo.vercel.app

Please sign in to comment.