3

I am learning about implementing GraphQL API in Rails app using graphql-ruby gem. I am not clear about the use-case of GraphQL Subscriptions.

I don't clearly understand the difference between GraphQL Subscriptions and ActionCable.

Let's say I have a mobile app which gets data from GraphQL API.

Will I be able to use ActionCable directly to publish the changes to mobile clients? If yes, then why should I go with GraphQL subscriptions?

1 Answers1

0

If you like to integrate subscriptions in your GraphQL API than GraphQL Subscriptions are for you. You can think of any real time feature that you like to implement (a multiplayer game, etc) you can read more background information about GraphQL subscriptions at https://github.com/facebook/graphql/blob/master/rfcs/Subscriptions.md.

The difference between GraphQL Subscriptions and ActionCable. GraphQL Subscriptions can be integrated in your GraphQL API. ActionCable is used in RoR to help developers to create realtime features possible in RoR. As mentioned at http://graphql-ruby.org/subscriptions/action_cable_implementation.html ActionCable can be used as a platform for delivering GraphQL subscriptions on Rails 5+.

For your last question what do you mean by a mobile app? Do you mean a native app? Or do you mean a web based app? For a native app it probably depends on your implementation and libraries you use. If you mean a web app you can use something like Relay Modern or Apollo client to handle subscriptions as mentioned in the guides. You can use the ActionCable front end stuff to setup a connection. You can find everything about the subscriptions in the http://graphql-ruby.org/guides.

Smek
  • 1,158
  • 11
  • 33