Skip to content

Commit

Permalink
fix: reunify apollo setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Rupert Redington committed Nov 22, 2021
1 parent fa4ce93 commit e11552a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 73 deletions.
18 changes: 0 additions & 18 deletions codegen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,3 @@ generates:
typesPath: ./graphql
plugins:
- graphql-codegen-apollo-next-ssr
src/api-client/staticPage.tsx:
config:
documentMode: external
importDocumentNodeExternallyFrom: ./graphql
reactApolloVersion: 3
withHooks: true
# withHOC: false
# excludePatterns: 'getComments'
# excludePatternsOptions: 'i'
# customDataIdFromObjectName: 'test'
# customDataIdFromObjectImport: 'abc'
apolloClientInstanceImport: '../components/withStaticApollo'
# apolloStateKey: '__APOLLO_STATE__'
preset: import-types
presetConfig:
typesPath: ./graphql
plugins:
- graphql-codegen-apollo-next-ssr
5 changes: 5 additions & 0 deletions src/api-client/graphql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ export type AuthedContributor = {
name: Scalars['String'];
};

export enum CacheControlScope {
Private = 'PRIVATE',
Public = 'PUBLIC'
}

/** A piece of proportional data, with a name and a value */
export type Chunk = {
__typename?: 'Chunk';
Expand Down
26 changes: 17 additions & 9 deletions src/components/withApollo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,26 @@ export const getApolloClient = (
ctx?: ApolloClientContext,
initialState?: NormalizedCacheObject
) => {
const url =
process.env.NODE_ENV === 'development'
? process.env.AUTH0_BASE_URL
: process.env.VERCEL_URL;
const httpLink = createHttpLink({
uri: typeof window === 'undefined' ? url + '/api' : '/api',
fetch,
});
let link;
if (typeof window === 'undefined') {
const { SchemaLink } = require('@apollo/client/link/schema');
const { schema } = require('../pages/api');
link = new SchemaLink({ schema });
} else {
const url =
process.env.NODE_ENV === 'development'
? process.env.AUTH0_BASE_URL
: process.env.VERCEL_URL;
link = createHttpLink({
uri: typeof window === 'undefined' ? url + '/api' : '/api',
fetch,
});
}

const cache = new InMemoryCache().restore(initialState || {});
return new ApolloClient({
link: httpLink,
ssrMode: typeof window === 'undefined',
link,
cache,
});
};
26 changes: 0 additions & 26 deletions src/components/withStaticApollo.tsx

This file was deleted.

20 changes: 0 additions & 20 deletions src/looCache.ts

This file was deleted.

0 comments on commit e11552a

Please sign in to comment.