Subscriptions-transport-ws: Cannot read property 'kind' of undefined at checkDocument

Created on 26 Apr 2017  路  6Comments  路  Source: apollographql/subscriptions-transport-ws

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

Most helpful comment

@devarashetty Do you happen to remember what key variable issue was? I'm running into the same issue.

All 6 comments

@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:

  1. Make sure you have react-apollo 2.1.0-beta.3
  2. Use query 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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

altschuler picture altschuler  路  4Comments

damour picture damour  路  3Comments

nickofthyme picture nickofthyme  路  3Comments

mjasnikovs picture mjasnikovs  路  5Comments

KaiWedekind picture KaiWedekind  路  4Comments