fastify-graphql-middleware
Installation
npm install fastify-graphql-middleware
yarn add fastify-graphql-middleware
Usage
install body-parser at first.
Example:
import { MiddlewareConsumer, Module, NestModule } from "@nestjs/common";
import { GraphQLFactory, GraphQLModule } from "@nestjs/graphql";
@Module({
imports: [GraphQLModule],
})
export class ApplicationModule implements NestModule {
constructor(private readonly graphQLFactory: GraphQLFactory) { }
configure(consumer: MiddlewareConsumer) {
const typeDefs = this.graphQLFactory.mergeTypesByPaths("./**/*.graphql");
const schema = this.graphQLFactory.createSchema({ typeDefs });
consumer
.apply(graphiQLFastify({ endpointURL: "/graphql" }))
.forRoutes("/graphiql")
.apply(bodyParser.json())
.forRoutes("/graphql")
.apply(graphQLFastify(req => ({ schema, rootValue: req })))
.forRoutes("/graphql");
}
}