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

Question: Executing and Returning Initial Query with Subscription #1910

Closed
ksylvest opened this issue Oct 18, 2018 · 6 comments
Closed

Question: Executing and Returning Initial Query with Subscription #1910

ksylvest opened this issue Oct 18, 2018 · 6 comments

Comments

@ksylvest
Copy link
Contributor

ksylvest commented Oct 18, 2018

For a GraphQL subscription is it possible to execute the initial query (to support pseudo live-queries)?

module Types
  class SampleType < GraphQL::Schema::Object
    field :greeting, String, null: false

    def greeting
     Time.current < Time.current.noon ? 'Morning!' : 'Evening'
    end
  end
end

class SampleSchema < GraphQL::Schema
  use GraphQL::Subscriptions::ActionCableSubscriptions
  subscription Types::SampleType
end

SampleSchema.execute('subscription greeting { greeting }')['data'] # nil -- can this be configured to be { greeting: '...' } ?

Per FB RFC on subscriptions - I'm a bit unclear if this type of thing is meant to be supported:

The server may send an initial publish from executing the subscription operation.

Realize this can likely be done via a Query + Subscription.

Also - is the logic on controlling execution wrapped up here?:

https://github.com/rmosolgo/graphql-ruby/blob/master/lib/graphql/subscriptions/instrumentation.rb#L59

@rmosolgo
Copy link
Owner

No, it's not possible to return something on an initial subscription query. I'm currently working on a new runtime for GraphQL-Ruby and I'll add this issue to my list (#1884), since many folks have asked for similar improvements to subscriptions.

Yes, you're right about where the logic is. You can see above that in some cases, the resolver is called, but the return value is ignored:

https://github.com/rmosolgo/graphql-ruby/blob/master/lib/graphql/subscriptions/instrumentation.rb#L47

@ksylvest
Copy link
Contributor Author

Thanks for the response Robert! Appreciate the work you put into graphql-ruby (super useful library). Closing.

@rmosolgo
Copy link
Owner

Btw I was looking back on the spec and didn't see any mention one way or another about initial responses, do you?

https://facebook.github.io/graphql/June2018/#sec-Subscription

I see your link above is to the RFC, but I wonder if/how that made it to the spec. I'm going to add support for initial responses one way or another but I'll include a bit from the spec if I can find it!

@ksylvest
Copy link
Contributor Author

Hmm, I can not find anything within the spec linked. It seems like it'd be challenging to avoid race conditions without (via the query / subscribe combo.

@rmosolgo
Copy link
Owner

yeah, i agree 😉

@rmosolgo
Copy link
Owner

Trying to add proper support for this in #1930

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