Skip to content

dzzzzzy/fastify-graphql-middleware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fastify-graphql-middleware

Installation

# npm install
npm install fastify-graphql-middleware

# yarn add
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";
import { fastifyGraphiQL, fastifyGraphQL } from "fastify-graphql-middleware";
import * as bodyParser from "body-parser";

@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(fastifyGraphiQL({ endpointURL: "/graphql" }))
            .forRoutes("/graphiql")
            .apply(bodyParser.json())
            .forRoutes("/graphql")
            .apply(fastifyGraphQL(req => ({ schema, rootValue: req })))
            .forRoutes("/graphql");
    }
}

About

nestjs fastify-graphql middleware.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors