chore(deps): update dependency graphql-ws to v6 #155
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
This PR contains the following updates:
^5.5.5->^6.0.0Release Notes
enisdenjo/graphql-ws (graphql-ws)
v6.0.6Compare Source
Patch Changes
1f53bb4Thanks @enisdenjo! - Fix building issues causing CJS type definitions referencing ESM modulesv6.0.5Compare Source
Patch Changes
fce94faThanks @m1212e! - crossws adapter for compatibility with all supported environmentsv6.0.4Compare Source
Patch Changes
b4a656dThanks @HermanBilous! - Use Math.pow for retry delay calculationv6.0.3Compare Source
Patch Changes
747c01cThanks @enisdenjo! - DropExecutionPatchResultandFormattedExecutionPatchResulttypesNeither of the types are officially supported (yet) and the future versions of graphql-js adding support for stream/defer will a different signature for the incremental execution result.
v6.0.2Compare Source
Patch Changes
6b180e8Thanks @pleunv! - FormattedExecutionResult errors field returns GraphQLFormattedErrorv6.0.1Compare Source
Patch Changes
#618
6be34c7Thanks @enisdenjo! - Remove exports for CommonJS for Deno exports in package.jsonDeno supports ECMAScript modules exclusively.
#618
6be34c7Thanks @enisdenjo! - Define exports for CommonJS TypeScript definitions in package.jsonv6.0.0Compare Source
Major Changes
b668b30Thanks @enisdenjo! - @fastify/websocket WebSocket in the context extra has been renamed fromconnectiontosocketMigrating from v5 to v6
import { makeHandler } from 'graphql-ws/use/@​fastify/websocket'; makeHandler({ schema(ctx) { - const websocket = ctx.extra.connection; + const websocket = ctx.extra.socket; }, context(ctx) { - const websocket = ctx.extra.connection; + const websocket = ctx.extra.socket; }, onConnect(ctx) { - const websocket = ctx.extra.connection; + const websocket = ctx.extra.socket; }, onDisconnect(ctx) { - const websocket = ctx.extra.connection; + const websocket = ctx.extra.socket; }, onClose(ctx) { - const websocket = ctx.extra.connection; + const websocket = ctx.extra.socket; }, onSubscribe(ctx) { - const websocket = ctx.extra.connection; + const websocket = ctx.extra.socket; }, onOperation(ctx) { - const websocket = ctx.extra.connection; + const websocket = ctx.extra.socket; }, onError(ctx) { - const websocket = ctx.extra.connection; + const websocket = ctx.extra.socket; }, onNext(ctx) { - const websocket = ctx.extra.connection; + const websocket = ctx.extra.socket; }, onComplete(ctx) { - const websocket = ctx.extra.connection; + const websocket = ctx.extra.socket; }, });#613
3f11abaThanks @enisdenjo! - Drop support forwsv7wsv7 has been deprecated. Please upgrade and use v8.#613
3f11abaThanks @enisdenjo! - Drop support for deprecatedfastify-websocketfastify-websockethas been deprecated since v4.3.0.. Please upgrade and use@fastify/websocket.#613
3f11abaThanks @enisdenjo! - The/lib/part from imports has been removed, for examplegraphql-ws/lib/use/wsbecomesgraphql-ws/use/wsMigrating from v5 to v6
Simply remove the
/lib/part from your graphql-ws imports that use a handler.ws
uWebSockets.js
@fastify/websocket
Bun
Deno
#613
3f11abaThanks @enisdenjo! -ErrorMessageuses andonErrorreturnsGraphQLFormattedError(instead ofGraphQLError)Thanks @benjie for working on this in #599
#613
3f11abaThanks @enisdenjo! - Least supported Node version is v20Node v10 has been deprecated for years now. There is no reason to support it. Bumping the engine to the current LTS (v20) also allows the code to be leaner and use less polyfills.
#613
3f11abaThanks @enisdenjo! - Least supportedgraphqlpeer dependency is ^15.10.1 and ^16Users are advised to use the latest of
graphqlbecause of various improvements in performance and security.#613
3f11abaThanks @enisdenjo! -NextMessageuses andonNextreturnsFormattedExecutionResult(instead ofExecutionResult)#613
3f11abaThanks @enisdenjo! -schema,context,onSubscribe,onOperation,onError,onNextandonCompletehooks don't have the full accompanying message anymore, only the ID and the relevant part from the messageThere is really no need to pass the full
SubscribeMessageto theonSubscribehook. The only relevant parts from the message are theidand thepayload, thetypeis useless since the hook inherently has it (onNextisnexttype,onErroriserrortype, etc).The actual techincal reason for not having the full message is to avoid serialising results and errors twice. Both
onNextandonErrorallow the user to augment the result and return it to be used instead.onNextoriginally had theNextMessageargument which already has theFormattedExecutionResult, andonErrororiginally had theErrorMessageargument which already has theGraphQLFormattedError, and they both also returnedFormattedExecutionResultandGraphQLFormattedErrorrespectivelly - meaning, if the user serialised the results - the serialisation would happen twice.Additionally, the
onOperation,onError,onNextandonCompletenow have thepayloadwhich is theSubscribeMessage.payload(SubscribePayload) for easier access to the original query as well as execution params extensions.Migrating from v5 to v6
schemaimport { ExecutionArgs } from 'graphql'; import { ServerOptions, SubscribePayload } from 'graphql-ws'; const opts: ServerOptions = { - schema(ctx, message, argsWithoutSchema: Omit<ExecutionArgs, 'schema'>) { - const messageId = message.id; - const messagePayload: SubscribePayload = message.payload; - }, + schema(ctx, id, payload) { + const messageId = id; + const messagePayload: SubscribePayload = payload; + }, };contextimport { ExecutionArgs } from 'graphql'; import { ServerOptions, SubscribePayload } from 'graphql-ws'; const opts: ServerOptions = { - context(ctx, message, args: ExecutionArgs) { - const messageId = message.id; - const messagePayload: SubscribePayload = message.payload; - }, + context(ctx, id, payload, args: ExecutionArgs) { + const messageId = id; + const messagePayload: SubscribePayload = payload; + }, };onSubscribeimport { ServerOptions, SubscribePayload } from 'graphql-ws'; const opts: ServerOptions = { - onSubscribe(ctx, message) { - const messageId = message.id; - const messagePayload: SubscribePayload = message.payload; - }, + onSubscribe(ctx, id, payload) { + const messageId = id; + const messagePayload: SubscribePayload = payload; + }, };onOperationThe
SubscribeMessage.payloadis not useful here at all, thepayloadhas been parsed to ready-to-use graphql execution args and should be used instead.import { ExecutionArgs } from 'graphql'; import { ServerOptions, SubscribePayload, OperationResult } from 'graphql-ws'; const opts: ServerOptions = { - onOperation(ctx, message, args: ExecutionArgs, result: OperationResult) { - const messageId = message.id; - const messagePayload: SubscribePayload = message.payload; - }, + onOperation(ctx, id, payload, args: ExecutionArgs, result: OperationResult) { + const messageId = id; + const messagePayload: SubscribePayload = payload; + }, };onErrorThe
ErrorMessage.payload(GraphQLFormattedError[]) is not useful here at all, the user has access toGraphQLError[]that are true instances of the error containing object references tooriginalErrors and other properties. The user can always convert and returnGraphQLFormattedError[]by using the.toJSON()method.import { GraphQLError, GraphQLFormattedError } from 'graphql'; import { ServerOptions, SubscribePayload } from 'graphql-ws'; const opts: ServerOptions = { - onError(ctx, message, errors) { - const messageId = message.id; - const graphqlErrors: readonly GraphQLError[] = errors; - const errorMessagePayload: readonly GraphQLFormattedError[] = message.payload; - }, + onError(ctx, id, payload, errors) { + const messageId = id; + const graphqlErrors: readonly GraphQLError[] = errors; + const subscribeMessagePayload: SubscribePayload = payload; + const errorMessagePayload: readonly GraphQLFormattedError[] = errors.map((e) => e.toJSON()); + }, };onNextThe
NextMessage.payload(FormattedExecutionResult) is not useful here at all, the user has access toExecutionResultthat contains actual object references to error instances. The user can always convert and returnFormattedExecutionResultby serialising the errors withGraphQLError.toJSON()method.import { ExecutionArgs, ExecutionResult, FormattedExecutionResult } from 'graphql'; import { ServerOptions, SubscribePayload } from 'graphql-ws'; const opts: ServerOptions = { - onNext(ctx, message, args: ExecutionArgs, result: ExecutionResult) { - const messageId = message.id; - const nextMessagePayload: FormattedExecutionResult = message.payload; - }, + onNext(ctx, id, payload, args: ExecutionArgs, result: ExecutionResult) { + const messageId = id; + const subscribeMessagePayload: SubscribePayload = payload; + const nextMessagePayload: FormattedExecutionResult = { ...result, errors: result.errors?.map((e) => e.toJSON()) }; + }, };onCompleteimport { ServerOptions, SubscribePayload } from 'graphql-ws'; const opts: ServerOptions = { - onComplete(ctx, message) { - const messageId = message.id; - }, + onComplete(ctx, id, payload) { + const messageId = id; + const subscribeMessagePayload: SubscribePayload = payload; + }, };#613
3f11abaThanks @enisdenjo! - Errors thrown from subscription iterables will be caught and reported through theErrorMessageCompared to the behaviour before, which terminated the whole WebSocket connection - those errors are now gracefully reported and terminate only the specific subscription that threw the error.
There's been an editorial change in the GraphQL Spec suggesting this being the correct approach.
Also, if you'd like to get involved and ideally drop your opinion about whether iterable errors should be reported as errors or
ExecutionResults witherrorsfield set, please read more here.Migrating from v5 to v6
If you had used the suggested "ws server usage with custom subscribe method that gracefully handles thrown errors" recipe, you can simply remove it since this behaviour is now baked in.
import { subscribe } from 'graphql'; import { useServer } from 'graphql-ws/use/ws'; import { WebSocketServer } from 'ws'; // yarn add ws const wsServer = new WebSocketServer({ port: 4000, path: '/graphql', }); useServer( { schema, - async subscribe(...args) { - const result = await subscribe(...args); - if ('next' in result) { - // is an async iterable, augment the next method to handle thrown errors - const originalNext = result.next; - result.next = async () => { - try { - return await originalNext(); - } catch (err) { - // gracefully handle the error thrown from the next method - return { value: { errors: [err] } }; - } - }; - } - return result; - }, }, wsServer, );3f11abaThanks @enisdenjo! - Remove deprecatedisMessage, usevalidateMessageinsteadMigrating from v5 to v6
Replace all ocurrances of
isMessagewithvalidateMessage. Note thatvalidateMessagethrows if the message is not valid, compared withisMessagethat simply returned true/false.3f11abaThanks @enisdenjo! - Removed deprecatedisFatalConnectionProblem, useshouldRetryinsteadMigrating from v5 to v6
Replace all ocurrances of
isFatalConnectionProblemwithshouldRetry. Note that the result is inverted, where you returnedfalseinisFatalConnectionProblemyou should returntrueinshouldRetry.import { createClient } from 'graphql-ws'; const client = createClient({ url: 'ws://localhost:4000/graphql', - isFatalConnectionProblem: () => false, + shouldRetry: () => true, });Minor Changes
#613
3f11abaThanks @enisdenjo! - Client is truly zero-dependency, not even a peer dependency ongraphqlIn non-browser environments, you can use only the client and not even depend on
graphqlby importing fromgraphql-ws/client.Note that, in browser envirments (and of course having your bundler use the
browserpackage.json field), you don't have to import fromgraphql-ws/client- simply importing fromgraphql-wswill only have thecreateClientavailable.#615
29dd26aThanks @enisdenjo! - Define optional peer dependencies and least supported versionsUsing the
peerDependenciesin combination withpeerDependenciesMetaconfiguration inpackage.json.v5.16.2Compare Source
Patch Changes
#611
6a5fde1Thanks @enisdenjo! - No more workspacesThis version does not contain any code changes.
v5.16.1Compare Source
Patch Changes
#607
a629ec7Thanks @enisdenjo! - Release with changesetsThis version does not contain any code changes.
Configuration
📅 Schedule: Branch creation - "every weekend" in timezone America/Los_Angeles, Automerge - At any time (no schedule defined).
🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.
♻ Rebasing: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.
🔕 Ignore: Close this PR and you won't be reminded about this update again.
This PR was generated by Mend Renovate. View the repository job log.