Skip to content

Commit

Permalink
Update fastify to v3 (#147)
Browse files Browse the repository at this point in the history
* update fastify to v3

* add new ci config

* update readme

* add fastify-websocket version

* fix  dependabot config

Co-authored-by: Adam Davis <adam@admataz.com>
  • Loading branch information
frikille and admataz authored Jul 8, 2020
1 parent eb4b1f7 commit 1ddda3c
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 49 deletions.
5 changes: 5 additions & 0 deletions .dependabot/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: 1
update_conigs:
- package_manager: "javascript"
directory: "/"
update_schedule: "daily"
18 changes: 18 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
11 changes: 0 additions & 11 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
41 changes: 15 additions & 26 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -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<HttpResponse> {
export interface Plugin {
/**
* Replace existing schema
* @param schema graphql schema
Expand Down Expand Up @@ -33,7 +31,7 @@ declare namespace fastifyGQL {
params: any
}>,
context: {
reply: FastifyReply<HttpResponse>
reply: FastifyReply
}) => any
}
}): void;
Expand All @@ -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<HttpServer, HttpRequest, HttpResponse> {
export interface Options {
/**
* The GraphQL schema. String schema will be parsed
*/
Expand All @@ -67,7 +61,7 @@ declare namespace fastifyGQL {
params: any
}>,
context: {
reply: FastifyReply<HttpResponse>
reply: FastifyReply
}) => any
}
},
Expand Down Expand Up @@ -107,19 +101,19 @@ declare namespace fastifyGQL {
*/
errorHandler?: boolean | ((
error: FastifyError,
request: FastifyRequest<HttpRequest>,
reply: FastifyReply<HttpResponse>
request: FastifyRequest,
reply: FastifyReply
) => ExecutionResult),
/**
* The maximum depth allowed for a single query.
*/
queryDepth?: number,
context?: (request: FastifyRequest, reply: FastifyReply) => Promise<any>,
/**
* Optional additional validation rules.
* Queries must satisfy these rules in addition to those defined by the GraphQL specification.
*/
validationRules?: ValidationRules,
context?: (request: FastifyRequest<HttpRequest>, reply: FastifyReply<HttpResponse>) => Promise<any>,
/**
* Enable subscription support when options are provided. [`emitter`](https://github.com/mcollina/mqemitter) property is required when subscriptions is an object. (Default false)
*/
Expand Down Expand Up @@ -164,14 +158,14 @@ declare namespace fastifyGQL {
}

declare module "fastify" {
interface FastifyInstance<HttpServer, HttpRequest, HttpResponse> {
interface FastifyInstance {
/**
* GraphQL plugin
*/
graphql: fastifyGQL.Plugin<HttpResponse>;
graphql: fastifyGQL.Plugin;
}

interface FastifyReply<HttpResponse> {
interface FastifyReply {
/**
* @param source GraphQL query string
* @param context request context
Expand All @@ -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<HttpServer, HttpRequest, HttpResponse>
>(
fastify: fastify.FastifyInstance<HttpServer, HttpRequest, HttpResponse>,
opts: Options): void;
declare function fastifyGQL(
instance: FastifyInstance<RawServerBase, RawRequestDefaultExpression<RawServerBase>, RawReplyDefaultExpression<RawServerBase>>,
opts: fastifyGQL.Options): void


export = fastifyGQL;
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 11 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -28,28 +28,31 @@
"@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",
"mqemitter": "^4.0.0",
"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"
}
}
4 changes: 2 additions & 2 deletions test/types/index.ts
Original file line number Diff line number Diff line change
@@ -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()

Expand Down Expand Up @@ -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 }) }
}
})
})
Expand Down

0 comments on commit 1ddda3c

Please sign in to comment.