I see This method becomes deprecated in the new package graphql-transport-ws. Start using the GraphQLTransportWSClient to make queries, mutations and subscriptions over websockets. deprecation warning, but I can't find an example how to use GraphQLTransportWSClient.
Can you add some example to README.md for GraphQLTransportWSClient?
Thanks.
Noticed the same thing.
In the project readme.
@ArnaudRinquin But I'm using Hybrid https://github.com/apollographql/subscriptions-transport-ws#hybrid-websocket-transport, and it says: use addGraphQLSubscriptions.
Also using the hybrid implementation and would like to know what to use instead.
I might be wrong but I guess that's the whole idea of using an hybrid network that is deprecated.
This warning is to notify the users that will be released in the next weeks a new transport package called graphql-transport-ws where the method addGraphQlSubscriptions will be removed. The 0.7.x version of the current package was built with retro compatibility in mind and it is the last version because our idea is to move into a new independent transport package with full webscoket support and without backward compatibility.
@mistic Could you link me to more information about why you're choosing to go in this direction?
@mistic @Urigo
I think that the implementation should allow using hybrid network interfaces, and addGraphQlSubscriptions should not be deprecated at the moment, since we do not have other alternative for creating hybrid interfaces.
I talked to @Urigo and we decided to keep it deprecated, and with v1.0 of this transport, we will provide a hybrid network interface implementation (Based on regular apollo-client network interface for queries and mutations, and this transport for subscriptions).
Closing for now, we will update as soon as the new network interface will be available
@ArnaudRinquin I don't see any reference to GraphQLTransportWSClient in the README. Searching the code only turns up the warning, no implementation. How are we supposed to use something that doesn't exist?
@mnpenner and everyone,
addGraphQLSubscriptions will be deprecated in 1.0 of the transport, we will create a new hybrid network interface soon, but we have to wait because it will need to be a part of the new apollo-fetcher done by @helfer and @evanshauser.
The warning is a bit misleading because the new implementation isn't there yet.
Actually the GraphQLTransportWSClient is SubscriptionClient - it implements the interface of Apollo network interface, so you can use it directly as your network layer, or use regular HTTP interface for queries and mutations, and subscriptions with addGraphQLSubscriptions.
The warning is a bit misleading
Would you consider removing the warning since I assume many will try to understand why it's here only to realise that it can't be solved?
you are all right :)
In the new 0.8 release I've changed the deprecation warning to be more understandable:
Notice that addGraphQLSubscriptions method will become deprecated in the new package graphql-transport-ws that will be released soon. Keep track for the new hybrid network release here: https://github.com/apollographql/subscriptions-transport-ws/issues/169
For those who wants to follow more closely on the exciting improvements happening on Apollo Client's network front, check it out here: https://github.com/apollographql/apollo-link/pull/6/files#diff-d3558ae69a848084cb7c6b40cf743177
Warnings that can't be fixed are just irritating. If it's not actionable, I don't think it should be displayed at all.
That said, the work you're doing looks great. A more readable version of the spec is here.
It worse if you're using react native 馃憥

@farzd It doesn't show in production though, right?
@scf4 of course not but it interferes with dev and clogs up the logs and makes it difficult to do automated testing.
Oh absolutely.
@dotansimha any update on this, it's been 3 months?
also waiting for an update here... would love a React Native syntax example on how best to adopt only the new implementation, which i'm assuming is GraphQLTransportWSClient/SubscriptionClient
here's how i'm currently doing it, but 3 months later and i'm still getting that deprecated warning
`
import { AsyncStorage,Alert } from 'react-native'
// ENV VARS
import { PROJECT_ID } from 'react-native-dotenv'
// LIBS
import { SubscriptionClient, addGraphQLSubscriptions } from 'subscriptions-transport-ws'
import { ApolloClient,createNetworkInterface } from 'react-apollo'
const networkInterface = createNetworkInterface({
uri: https://api.graph.cool/simple/v1/${PROJECT_ID},
opts: {
credentials: 'same-origin'
}
})
const wsClient = new SubscriptionClient(wss://subscriptions.us-west-2.graph.cool/v1/${PROJECT_ID}, {
reconnect: true,
connectionParams: {
authToken: AsyncStorage.getItem('token')
}
})
const networkInterfaceWithSubscriptions = addGraphQLSubscriptions(
networkInterface,
wsClient
)
networkInterface.use([{
applyMiddleware(req, next) {
if (!req.options.headers) {
req.options.headers = {}
}
AsyncStorage.getItem('token').then(
token => {
if (token !== null) {
req.options.headers['authorization'] = Bearer ${token}
} else {
req.options.headers['authorization'] = null
}
next()
},
failure => {
Alert.alert('ERROR: ', failure.message)
next()
})
}
}])
const client = new ApolloClient({
networkInterface: networkInterfaceWithSubscriptions
})
export default client
`
Fix:
yarn add add-graphql-subscriptions
(https://github.com/scf4/add-graphql-subscriptions)
And then:
import { addGraphQLSubscriptions } from 'add-graphql-subscriptions';
instead of from subscriptions-transport-ws.
how to subscriptions on "subscriptions-transport-ws" version 0.9.0"?
@bakumn 0.9.0 is very different from 0.8.x. You have to use Apollo Links instead of the previous networkInterface, which means you have to use Apollo Client 2, but that's not out of beta yet.
@altschuler so I basically can't do subscriptions with the latest of subscriptions-transport-ws and apollo-links because Apollo Client 2 isn't released, correct? So, what versions of each do I need to be using to pull off subscriptions. Bleeding edge truly hurts.
Edit: Am I missing something or are subscriptions going away from apollo-links? https://github.com/apollographql/apollo-link/blob/master/docs/roadmap.md#terminating
Hmmmmm looks like we should look into the release process and versioning here. Maybe it's possible to tag 0.9 as a "preview" release or similar, since there is definitely some confusion here right now.
The worst thing here was that addGraphQLSubscriptions is still in the README. It took me half an hour to find the commit mentioning this issue.
I've said this on another issue, but this is particularly concerning since the "official" graphql how to refers to the implementation with addGraphQLSubscriptions. This can be found at https://www.howtographql.com/vue-apollo/8-subscriptions/
I've reported this to them so that they may update their docs for specific npm version
Please update the README because we are now in version 0.9.x and the README still using addGraphQLSubscriptions.
https://github.com/apollographql/subscriptions-transport-ws#hybrid-websocket-transport
import {SubscriptionClient, addGraphQLSubscriptions} from 'subscriptions-transport-ws';
So, currently, if I do exactly what the README file says, I get a deprecation warning.
This is _not_ how things are supposed to work - correct?
I am not getting any warning. It simply does not exist.
So, how do I do subscriptions with the stable realeses (react apollo 1.4.6)
Came here from https://www.howtographql.com/vue-apollo/8-subscriptions/ as a complete Vue and Apollo newbie... any suggestions as to what the "right" way to do this is, without pinning to an old version?
For future tumbleweeds who are struggling to setup React + Apollo with subscriptions a couple of people in another repo left a comment and wrote a guide see:
But basically the client side code will look something like this:
import React from "react";
import ReactDOM from "react-dom";
import { ApolloClient } from "apollo-client";
import { ApolloLink } from "apollo-link";
import { ApolloProvider } from "react-apollo";
import { HttpLink } from "apollo-link-http";
import { InMemoryCache } from "apollo-cache-inmemory";
import { WebSocketLink } from "apollo-link-ws";
import { getOperationAST } from "graphql";
const link = ApolloLink.split(
operation => {
const operationAST = getOperationAST(operation.query, operation.operationName);
return !!operationAST && operationAST.operation === "subscription";
},
new WebSocketLink({
uri: `ws://${window.location.host}/graphql`,
options: {
reconnect: true,
},
}),
new HttpLink({ uri: "/graphql" }),
);
const client = new ApolloClient({
link,
cache: new InMemoryCache(),
});
ReactDOM.render(
<ApolloProvider client={client}>
<YourApp />
</ApolloProvider>,
document.getElementById("root"),
);
Thank you for this post @ksrb. Spent a long time reading the docs in circles over this. Looking forward to updated docs :)
Most helpful comment
Warnings that can't be fixed are just irritating. If it's not actionable, I don't think it should be displayed at all.
That said, the work you're doing looks great. A more readable version of the spec is here.