@kazion/create-app
Version:
A cli tool to help you get started with graphql and rest api's with typescript
35 lines (30 loc) • 798 B
text/typescript
import { ApolloServer, type BaseContext } from '@apollo/server'
import fastifyApollo, {
fastifyApolloDrainPlugin,
} from '@as-integrations/fastify'
import Fastify from 'fastify'
import { useServer } from 'graphql-ws/lib/use/ws'
import { WebSocketServer } from 'ws'
import { schema } from '~/_graphql'
const app = Fastify()
const wsServer = new WebSocketServer({
server: app.server,
path: '/graphql',
})
const serverCleanup = useServer({ schema }, wsServer)
const apolloServer = new ApolloServer<BaseContext>({
schema,
plugins: [
fastifyApolloDrainPlugin(app),
{
async serverWillStart() {
return {
async drainServer() {
await serverCleanup.dispose()
},
}
},
},
],
})
export { apolloServer, app, fastifyApollo }