stacker.news/api/client.js

27 lines
761 B
JavaScript
Raw Normal View History

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'
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
}
}),
cache: new InMemoryCache()
})
}