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
|
|
|
|
2022-04-27 22:06:42 +00:00
|
|
|
const plugin = {
|
|
|
|
serverWillStart (ctx) {
|
|
|
|
console.log('gql server starting up')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const apolloServer = new ApolloServer({
|
2021-03-25 19:29:24 +00:00
|
|
|
typeDefs,
|
|
|
|
resolvers,
|
2022-04-27 22:06:42 +00:00
|
|
|
plugins: [plugin],
|
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-04-21 22:50:02 +00:00
|
|
|
me: session
|
|
|
|
? await models.user.findUnique({ where: { id: session.user?.id } })
|
|
|
|
: null,
|
2022-01-26 15:35:14 +00:00
|
|
|
search
|
2021-04-12 18:05:09 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-25 19:29:24 +00:00
|
|
|
})
|
|
|
|
|
2022-04-27 22:06:42 +00:00
|
|
|
module.exports = apolloServer.start().then(() => apolloServer.createHandler({ path: '/api/graphql' }))
|