anycable / graphql-anycable

A drop-in replacement for GraphQL ActionCable subscriptions. Works with AnyCable.
MIT License
107 stars 16 forks source link

client receives `No operation named \"\"` when calling triggers #2

Closed FX-HAO closed 5 years ago

FX-HAO commented 5 years ago

When I tried to trigger an event, my client kept getting {"errors":[{"message":"No operation named \"\""}]}. image

My code:

class Types::SubscriptionType < GraphQL::Schema::Object
  # field :intercity_ride_was_updated, subscription: Subscriptions::IntercityRide
  field :intercity_ride_was_updated, Types::IntercityRideType, null: false

  def intercity_ride_was_updated
    intercity_ride = ::IntercityRide.take
  end
end

# This is how I trigger the event
RelaySchema.subscriptions.trigger("intercityRideWasUpdated", {}, IntercityRide.take)

The backtrace:

[0] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/graphql-1.9.6/lib/graphql/query.rb:26:in `backtrace'"
[1] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/graphql-1.9.6/lib/graphql/query.rb:26:in `initialize'"
[2] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/2.4.0/delegate.rb:85:in `eval'"
[3] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/2.4.0/delegate.rb:85:in `call'"
[4] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/2.4.0/delegate.rb:85:in `method_missing'"
[5] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/ruby-debug-ide-0.7.0.beta7/lib/ruby-debug-ide/command.rb:138:in `block in debug_eval'"
[6] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/ruby-debug-ide-0.7.0.beta7/lib/ruby-debug-ide/command.rb:119:in `timeout'"
[7] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/ruby-debug-ide-0.7.0.beta7/lib/ruby-debug-ide/command.rb:137:in `debug_eval'"
[8] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/ruby-debug-ide-0.7.0.beta7/lib/ruby-debug-ide/commands/inspect.rb:19:in `execute'"
[9] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/ruby-debug-ide-0.7.0.beta7/lib/ruby-debug-ide/ide_processor.rb:41:in `block (2 levels) in process_commands'"
[10] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/ruby-debug-ide-0.7.0.beta7/lib/ruby-debug-ide/ide_processor.rb:34:in `each'"
[11] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/ruby-debug-ide-0.7.0.beta7/lib/ruby-debug-ide/ide_processor.rb:34:in `block in process_commands'"
[12] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/ruby-debug-ide-0.7.0.beta7/lib/ruby-debug-ide/ide_processor.rb:33:in `catch'"
[13] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/ruby-debug-ide-0.7.0.beta7/lib/ruby-debug-ide/ide_processor.rb:33:in `process_commands'"
[14] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/ruby-debug-ide-0.7.0.beta7/lib/ruby-debug-ide/event_processor.rb:58:in `line_event'"
[15] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/ruby-debug-ide-0.7.0.beta7/lib/ruby-debug-ide/event_processor.rb:34:in `at_line'"
[16] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/debase-0.2.3.beta5/lib/debase/context.rb:35:in `at_line'"
[17] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/graphql-1.9.6/lib/graphql/query.rb:26:in `initialize'"
[18] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/graphql-1.9.6/lib/graphql/query.rb:348:in `new'"
[19] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/graphql-1.9.6/lib/graphql/query.rb:348:in `prepare_ast'"
[20] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/graphql-1.9.6/lib/graphql/query.rb:374:in `with_prepared_ast'"
[21] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/graphql-1.9.6/lib/graphql/query.rb:291:in `subscription?'"
[22] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/graphql-1.9.6/lib/graphql/subscriptions/instrumentation.rb:25:in `before_query'"
[23] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/graphql-1.9.6/lib/graphql/execution/instrumentation.rb:58:in `public_send'"
[24] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/graphql-1.9.6/lib/graphql/execution/instrumentation.rb:58:in `block in call_hooks'"
[25] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/graphql-1.9.6/lib/graphql/execution/instrumentation.rb:57:in `each'"
[26] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/graphql-1.9.6/lib/graphql/execution/instrumentation.rb:57:in `call_hooks'"
[27] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/graphql-1.9.6/lib/graphql/execution/instrumentation.rb:44:in `each_query_call_hooks'"
[28] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/graphql-1.9.6/lib/graphql/execution/instrumentation.rb:27:in `block in apply_instrumenters'"
[29] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/graphql-1.9.6/lib/graphql/execution/instrumentation.rb:72:in `call_hooks'"
[30] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/graphql-1.9.6/lib/graphql/execution/instrumentation.rb:26:in `apply_instrumenters'"
[31] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/graphql-1.9.6/lib/graphql/execution/multiplex.rb:174:in `instrument_and_analyze'"
[32] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/graphql-1.9.6/lib/graphql/execution/multiplex.rb:61:in `block in run_queries'"
[33] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/graphql-1.9.6/lib/graphql/tracing.rb:62:in `block in trace'"
[34] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/graphql-1.9.6/lib/graphql/tracing.rb:76:in `call_tracers'"
[35] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/graphql-1.9.6/lib/graphql/tracing.rb:62:in `trace'"
[36] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/graphql-1.9.6/lib/graphql/execution/multiplex.rb:59:in `run_queries'"
[37] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/graphql-1.9.6/lib/graphql/execution/multiplex.rb:49:in `run_all'"
[38] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/graphql-1.9.6/lib/graphql/schema.rb:376:in `block in multiplex'"
[39] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/graphql-1.9.6/lib/graphql/schema.rb:1205:in `with_definition_error_check'"
[40] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/graphql-1.9.6/lib/graphql/schema.rb:375:in `multiplex'"
[41] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/graphql-1.9.6/lib/graphql/schema.rb:352:in `execute'"
[42] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/graphql-1.9.6/lib/graphql/subscriptions.rb:92:in `execute'"
[43] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/graphql-anycable-0.3.0/lib/graphql/subscriptions/anycable_subscriptions.rb:75:in `block in execute_all'"
[44] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/graphql-anycable-0.3.0/lib/graphql/subscriptions/anycable_subscriptions.rb:73:in `each'"
[45] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/graphql-anycable-0.3.0/lib/graphql/subscriptions/anycable_subscriptions.rb:73:in `execute_all'"
[46] = "/Users/haofuxin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/graphql-1.9.6/lib/graphql/subscriptions.rb:69:in `trigger'"

but I'm not sure if it's the bug of graphql-ruby or this gem. graphql version is 1.9.6.

Envek commented 5 years ago

I've not personally checked it with graphql-ruby 1.9.x yet, so it may be a version incompatibility.

Thank you for reporting I will check it in one of the following days.

FX-HAO commented 5 years ago

I took a deeper look and found what the problem was. https://github.com/rmosolgo/graphql-ruby/blob/bcf0eb1c7a51dad6957460c80b5d32291ef1b9b7/lib/graphql/subscriptions.rb#L90

    def execute(subscription_id, event, object)
      # Lookup the saved data for this subscription
      query_data = read_subscription(subscription_id)
      # Fetch the required keys from the saved data
      query_string = query_data.fetch(:query_string)
      variables = query_data.fetch(:variables)
      context = query_data.fetch(:context)
      operation_name = query_data.fetch(:operation_name) # this should be `nil` instead of `""`

It seems like hmset sets a nil and hmget gets an empty string. I'll fix it.