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

Subscription Action Cable Implementation Example leads to JavaScript client Uncaught TypeError: Cannot read property 'data' of null #1368

mlwilkerson opened this Issue Mar 24, 2018 · 0 comments


1 participant

mlwilkerson commented Mar 24, 2018

The guide for Action Cable Implementation of Subscriptions refers to the API doc for example code to implement GraphqlChannel < ApplicationCable::Channel.

Unfortunately, that example code seems to have an error (maybe code that was correct for a previous version?) that leads to this JavaScript client side error when using ActionCableLink:
import ActionCableLink from 'graphql-ruby-client/subscriptions/ActionCableLink'

Here's the error on the client:

ActionCableLink.js:30 Uncaught TypeError: Cannot read property 'data' of null

This happens when initially setting up the subscription. The server generates a nil result with more: true. And it sets up the payload like this:

    payload = {
        result: result.subscription? ? nil : result.to_h,
        more: result.subscription?

But ActionCableLink chokes when it tries to look at in received:

        received: function(payload) {
          if ( {

          if (!payload.more) {

This is because payload.result is null, because it was set to null by the server (above).

I couldn't seem to isolate the problem until downloading the demo app offered here and comparing to a working example.

The key is that the demo app from SenteraLLC wraps the nil result in {data: nil} like this:

    payload = {
        result: result.subscription? ? {data: nil} : result.to_h,
        more: result.subscription?

mlwilkerson added a commit to mlwilkerson/graphql-ruby that referenced this issue Mar 24, 2018

github0013 pushed a commit to github0013/graphql_subscription_actioncable that referenced this issue Aug 21, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment