stacker.news/pages/api/graphql.js

31 lines
698 B
JavaScript
Raw Normal View History

2021-03-25 19:29:24 +00:00
import { ApolloServer } from 'apollo-server-micro'
import resolvers from '../../api/resolvers'
import models from '../../api/models'
2021-04-29 21:58:43 +00:00
import lnd from '../../api/lnd'
2021-03-25 19:29:24 +00:00
import typeDefs from '../../api/typeDefs'
2021-04-12 18:05:09 +00:00
import { getSession } from 'next-auth/client'
2022-01-26 15:35:14 +00:00
import search from '../../api/search'
2021-03-25 19:29:24 +00:00
2021-09-30 15:46:58 +00:00
global.apolloServer ||= new ApolloServer({
2021-03-25 19:29:24 +00:00
typeDefs,
resolvers,
2021-04-29 15:56:28 +00:00
tracing: true,
2021-04-12 18:05:09 +00:00
context: async ({ req }) => {
const session = await getSession({ req })
return {
models,
2021-04-29 21:58:43 +00:00
lnd,
2022-01-26 15:35:14 +00:00
me: session ? session.user : null,
search
2021-04-12 18:05:09 +00:00
}
}
2021-03-25 19:29:24 +00:00
})
export const config = {
api: {
bodyParser: false
}
}
2021-09-30 15:46:58 +00:00
export default global.apolloServer.createHandler({ path: '/api/graphql' })