I tried to do the subscriptions in the following way.
Server Schema definition
const Subscription = new GraphQLObjectType({
name: 'BlogSubscriptions',
fields: {
authors: {
type: new GraphQLList(Author),
description: 'Available authors in the blog',
resolve: function() {
return _.values(AuthorsMap);
}
},
authorAdded: {
type: Author,
description: 'Create a new blog post',
resolve: function(source, {args}) {
console.log("args",source,args)
}
},
}
});
Client
const networkInterface = createNetworkInterface('http://localhost:8000/graphql');
const wsClient = new SubscriptionClient(`ws://localhost:5000/`, {
reconnect: true,
connectionParams: {
// Pass any arguments you want for initialization
}
});
const networkInterfaceWithSubscriptions = addGraphQLSubscriptions(
networkInterface,
wsClient
);
const apolloClient = new ApolloClient({
networkInterface: networkInterfaceWithSubscriptions
})
apolloClient.subscribe({
document: gql`
subscription testing {
authors {
id
}
}`,
updateQuery: (prev, {subscriptionData}) => {
console.log("subscriptionData",subscriptionData)
return; // Modify your store and return new state with the new arrived data
}
});
Output
cannot read kind of undefined
@devarashetty
Where do you see this error? on the client side or server side?
Also, does the socket actually open and pass the subscription to the server before the error?
@Urigo I found the reason ,it's becaz of some key variable name gone wrong.
ok thanks, closing
@devarashetty Do you happen to remember what key variable issue was? I'm running into the same issue.
the same problem
If you're quering with React:
react-apollo 2.1.0-beta.3query instead of subscription prop in <Subscription /> component. I guess there's a mistake in docs, eg:<Subscription
query={myQuery}
variables={{ chatId: '0ad5ffb8-308b-4355-96d0-f0e5047deb50' }}
>
Found it here https://github.com/apollographql/react-apollo/pull/1483/files#diff-0c67e4cbe31bd05dd0111a850cd8c24cR19 and it seems that it's required too.
Most helpful comment
@devarashetty Do you happen to remember what key variable issue was? I'm running into the same issue.