Search code examples
rubygraphqlgraphql-ruby

GraphQL Ruby Subscription Executing Initial Query


With GraphQL Ruby it possible to have a GraphQL subscription also return resolves when subscribing? For example:

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

    def greeting
     'Howdy!'
    end
  end
end

class SampleSchema < GraphQL::Schema
  subscription Types::SampleType
  query Types::SampleType
end

SampleSchema.execute('subscription greeting { greeting }')['data'] # nil - but want the same as query
SampleSchema.execute('query greeting { greeting }')['data'] # { greeting: 'Howdy!' }

Note: have found this Subscription Type documents that specify the return value of the resolver is not used for data (only authorization).


Solution

  • The author of GraphQL-ruby responded to an issue stating:

    https://github.com/rmosolgo/graphql-ruby/issues/1910

    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.

    So not now, maybe later.