docs.nestjs.com icon indicating copy to clipboard operation
docs.nestjs.com copied to clipboard

graphql-ws documentation does not match behavior

Open zacksinclair opened this issue 5 years ago • 2 comments

Is there an existing issue that is already proposing this?

  • [X] I have searched the existing issues

Is your feature request related to a problem? Please describe it

The documentation for graphql-ws describes that the return value of onConnect will behave as it does with subscriptions-transport-ws, where the value is attached to context for usage in context() etc - however, this is not the case.

The return value of onConnect for graphql-ws is actually returned to the client as the payload for connection_ack.

Describe the solution you'd like

It is unclear to me which is more correct, but at the moment, the documentation and the behavior are out of sync in a way that results in confused developers (me) at best, or, at worst, returning data intended for server-side usage to the client.

I'd like to see a version of onConnect that allows for both - returning a tuple causes the first value to be returned as connection_ack payload and the second value attached to context.

Teachability, documentation, adoption, migration strategy

No response

What is the motivation / use case for changing the behavior?

  1. The documentation is incorrect with regard to actual behavior.
  2. We cannot attach any data at connection time to context for websocket connections.

zacksinclair avatar Oct 22 '21 19:10 zacksinclair

Would you like to create a PR to the docs?

kamilmysliwiec avatar Jan 24 '22 14:01 kamilmysliwiec

Documented since: graphql/subscriptions.md now shows graphql-ws's actual onConnect signature — the callback receives the connection context and extra values belong in its extra field, with a full authentication example. The tuple-return API idea belongs in nestjs/graphql.

kamilmysliwiec avatar Aug 28 '26 10:08 kamilmysliwiec