I were checking dependencies and noticed Type-graphql is based on Express and apollo-server-express.
How hard would it be to switch to a faster Node framework like Fastify (and apollo-server-fastify) ?
TypeGraphQL depends only on graphql-js and produce only a GraphQLSchema.
So you can use Express, Fastify, Websockets, MQTT or even TCP to expose the graphql api to the world. It's all your choice which integration library (apollo-server-fastify) you will use 馃槈
I'm doing like this.
// schema.ts
import { buildSchema } from 'type-graphql'
import { Container } from 'typedi'
import { QueryResolver } from './resolvers/QueryResolver'
import { MutationResolver } from './resolvers/MutationResolver'
export const getSchema = () =>
buildSchema({
resolvers: [QueryResolver, MutationResolver],
emitSchemaFile: true,
container: Container,
})
// graphqlPlugin.ts
import { getSchema } from './schema'
import { graphql } from 'graphql'
import { FastifyPluginAsync } from 'fastify'
const graphqlPlugin: FastifyPluginAsync = async (app) => {
const schema = await getSchema()
app.post<{ Body: { query: string; variables?: object } }>(
'/',
async (request, reply) => {
const res = await graphql({
schema,
source: request.body.query,
variableValues: request.body.variables,
contextValue: {},
})
reply.send(res)
},
)
}
Most helpful comment
I'm doing like this.