rmosolgo / rmosolgo/graphql-ruby

The example for ActionCable subscription may contain a bug

Open
#5,212 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
5.4k
Forks
1.4k
Avg merge
23h 19m
Merged PRs (30d)
28

Description

Describe the bug

I figured this one out after a long session of debugging: if you skip the initial response from the GraphQL subscription then the example GraphqlChannel from the docs will fail to register the subscription and throw an error about missing field.

Versions

graphql version: 2.4.8
graphql-ruby-client version: 1.14.5

Steps to reproduce

Implement ActionCable integration exactly as in the documentation, then use useSubscribe from basic Apollo stack.

I can provide full repro if needed.

Expected behavior

No errors from Apollo library, subscription registers correctly

Actual behavior

Missing field 'subscriptionName' while writing result {}

The subscription fails to be attached properly.

Additional context

This error happens because the example implementation of GraphqlChannel by default converts data: nil into data: {} (due to .to_h) and then always calls transmit, pushing empty data in an unexpected format. This is in turned picked by ActionCableLink which checks if result.data exists but not if it's an empty object, passing it to Apollo, triggering the bug.

I am not sure if this is expected behaviour in any configuration (Relay?) so I did not send a pull request but the solution when using base Apollo is simply to:

transmit(payload) unless result['data'].empty?

This will avoid the initial, broken call while making all the subsequent subscription events work as expected.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the ActionCable GraphqlChannel example in the linked GraphQL API documentation and inspect javascript_client/src/subscriptions/ActionCableLink.ts around line 49. Reproduce the Apollo useSubscribe flow described in the issue, then verify that the initial empty payload no longer causes the missing-field error while subsequent subscription events still register correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby, typescript
Domain
api, backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.