fastify-graphql-middleware
TypeScript icon, indicating that this package has built-in type declarations

2.1.1 • Public • Published

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");
    }
}

Readme

Keywords

Package Sidebar

Install

npm i fastify-graphql-middleware

Weekly Downloads

0

Version

2.1.1

License

Apache-2.0

Unpacked Size

9.31 kB

Total Files

11

Last publish

Collaborators

  • duanzeyao