2021-04-14 23:56:29 +00:00
|
|
|
import { ApolloClient, InMemoryCache } from '@apollo/client'
|
|
|
|
import { SchemaLink } from '@apollo/client/link/schema'
|
|
|
|
import { mergeSchemas } from 'graphql-tools'
|
|
|
|
import { getSession } from 'next-auth/client'
|
|
|
|
import resolvers from './resolvers'
|
|
|
|
import typeDefs from './typeDefs'
|
|
|
|
import models from './models'
|
|
|
|
|
2021-04-26 21:55:15 +00:00
|
|
|
export default async function serverSideClient (req) {
|
|
|
|
const session = await getSession({ req })
|
|
|
|
return new ApolloClient({
|
|
|
|
ssrMode: true,
|
|
|
|
// Instead of "createHttpLink" use SchemaLink here
|
|
|
|
link: new SchemaLink({
|
|
|
|
schema: mergeSchemas({
|
|
|
|
schemas: typeDefs,
|
|
|
|
resolvers: resolvers
|
|
|
|
}),
|
|
|
|
context: {
|
2021-04-14 23:56:29 +00:00
|
|
|
models,
|
|
|
|
me: session ? session.user : null
|
|
|
|
}
|
2021-04-26 21:55:15 +00:00
|
|
|
}),
|
|
|
|
cache: new InMemoryCache()
|
|
|
|
})
|
|
|
|
}
|