-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why use WebSocketLink from '@apollo/client/link/ws' #8345
Comments
+1, I think it would be better to link to the new To the maintainers: was there a particular reason for using |
I tried to implement graphql-ws with apollo (following the example in graphql-ws documentation) but i had no success. |
+1 |
Example is here: https://github.com/enisdenjo/graphql-ws#apollo-client |
Apollo Client currently contains `WebSocketLink` in `@apollo/client/link/ws` which uses the `subscriptions-transport-ws` library. That library is no longer actively maintained, and there is an improved fork called `graphql-ws`. The two libraries use different protocols so a different client link is required for `graphql-ws`. (While the WebSocket protocol does allow for subprotocol negotiation, neither server implementation supports this in a practical way.) This PR adds a new link `GraphQLWsLink` in `@apollo/client/link/subscriptions`. Its constructor arguments are the same as the `createClient` function in `graphql-ws` (or it can take a `Client` object returned from that function), and you need to install the optional peer dep `graphql-ws` instead of `subscriptions-transport-ws`. Once you've created the link, it works exactly like the old `WebSocketLink`. This PR changes the main subscriptions doc page to mostly document the new link, with an extra section at the bottom for the old link. The core GraphQLWsLink code is based on MIT-licensed code from the README of the graphql-ws repository. Fixes #8345. Part of apollographql/apollo-server#6058
Apollo Client currently contains `WebSocketLink` in `@apollo/client/link/ws` which uses the `subscriptions-transport-ws` library. That library is no longer actively maintained, and there is an improved fork called `graphql-ws`. The two libraries use different protocols so a different client link is required for `graphql-ws`. (While the WebSocket protocol does allow for subprotocol negotiation, neither server implementation supports this in a practical way.) This PR adds a new link `GraphQLWsLink` in `@apollo/client/link/subscriptions`. Its constructor arguments are the same as the `createClient` function in `graphql-ws` (or it can take a `Client` object returned from that function), and you need to install the optional peer dep `graphql-ws` instead of `subscriptions-transport-ws`. Once you've created the link, it works exactly like the old `WebSocketLink`. This PR changes the main subscriptions doc page to mostly document the new link, with an extra section at the bottom for the old link. The core GraphQLWsLink code is based on MIT-licensed code from the README of the graphql-ws repository. Fixes #8345. Part of apollographql/apollo-server#6058
Apollo Client currently contains `WebSocketLink` in `@apollo/client/link/ws` which uses the `subscriptions-transport-ws` library. That library is no longer actively maintained, and there is an improved fork called `graphql-ws`. The two libraries use different protocols so a different client link is required for `graphql-ws`. (While the WebSocket protocol does allow for subprotocol negotiation, neither server implementation supports this in a practical way.) This PR adds a new link `GraphQLWsLink` in `@apollo/client/link/subscriptions`. Its constructor arguments are the same as the `createClient` function in `graphql-ws` (or it can take a `Client` object returned from that function), and you need to install the optional peer dep `graphql-ws` instead of `subscriptions-transport-ws`. Once you've created the link, it works exactly like the old `WebSocketLink`. This PR changes the main subscriptions doc page to mostly document the new link, with an extra section at the bottom for the old link. The core GraphQLWsLink code is based on MIT-licensed code from the README of the graphql-ws repository. Fixes #8345. Part of apollographql/apollo-server#6058
Apollo Client currently contains `WebSocketLink` in `@apollo/client/link/ws` which uses the `subscriptions-transport-ws` library. That library is no longer actively maintained, and there is an improved fork called `graphql-ws`. The two libraries use different protocols so a different client link is required for `graphql-ws`. (While the WebSocket protocol does allow for subprotocol negotiation, neither server implementation supports this in a practical way.) This PR adds a new link `GraphQLWsLink` in `@apollo/client/link/subscriptions`. Its constructor arguments are the same as the `createClient` function in `graphql-ws` (or it can take a `Client` object returned from that function), and you need to install the optional peer dep `graphql-ws` instead of `subscriptions-transport-ws`. Once you've created the link, it works exactly like the old `WebSocketLink`. This PR changes the main subscriptions doc page to mostly document the new link, with an extra section at the bottom for the old link. The core GraphQLWsLink code is based on MIT-licensed code from the README of the graphql-ws repository. Fixes #8345. Part of apollographql/apollo-server#6058
Apollo Client currently contains `WebSocketLink` in `@apollo/client/link/ws` which uses the `subscriptions-transport-ws` library. That library is no longer actively maintained, and there is an improved fork called `graphql-ws`. The two libraries use different protocols so a different client link is required for `graphql-ws`. (While the WebSocket protocol does allow for subprotocol negotiation, neither server implementation supports this in a practical way.) This PR adds a new link `GraphQLWsLink` in `@apollo/client/link/subscriptions`. Its constructor arguments are the same as the `createClient` function in `graphql-ws` (or it can take a `Client` object returned from that function), and you need to install the optional peer dep `graphql-ws` instead of `subscriptions-transport-ws`. Once you've created the link, it works exactly like the old `WebSocketLink`. This PR changes the main subscriptions doc page to mostly document the new link, with an extra section at the bottom for the old link. The core GraphQLWsLink code is based on MIT-licensed code from the README of the graphql-ws repository. Fixes #8345. Part of apollographql/apollo-server#6058
This work was completed and will be included in the soon to be released |
In your documentation (https://www.apollographql.com/docs/react/api/link/apollo-link-ws/) you encourage to use WebSocket which depends on subscriptions-transport-ws npm package. but apollographql/subscriptions-transport-ws repo says
Same case here https://www.apollographql.com/docs/graphql-subscriptions/authentication/ .
By other side in the next link you implement difference approach to the same solution, will be great or unify then, or explain pros/cons, or when use what:
https://www.apollographql.com/docs/graphql-subscriptions/express/
https://www.apollographql.com/docs/apollo-server/data/subscriptions/#example-authentication-with-onconnect
Finally I would like to ask you about an example to how implement graphql-ws with apollo server.
The text was updated successfully, but these errors were encountered: