From ad5aea2703d8612a8f5b16814864268fd7f3feb6 Mon Sep 17 00:00:00 2001 From: enisdenjo Date: Thu, 26 Aug 2021 20:57:17 +0200 Subject: [PATCH] fix: Add support for `graphql@v16` --- docs/interfaces/common.NextMessage.md | 2 +- docs/interfaces/server.ServerOptions.md | 92 +++++++++++++++---------- package.json | 4 +- src/server.ts | 11 +-- yarn.lock | 12 ++-- 5 files changed, 65 insertions(+), 56 deletions(-) diff --git a/docs/interfaces/common.NextMessage.md b/docs/interfaces/common.NextMessage.md index b99d2f6e..3e82ef6b 100644 --- a/docs/interfaces/common.NextMessage.md +++ b/docs/interfaces/common.NextMessage.md @@ -22,7 +22,7 @@ ___ ### payload -• `Readonly` **payload**: `ExecutionResult`<`Object`, `Object`\> +• `Readonly` **payload**: `ExecutionResult`<`ObjMap`<`unknown`\>, `ObjMap`<`unknown`\>\> ___ diff --git a/docs/interfaces/server.ServerOptions.md b/docs/interfaces/server.ServerOptions.md index 0d02b86c..40119ca3 100644 --- a/docs/interfaces/server.ServerOptions.md +++ b/docs/interfaces/server.ServerOptions.md @@ -20,6 +20,7 @@ - [jsonMessageReviver](server.ServerOptions.md#jsonmessagereviver) - [roots](server.ServerOptions.md#roots) - [schema](server.ServerOptions.md#schema) +- [validate](server.ServerOptions.md#validate) ### Methods @@ -33,7 +34,6 @@ - [onOperation](server.ServerOptions.md#onoperation) - [onSubscribe](server.ServerOptions.md#onsubscribe) - [subscribe](server.ServerOptions.md#subscribe) -- [validate](server.ServerOptions.md#validate) ## Properties @@ -140,6 +140,57 @@ Throwing an error from within this function will close the socket with the `Error` message in the close event reason. +___ + +### validate + +• `Optional` **validate**: (`schema`: `GraphQLSchema`, `documentAST`: `DocumentNode`, `rules?`: `ReadonlyArray`<`ValidationRule`\>, `options?`: {}, `typeInfo?`: `TypeInfo`) => `ReadonlyArray`<`GraphQLError`\> + +A custom GraphQL validate function allowing you to apply your +own validation rules. + +Returned, non-empty, array of `GraphQLError`s will be communicated +to the client through the `ErrorMessage`. Use an empty array if the +document is valid and no errors have been encountered. + +Will not be used when implementing a custom `onSubscribe`. + +Throwing an error from within this function will close the socket +with the `Error` message in the close event reason. + +#### Type declaration + +▸ (`schema`, `documentAST`, `rules?`, `options?`, `typeInfo?`): `ReadonlyArray`<`GraphQLError`\> + +Implements the "Validation" section of the spec. + +Validation runs synchronously, returning an array of encountered errors, or +an empty array if no errors were encountered and the document is valid. + +A list of specific validation rules may be provided. If not provided, the +default list of rules defined by the GraphQL specification will be used. + +Each validation rules is a function which returns a visitor +(see the language/visitor API). Visitor methods are expected to return +GraphQLErrors, or Arrays of GraphQLErrors when invalid. + +Optionally a custom TypeInfo instance may be provided. If not provided, one +will be created from the provided schema. + +##### Parameters + +| Name | Type | +| :------ | :------ | +| `schema` | `GraphQLSchema` | +| `documentAST` | `DocumentNode` | +| `rules?` | `ReadonlyArray`<`ValidationRule`\> | +| `options?` | `Object` | +| `typeInfo?` | `TypeInfo` | + +##### Returns + +`ReadonlyArray`<`GraphQLError`\> + ## Methods ### execute @@ -329,7 +380,7 @@ ___ ### onNext -▸ `Optional` **onNext**(`ctx`, `message`, `args`, `result`): `void` \| `ExecutionResult`<`Object`, `Object`\> \| `Promise`<`void` \| `ExecutionResult`<`Object`, `Object`\>\> +▸ `Optional` **onNext**(`ctx`, `message`, `args`, `result`): `void` \| `ExecutionResult`<`ObjMap`<`unknown`\>, `ObjMap`<`unknown`\>\> \| `Promise`<`void` \| `ExecutionResult`<`ObjMap`<`unknown`\>, `ObjMap`<`unknown`\>\>\> Executed after an operation has emitted a result right before that result has been sent to the client. Results from both @@ -351,11 +402,11 @@ in the close event reason. | `ctx` | [`Context`](server.Context.md)<`E`\> | | `message` | [`NextMessage`](common.NextMessage.md) | | `args` | `ExecutionArgs` | -| `result` | `ExecutionResult`<`Object`, `Object`\> | +| `result` | `ExecutionResult`<`ObjMap`<`unknown`\>, `ObjMap`<`unknown`\>\> | #### Returns -`void` \| `ExecutionResult`<`Object`, `Object`\> \| `Promise`<`void` \| `ExecutionResult`<`Object`, `Object`\>\> +`void` \| `ExecutionResult`<`ObjMap`<`unknown`\>, `ObjMap`<`unknown`\>\> \| `Promise`<`void` \| `ExecutionResult`<`ObjMap`<`unknown`\>, `ObjMap`<`unknown`\>\>\> ___ @@ -462,36 +513,3 @@ in the close event reason. #### Returns [`OperationResult`](../modules/server.md#operationresult) - -___ - -### validate - -▸ `Optional` **validate**(`schema`, `documentAST`, `rules?`, `typeInfo?`, `options?`): readonly `GraphQLError`[] - -A custom GraphQL validate function allowing you to apply your -own validation rules. - -Returned, non-empty, array of `GraphQLError`s will be communicated -to the client through the `ErrorMessage`. Use an empty array if the -document is valid and no errors have been encountered. - -Will not be used when implementing a custom `onSubscribe`. - -Throwing an error from within this function will close the socket -with the `Error` message in the close event reason. - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `schema` | `GraphQLSchema` | -| `documentAST` | `DocumentNode` | -| `rules?` | readonly `ValidationRule`[] | -| `typeInfo?` | `TypeInfo` | -| `options?` | `Object` | -| `options.maxErrors?` | `number` | - -#### Returns - -readonly `GraphQLError`[] diff --git a/package.json b/package.json index 3abc2008..05606782 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,7 @@ "release": "semantic-release" }, "peerDependencies": { - "graphql": ">=0.11 <=15" + "graphql": ">=0.11 <=16" }, "devDependencies": { "@babel/core": "^7.15.0", @@ -100,7 +100,7 @@ "fastify": "^3.20.2", "fastify-websocket": "^3.2.1", "glob": "^7.1.7", - "graphql": "^15.5.1", + "graphql": "^16.0.0-rc.1", "jest": "^27.0.6", "prettier": "^2.3.2", "replacestream": "^4.0.3", diff --git a/src/server.ts b/src/server.ts index d461be9d..f388e46b 100644 --- a/src/server.ts +++ b/src/server.ts @@ -16,9 +16,6 @@ import { GraphQLError, SubscriptionArgs, ExecutionResult, - DocumentNode, - ValidationRule, - TypeInfo, } from 'graphql'; import { GRAPHQL_TRANSPORT_WS_PROTOCOL, @@ -146,13 +143,7 @@ export interface ServerOptions { * Throwing an error from within this function will close the socket * with the `Error` message in the close event reason. */ - validate?: ( - schema: GraphQLSchema, - documentAST: DocumentNode, - rules?: ReadonlyArray, - typeInfo?: TypeInfo, - options?: { maxErrors?: number }, - ) => ReadonlyArray; + validate?: typeof graphqlValidate; /** * Is the `execute` function from GraphQL which is * used to execute the query and mutation operations. diff --git a/yarn.lock b/yarn.lock index bf33cfeb..cbd1a69f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4654,7 +4654,7 @@ __metadata: fastify: ^3.20.2 fastify-websocket: ^3.2.1 glob: ^7.1.7 - graphql: ^15.5.1 + graphql: ^16.0.0-rc.1 jest: ^27.0.6 prettier: ^2.3.2 replacestream: ^4.0.3 @@ -4668,14 +4668,14 @@ __metadata: uWebSockets.js: "uNetworking/uWebSockets.js#v19.3.0" ws: ^8.2.0 peerDependencies: - graphql: ">=0.11 <=15" + graphql: ">=0.11 <=16" languageName: unknown linkType: soft -"graphql@npm:^15.5.1": - version: 15.5.1 - resolution: "graphql@npm:15.5.1" - checksum: 7e45ae27021e5bafd2a3ce557e708606ff28504aae705654764fa6239b0151d014a90cbd4c68300f4f95a9074820aaee9b1f25b560ff089c8db0b49563e34080 +"graphql@npm:^16.0.0-rc.1": + version: 16.0.0-rc.1 + resolution: "graphql@npm:16.0.0-rc.1" + checksum: 50780040ada5f4e71d3f485c6c8265dc4ce2ec6d44425f7a36eb2f3ef73ea60a91d89ba956f1b2fee042cc3ebdba387b967c458db736702415d8cfafca384af8 languageName: node linkType: hard