diff --git a/.dependabot/config.yml b/.dependabot/config.yml new file mode 100644 index 00000000..dbf96cc3 --- /dev/null +++ b/.dependabot/config.yml @@ -0,0 +1,5 @@ +version: 1 +update_conigs: + - package_manager: "javascript" + directory: "/" + update_schedule: "daily" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..38ce605a --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,18 @@ +name: CI workflow +on: [push, pull_request] +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [10.x, 12.x, 14.x] + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - name: Install Dependencies + run: npm install --ignore-scripts + - name: Test + run: npm test diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 192afe49..00000000 --- a/.travis.yml +++ /dev/null @@ -1,11 +0,0 @@ -language: node_js - -node_js: - - "13" - - "12" - - "10" - -notifications: - email: - on_success: never - on_failure: always diff --git a/README.md b/README.md index 8e52e5df..6ba2b5b6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # fastify-gql -[![Build Status](https://travis-ci.com/mcollina/fastify-gql.svg?branch=master)](https://travis-ci.com/mcollina/fastify-gql) +![CI workflow](https://github.com/fastify/fastify-oauth2/workflows/CI%20workflow/badge.svg) Fastify GraphQL adapter. diff --git a/index.d.ts b/index.d.ts index 5c90ee65..1417b649 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,11 +1,9 @@ -import fastify, { FastifyError, FastifyReply, FastifyRequest, RegisterOptions } from "fastify"; -import { DocumentNode, ExecutionResult, GraphQLSchema, Source, GraphQLResolveInfo, GraphQLIsTypeOfFn, GraphQLTypeResolver, GraphQLScalarType, ValidationRule } from 'graphql'; -import { IncomingMessage, Server, ServerResponse } from "http"; -import { Http2Server, Http2ServerRequest, Http2ServerResponse } from 'http2'; +import { FastifyError, FastifyReply, FastifyRequest, FastifyInstance, RawServerBase, RawRequestDefaultExpression, RawReplyDefaultExpression, RegisterOptions } from "fastify"; +import { DocumentNode, ExecutionResult, GraphQLSchema, Source, GraphQLResolveInfo, GraphQLIsTypeOfFn, GraphQLTypeResolver, GraphQLScalarType, ValidationRule } from 'graphql'; declare namespace fastifyGQL { - export interface Plugin { + export interface Plugin { /** * Replace existing schema * @param schema graphql schema @@ -33,7 +31,7 @@ declare namespace fastifyGQL { params: any }>, context: { - reply: FastifyReply + reply: FastifyReply }) => any } }): void; @@ -43,11 +41,7 @@ declare namespace fastifyGQL { schema: GraphQLSchema; } - export interface Options< - HttpServer extends (Server | Http2Server) = Server, - HttpRequest extends (IncomingMessage | Http2ServerRequest) = IncomingMessage, - HttpResponse extends (ServerResponse | Http2ServerResponse) = ServerResponse - > extends RegisterOptions { + export interface Options { /** * The GraphQL schema. String schema will be parsed */ @@ -67,7 +61,7 @@ declare namespace fastifyGQL { params: any }>, context: { - reply: FastifyReply + reply: FastifyReply }) => any } }, @@ -107,19 +101,19 @@ declare namespace fastifyGQL { */ errorHandler?: boolean | (( error: FastifyError, - request: FastifyRequest, - reply: FastifyReply + request: FastifyRequest, + reply: FastifyReply ) => ExecutionResult), /** * The maximum depth allowed for a single query. */ queryDepth?: number, + context?: (request: FastifyRequest, reply: FastifyReply) => Promise, /** * Optional additional validation rules. * Queries must satisfy these rules in addition to those defined by the GraphQL specification. */ validationRules?: ValidationRules, - context?: (request: FastifyRequest, reply: FastifyReply) => Promise, /** * Enable subscription support when options are provided. [`emitter`](https://github.com/mcollina/mqemitter) property is required when subscriptions is an object. (Default false) */ @@ -164,14 +158,14 @@ declare namespace fastifyGQL { } declare module "fastify" { - interface FastifyInstance { + interface FastifyInstance { /** * GraphQL plugin */ - graphql: fastifyGQL.Plugin; + graphql: fastifyGQL.Plugin; } - interface FastifyReply { + interface FastifyReply { /** * @param source GraphQL query string * @param context request context @@ -187,14 +181,9 @@ declare module "fastify" { } } -declare function fastifyGQL< - HttpServer extends (Server | Http2Server) = Server, - HttpRequest extends (IncomingMessage | Http2ServerRequest) = IncomingMessage, - HttpResponse extends (ServerResponse | Http2ServerResponse) = ServerResponse, - Options = fastifyGQL.Options ->( - fastify: fastify.FastifyInstance, - opts: Options): void; +declare function fastifyGQL( + instance: FastifyInstance, RawReplyDefaultExpression>, + opts: fastifyGQL.Options): void export = fastifyGQL; diff --git a/index.js b/index.js index c92dfa3c..571ed4c2 100644 --- a/index.js +++ b/index.js @@ -424,7 +424,8 @@ const plugin = fp(async function (app, opts) { return execution } }, { - name: 'fastify-gql' + name: 'fastify-gql', + fastify: '>=3.x' }) plugin.ErrorWithProps = ErrorWithProps diff --git a/package.json b/package.json index 6f7ff460..e4550e7b 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "lint": "npm run lint:standard && npm run lint:typescript", "lint:standard": "standard | snazzy", "lint:typescript": "standard --parser @typescript-eslint/parser --plugin @typescript-eslint/eslint-plugin test/types/*.ts", - "typescript": "tsc --project ./test/types/tsconfig.json", + "typescript": "tsd", "test": "npm run lint && npm run unit && npm run typescript" }, "repository": { @@ -28,20 +28,21 @@ "@typescript-eslint/eslint-plugin": "^3.0.0", "@typescript-eslint/parser": "^3.0.0", "autocannon": "^5.0.0", - "fastify": "^2.12.0", + "fastify": "^3.0.0", "graphql-tools": "^6.0.8", "pre-commit": "^1.2.2", "proxyquire": "^2.1.3", "snazzy": "^8.0.0", "standard": "^14.0.0", "tap": "^14.10.6", - "typescript": "^3.7.5" + "tsd": "^0.11.0", + "ws": "^7.2.1" }, "dependencies": { "end-of-stream": "^1.4.4", - "fastify-plugin": "^1.6.0", - "fastify-static": "^2.6.0", - "fastify-websocket": "^1.0.0", + "fastify-plugin": "^2.0.0", + "fastify-static": "^3.0.0", + "fastify-websocket": "^2.0.0", "graphql": "^15.0.0", "graphql-jit": "^0.4.0", "http-errors": "^1.7.3", @@ -49,7 +50,9 @@ "p-map": "^4.0.0", "readable-stream": "^3.5.0", "single-user-cache": "^0.3.0", - "tiny-lru": "^7.0.2", - "ws": "^7.2.1" + "tiny-lru": "^7.0.2" + }, + "tsd": { + "directory": "test/types" } } diff --git a/test/types/index.ts b/test/types/index.ts index cc59c379..420913c0 100644 --- a/test/types/index.ts +++ b/test/types/index.ts @@ -1,7 +1,7 @@ import Fastify from 'fastify' +import * as GQL from '../..' // eslint-disable-next-line no-unused-vars import { ValidationContext, ValidationRule } from 'graphql' -import GQL, { ErrorWithProps } from '../..' const app = Fastify() @@ -91,7 +91,7 @@ app.register(async function (app) { `) app.graphql.defineResolvers({ Query: { - willThrow: async () => { throw new ErrorWithProps('Extended Error', { code: 'EXTENDED_ERROR', reason: 'some reason', other: 32 }) } + willThrow: async () => { throw new GQL.ErrorWithProps('Extended Error', { code: 'EXTENDED_ERROR', reason: 'some reason', other: 32 }) } } }) })