Skip to content
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

developing and testing action cable subscriptions #4094

Closed
tim-millar opened this issue Jun 10, 2022 · 4 comments
Closed

developing and testing action cable subscriptions #4094

tim-millar opened this issue Jun 10, 2022 · 4 comments

Comments

@tim-millar
Copy link

This is neither a feature request nor a bug report exactly, but more a request for clarification and advice.

We are currently porting an existing application from phoenix / elixir (using absinthe to provide graphql integration) to a rails API using graphql-ruby and action cable. this application contains a number of subscriptions which are required by the frontend connected to the app (which uses apollo-client). When developing the old application we were able to play around with subscriptions in the graphiql IDE in order to see how they worked and write integration tests for them in order to have confidence that they worked without needing to involve the frontend.

Ideally we would like to do something similar with the new application: play around with queries in some form or another while we try to understand how to replicate the implementation using action-cable and graphql-ruby (e.g., using graphiql, or postman, or even a ruby-client of some sort which can be launched from the console or command line), and write request specs using rspec in order that everything is working correctly without needing to worry about the frontend app. This both parallels our workflow in the phoenix application, but also in the new app with graphql queries and mutations.

My understanding based on trying to achieve this over the last few days is that neither is possible (at least at the moment). Is that correct - i.e., subscriptions won't work in any sort of API client like graphiql or postman and require a proper frontend using apollo or relay clients, and there's no way to write request specs using rspec? (When attempting this, in both cases, I encounter the, "This GraphQL Subscription client does not support the transport protocol expected by the backend Subscription Server implementation (graphql-ruby ActionCableSubscriptions in this case)" error message.)

Is there a recommended way to develop and test subscriptions when developing a backend application using action cable? The only option seems to be to connect a frontend app and use that as the subscription client, but this isn't ideal from a developer workflow POV and also doesn't help with the testing.

Many thanks

@rmosolgo
Copy link
Owner

Hey, great question. You're right, as far as I know, that nobody has developed a GraphiQL connector for ActionCable subscriptions.

As far as testing goes, you can inject a dummy ActionCable implementation in your unit tests to inspect what GraphQL ends up sending, for example:

You can inject that in test, or, after #4108 is released, you can make a subclass of your main schema and re-attach ActionCableSubscriptions to that subclass with a different action_cable option.

It'd be great to get ActionCable connected to GraphiQL, but I've never made time for it 😖

@tim-millar
Copy link
Author

Thanks!

We've since used your dummy action cable implementation and rspec examples to write similar tests for our subscriptions, although we weren't able to get working request specs (which we use for queries and mutations) or to write tests where we subscribe and then trigger the broadcasts via a mutation query (instead we're manually triggering, again based on your example).

Instead of using graphiql, we created a react app with graphql-playground and apollo-client, based on comments we read on the issues pages here. It's working perfectly well, so although it was some effort to set up, there's no real issue with not being able to access graphiql.

@rmosolgo
Copy link
Owner

I hope you found something that works for you! I don't have plans to work further on this now so I'm closing it.

@rmosolgo
Copy link
Owner

👋 It's been a while, but I recently released support for ActionCable + GraphiQL in graphql-ruby-client: https://graphql-ruby.org/javascript_client/graphiql_subscriptions.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants