graphql-ruby: Subscription Triggers Do Nothing with ActionCable
Hi! Thanks a lot for this awesome library and thanks in advance for the help.
I am using v1.9.15
We’ve been working with graphql-ruby in our app with Apollo on the frontend for quite awhile, and are currently in the process of implementing subscriptions for the first time. Since we are only planning on using a few subscriptions, we thought ActionCable would be an easy choice for the websocket server.
I’m able to establish a connection and I see ongoing pings on the client letting me know that my connection is remaining open. I’m reaching an impasse, though, when attempting to use MySchema.trigger to pass messages to the subscribed client. My subscription type looks like this:
module Types
class SubscriptionType < GraphQL::Schema::Object
field login_response, subscription: Subscriptions::LoginResponse,
null: false,
description: "FILL THIS IN"
end
end
and the specific subscription in question looks like this:
module Types
class LoginResponse < Types::BaseObject
field :accounts, [Types::ThirdPartyAccount], null: true,
description: 'third-party login was successful'
field :mfa_challenge, Types::MfaChallenge, null: true
end
end
I am attempting to trigger in a mutation like this:
AppSchema.subscriptions.trigger('loginResponse', {}, ThirdPartyAccount.last(2))
This trigger call logs out the following:
[ActionCable] Broadcasting to graphql-event::loginResponse:: "[{\"__gid__\":\"Z2lkOi8vcG9vbC9MaW5rZWRBY2NvdW50LzMw\"},{\"__gid__\":\"Z2lkOi8vcG9vbC9MaW5rZWRBY2NvdW50LzMx\"}]"
At this point nothing arrives on the client. I’ve tried scoping the subscription field and passing the associated scope: option to trigger per the guides and I’ve used the Redis and Async adapters but nothing seems to work. Any help is greatly appreciated!
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 18 (2 by maintainers)
Sorry about the trouble 😖 In your root
Subscriptiontype, do you have? It’s required for the new interpreter runtime, so you might have to add it.
I think it can be refactored so that the
extendis not required, so if that fixes it, I’ll look into it!Thanks for building this - I’m loving it so far. I’m also running into this issue. Exact same for me. Trigger logs:
[ActionCable] Broadcasting to graphql-event::identityCreated:: "{\"__gid__\":\"Z2lkOi8vYXBpL0lkZW50aXR5LzE\"}"But nothing happens after that. I’ve followed all the tutorials and used the async and redis adapters.
One thing I’ve noticed is that a stream does not ever seem to be created. When the subscription triggers I see the following in the rails server but never a stream begin.
GraphqlChannel transmitting {:result=>{"data"=>{"identityCreated"=>{"waitListCount"=>233, "__typename"=>"IdentityCreatedPayload"}}}, :more=>true}In this tutorial, in the “Realtime Updates!” section, it shows this screenshot:
It seems that channel should start a stream but that never happens for me.
Any suggestions?
@dmill
I came to this issue for the same problem. I could run subscription and trigger, and here’s the bare minimum project.
https://github.com/github0013/graphql-ruby-bare-min/tree/master
Hope this help anyone who comes for the same issue.
In case you find this issue and this does not work for you, check that you are NOT using
asyncfor your development adapter incable.yamlNote bullet point 3 here: https://www.rubydoc.info/gems/graphql/GraphQL/Subscriptions/ActionCableSubscriptions
I had similar problem which trigger the
Subscription.update, but react app won’t receive the update. Which was due to the serialisation failed:I added
to_hto convert to a simpler structure which worked:Hope it helps for some friends!