You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Node 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.
#6133f11aba Thanks @enisdenjo! - Least supported graphql peer dependency is ^15.10.1 and ^16
Users are advised to use the latest of graphql because of various improvements in performance and security.
#6133f11aba Thanks @enisdenjo! - NextMessage uses and onNext returns FormattedExecutionResult (instead of ExecutionResult)
#6133f11aba Thanks @enisdenjo! - schema, context, onSubscribe, onOperation, onError, onNext and onComplete hooks don't have the full accompanying message anymore, only the ID and the relevant part from the message
There is really no need to pass the full SubscribeMessage to the onSubscribe hook. The only relevant parts from the message are the id and the payload, the type is useless since the hook inherently has it (onNext is next type, onError is error type, etc).
The actual techincal reason for not having the full message is to avoid serialising results and errors twice. Both onNext and onError allow the user to augment the result and return it to be used instead. onNext originally had the NextMessage argument which already has the FormattedExecutionResult, and onError originally had the ErrorMessage argument which already has the GraphQLFormattedError, and they both also returned FormattedExecutionResult and GraphQLFormattedError respectivelly - meaning, if the user serialised the results - the serialisation would happen twice.
Additionally, the onOperation, onError, onNext and onComplete now have the payload which is the SubscribeMessage.payload (SubscribePayload) for easier access to the original query as well as execution params extensions.
The ErrorMessage.payload (GraphQLFormattedError[]) is not useful here at all, the user has access to GraphQLError[] that are true instances of the error containing object references to originalErrors and other properties. The user can always convert and return GraphQLFormattedError[] by using the .toJSON() method.
The NextMessage.payload (FormattedExecutionResult) is not useful here at all, the user has access to ExecutionResult that contains actual object references to error instances. The user can always convert and return FormattedExecutionResult by serialising the errors with GraphQLError.toJSON() method.
#6133f11aba Thanks @enisdenjo! - Errors thrown from subscription iterables will be caught and reported through the ErrorMessage
Compared 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.
Also, if you'd like to get involved and ideally drop your opinion about whether iterable errors should be reported as errors or ExecutionResults with errors field 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,
);
Replace all ocurrances of isMessage with validateMessage. Note that validateMessage throws if the message is not valid, compared with isMessage that simply returned true/false.
#6133f11aba Thanks @enisdenjo! - Removed deprecated isFatalConnectionProblem, use shouldRetry instead
Migrating from v5 to v6
Replace all ocurrances of isFatalConnectionProblem with shouldRetry. Note that the result is inverted, where you returned false in isFatalConnectionProblem you should return true in shouldRetry.
Note that, in browser envirments (and of course having your bundler use the browser package.json field), you don't have to import from graphql-ws/client - simply importing from graphql-ws will only have the createClient available.
#61529dd26a Thanks @enisdenjo! - Define optional peer dependencies and least supported versions
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
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.0.0
->^6.0.0
Release Notes
enisdenjo/graphql-ws (graphql-ws)
v6.0.0
Compare Source
Major Changes
b668b30
Thanks @enisdenjo! - @fastify/websocket WebSocket in the context extra has been renamed fromconnection
tosocket
Migrating from v5 to v6
#613
3f11aba
Thanks @enisdenjo! - Drop support forws
v7ws
v7 has been deprecated. Please upgrade and use v8.#613
3f11aba
Thanks @enisdenjo! - Drop support for deprecatedfastify-websocket
fastify-websocket
has been deprecated since v4.3.0.. Please upgrade and use@fastify/websocket
.#613
3f11aba
Thanks @enisdenjo! - The/lib/
part from imports has been removed, for examplegraphql-ws/lib/use/ws
becomesgraphql-ws/use/ws
Migrating 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
3f11aba
Thanks @enisdenjo! -ErrorMessage
uses andonError
returnsGraphQLFormattedError
(instead ofGraphQLError
)Thanks @benjie for working on this in #599
#613
3f11aba
Thanks @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
3f11aba
Thanks @enisdenjo! - Least supportedgraphql
peer dependency is ^15.10.1 and ^16Users are advised to use the latest of
graphql
because of various improvements in performance and security.#613
3f11aba
Thanks @enisdenjo! -NextMessage
uses andonNext
returnsFormattedExecutionResult
(instead ofExecutionResult
)#613
3f11aba
Thanks @enisdenjo! -schema
,context
,onSubscribe
,onOperation
,onError
,onNext
andonComplete
hooks 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
SubscribeMessage
to theonSubscribe
hook. The only relevant parts from the message are theid
and thepayload
, thetype
is useless since the hook inherently has it (onNext
isnext
type,onError
iserror
type, etc).The actual techincal reason for not having the full message is to avoid serialising results and errors twice. Both
onNext
andonError
allow the user to augment the result and return it to be used instead.onNext
originally had theNextMessage
argument which already has theFormattedExecutionResult
, andonError
originally had theErrorMessage
argument which already has theGraphQLFormattedError
, and they both also returnedFormattedExecutionResult
andGraphQLFormattedError
respectivelly - meaning, if the user serialised the results - the serialisation would happen twice.Additionally, the
onOperation
,onError
,onNext
andonComplete
now have thepayload
which is theSubscribeMessage.payload
(SubscribePayload
) for easier access to the original query as well as execution params extensions.Migrating from v5 to v6
schema
context
onSubscribe
onOperation
The
SubscribeMessage.payload
is not useful here at all, thepayload
has been parsed to ready-to-use graphql execution args and should be used instead.onError
The
ErrorMessage.payload
(GraphQLFormattedError[]
) is not useful here at all, the user has access toGraphQLError[]
that are true instances of the error containing object references tooriginalError
s and other properties. The user can always convert and returnGraphQLFormattedError[]
by using the.toJSON()
method.onNext
The
NextMessage.payload
(FormattedExecutionResult
) is not useful here at all, the user has access toExecutionResult
that contains actual object references to error instances. The user can always convert and returnFormattedExecutionResult
by serialising the errors withGraphQLError.toJSON()
method.onComplete
#613
3f11aba
Thanks @enisdenjo! - Errors thrown from subscription iterables will be caught and reported through theErrorMessage
Compared 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
ExecutionResult
s witherrors
field 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.
3f11aba
Thanks @enisdenjo! - Remove deprecatedisMessage
, usevalidateMessage
insteadMigrating from v5 to v6
Replace all ocurrances of
isMessage
withvalidateMessage
. Note thatvalidateMessage
throws if the message is not valid, compared withisMessage
that simply returned true/false.3f11aba
Thanks @enisdenjo! - Removed deprecatedisFatalConnectionProblem
, useshouldRetry
insteadMigrating from v5 to v6
Replace all ocurrances of
isFatalConnectionProblem
withshouldRetry
. Note that the result is inverted, where you returnedfalse
inisFatalConnectionProblem
you should returntrue
inshouldRetry
.Minor Changes
#613
3f11aba
Thanks @enisdenjo! - Client is truly zero-dependency, not even a peer dependency ongraphql
In non-browser environments, you can use only the client and not even depend on
graphql
by importing fromgraphql-ws/client
.Note that, in browser envirments (and of course having your bundler use the
browser
package.json field), you don't have to import fromgraphql-ws/client
- simply importing fromgraphql-ws
will only have thecreateClient
available.#615
29dd26a
Thanks @enisdenjo! - Define optional peer dependencies and least supported versionsUsing the
peerDependencies
in combination withpeerDependenciesMeta
configuration inpackage.json
.v5.16.2
Compare Source
Patch Changes
#611
6a5fde1
Thanks @enisdenjo! - No more workspacesThis version does not contain any code changes.
v5.16.1
Compare Source
Patch Changes
#607
a629ec7
Thanks @enisdenjo! - Release with changesetsThis version does not contain any code changes.
v5.16.0
Compare Source
Bug Fixes
Features
v5.15.0
Compare Source
Bug Fixes
TerminatedCloseEvent
class extending anError
for rejecting promises when terminating (74b4ceb), closes #531Features
5.14.3 (2023-12-20)
Bug Fixes
this
) (812129d)5.14.2 (2023-10-23)
Bug Fixes
5.14.1 (2023-09-28)
Bug Fixes
v5.14.3
Compare Source
Bug Fixes
this
) (812129d)v5.14.2
Compare Source
Bug Fixes
v5.14.1
Compare Source
Bug Fixes
v5.14.0
Compare Source
Features
5.13.1 (2023-05-15)
Bug Fixes
v5.13.1
Compare Source
Bug Fixes
v5.13.0
Compare Source
Features
5.12.1 (2023-03-31)
Bug Fixes
v5.12.1
Compare Source
Bug Fixes
v5.12.0
Compare Source
Features
5.11.3 (2023-02-01)
Bug Fixes
Error
(#442) (9884889), closes #4415.11.2 (2022-09-21)
Bug Fixes
5.11.1 (2022-09-16)
Bug Fixes
v5.11.3
Compare Source
Bug Fixes
Error
(#442) (9884889), closes #441v5.11.2
Compare Source
Bug Fixes
v5.11.1
Compare Source
Bug Fixes
v5.11.0
Compare Source
Features
generateID
(d0bc6e1), closes #3985.10.2 (2022-09-12)
Performance Improvements
5.10.1 (2022-08-19)
Bug Fixes
lazyCloseTimeout
(c332837), closes #388v5.10.2
Compare Source
Performance Improvements
v5.10.1
Compare Source
Bug Fixes
lazyCloseTimeout
(c332837), closes #388v5.10.0
Compare Source
Features
@fastify/websocket
(#382) (dd755b0), closes #3815.9.1 (2022-07-01)
Bug Fixes
exports
(#375) (9f394d7)v5.9.1
Compare Source
Bug Fixes
exports
(#375) (9f394d7)v5.9.0
Compare Source
Features
5.8.2 (2022-05-12)
Bug Fixes
5.8.1 (2022-04-25)
Bug Fixes
isFatalConnectionProblem
defaults to undefined for usingshouldRetry
(9d5c573)v5.8.2
Compare Source
Bug Fixes
v5.8.1
Compare Source
Bug Fixes
isFatalConnectionProblem
defaults to undefined for usingshouldRetry
(9d5c573)v5.8.0
Compare Source
Features
isFatalConnectionProblem
option in favour ofshouldRetry
(d8dcf21)v5.7.0
Compare Source
Features
5.6.4 (2022-03-24)
Bug Fixes
5.6.3 (2022-03-13)
Bug Fixes
connectionParams
took too long and the server kicked the client off (1e94e45), closes #3315.6.2 (2022-02-23)
Bug Fixes
handleProtocols
accepts arrays too and gracefully rejects other types (98dec1a), closes #3185.6.1 (2022-02-21)
Bug Fixes
Sec-WebSocket-Protocol
header if none supported (9bae064)v5.6.4
Compare Source
Bug Fixes
v5.6.3
Compare Source
Bug Fixes
connectionParams
took too long and the server kicked the client off (1e94e45), closes #331v5.6.2
Compare Source
Bug Fixes
handleProtocols
accepts arrays too and gracefully rejects other types (98dec1a), closes #318v5.6.1
Compare Source
Bug Fixes
Sec-WebSocket-Protocol
header if none supported (9bae064)v5.6.0
Compare Source
Features
connectionParams
) (#311) (e67cf80)5.5.5 (2021-10-29)
Bug Fixes
5.5.4 (2021-10-27)
Bug Fixes
5.5.3 (2021-10-20)
Bug Fixes
5.5.2 (2021-10-20)
Bug Fixes
Complete
message followed (27754b2), closes #2455.5.1 (2021-10-19)
Bug Fixes
v5.5.5
Compare Source
Bug Fixes
v5.5.4
Compare Source
Bug Fixes
v5.5.3
Compare Source
Bug Fixes
v5.5.2
Compare Source
Bug Fixes
Complete
message followed (27754b2), closes #245v5.5.1
Compare Source
Bug Fixes
v5.5.0
Compare Source
Bug Fixes
Features
connectionAckWaitTimeout
option (#228) (35ce054)5.4.1 (2021-08-26)
Bug Fixes
graphql@v16
(ad5aea2)ExecutionResult
(045b402)v5.4.1
Compare Source
Bug Fixes
graphql@v16
(ad5aea2)ExecutionResult
(045b402)v5.4.0
Compare Source
Bug Fixes
4406
close code for unsupported subprotocol (1002
is an internal WebSocket close code) (df85281)4500
close code for internal server errors (1011
is an internal WebSocket close code) (3c0316d)Features
CloseCode
enum (d10a75c)ws@v8
(9119153)v5.3.0
Compare Source
Bug Fixes
ConnectionInit
payload is absent ifconnectionParams
returns nothing (98f8265)Features
connectionParams
can returnundefined
(a543187)opened
event for when a WebSocket opens (9053224)v5.2.0
Compare Source
Features
onPing
andonPong
message type listeners (f36066f)5.1.2 (2021-06-09)
Bug Fixes
5.1.1 (2021-06-09)
Bug Fixes
v5.1.2
Compare Source
Bug Fixes
v5.1.1
Compare Source
Bug Fixes
v5.1.0
Compare Source
Features
disablePong
option for when implementing a custom pinger (6510360), closes #117payload
for ping/pong message types (2fe0345), closes #117Configuration
📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).
🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.
♻ Rebasing: Whenever PR becomes conflicted, 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.