Skip to content

Commit

Permalink
fix: Add support for graphql@v16
Browse files Browse the repository at this point in the history
  • Loading branch information
enisdenjo committed Aug 26, 2021
1 parent 156c5fb commit ad5aea2
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 56 deletions.
2 changes: 1 addition & 1 deletion docs/interfaces/common.NextMessage.md
Expand Up @@ -22,7 +22,7 @@ ___

### payload

`Readonly` **payload**: `ExecutionResult`<`Object`, `Object`\>
`Readonly` **payload**: `ExecutionResult`<`ObjMap`<`unknown`\>, `ObjMap`<`unknown`\>\>

___

Expand Down
92 changes: 55 additions & 37 deletions docs/interfaces/server.ServerOptions.md
Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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`\>\>\>

___

Expand Down Expand Up @@ -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`[]
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -76,7 +76,7 @@
"release": "semantic-release"
},
"peerDependencies": {
"graphql": ">=0.11 <=15"
"graphql": ">=0.11 <=16"
},
"devDependencies": {
"@babel/core": "^7.15.0",
Expand All @@ -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",
Expand Down
11 changes: 1 addition & 10 deletions src/server.ts
Expand Up @@ -16,9 +16,6 @@ import {
GraphQLError,
SubscriptionArgs,
ExecutionResult,
DocumentNode,
ValidationRule,
TypeInfo,
} from 'graphql';
import {
GRAPHQL_TRANSPORT_WS_PROTOCOL,
Expand Down Expand Up @@ -146,13 +143,7 @@ export interface ServerOptions<E = unknown> {
* 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<ValidationRule>,
typeInfo?: TypeInfo,
options?: { maxErrors?: number },
) => ReadonlyArray<GraphQLError>;
validate?: typeof graphqlValidate;
/**
* Is the `execute` function from GraphQL which is
* used to execute the query and mutation operations.
Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit ad5aea2

Please sign in to comment.