Comments (5)
Here's a reproducible spec:
# frozen_string_literal: true
require "spec_helper"
module SubscriptionEnum
class InMemoryBackend < GraphQL::Subscriptions
attr_reader :write_subscription_events, :execute_all_events
def initialize(...)
super
@write_subscription_events = []
@execute_all_events = []
end
def write_subscription(_query, events)
@write_subscription_events.concat(events)
end
def execute_all(event, _object)
@execute_all_events.push(event)
end
end
class MyEnumType < GraphQL::Schema::Enum
value "ONE", value: "one"
value "TWO", value: "two"
end
class MySubscription < GraphQL::Schema::Subscription
argument :my_enum, MyEnumType, required: true
field :my_enum, MyEnumType
end
class SubscriptionType < GraphQL::Schema::Object
field :my_subscription, resolver: MySubscription
end
class Schema < GraphQL::Schema
subscription SubscriptionType
use InMemoryBackend
end
end
describe GraphQL::Subscriptions do
describe "enums" do
let(:schema) { SubscriptionEnum::Schema }
let(:implementation) { schema.subscriptions }
let(:write_subscription_events) { implementation.write_subscription_events }
let(:execute_all_events) { implementation.execute_all_events }
describe "pushing updates" do
focus
it "sends updated data" do
query_str = <<-GRAPHQL
subscription ($myEnum: MyEnum!) {
mySubscription (myEnum: $myEnum) {
myEnum
}
}
GRAPHQL
schema.execute(query_str, variables: { "myEnum" => "ONE" })
schema.subscriptions.trigger(:mySubscription, { "myEnum" => "ONE" }, nil)
assert_equal(":mySubscription:myEnum:one", write_subscription_events[0].topic)
assert_equal(":mySubscription:myEnum:one", execute_all_events[0].topic)
end
end
end
end
from graphql-ruby.
It fails with:
$ bundle exec rake test
# Running tests with run options --seed 49142:
F
Finished tests in 0.062282s, 16.0560 tests/s, 32.1120 assertions/s.
Failure:
GraphQL::Subscriptions::enums::pushing updates#test_0001_sends updated data [/Users/sobrinho/Developer/opensource/graphql-ruby/spec/graphql/subscriptions_enum_spec.rb:66]
Minitest::Assertion: --- expected
+++ actual
@@ -1 +1 @@
-":mySubscription:myEnum:one"
+":mySubscription:myEnum:ONE"
1 tests, 2 assertions, 1 failures, 0 errors, 0 skips
rake aborted!
Command failed with status (1)
/Users/sobrinho/.gem/ruby/2.7.6/gems/rake-13.1.0/exe/rake:27:in `<top (required)>'
/Users/sobrinho/.gem/ruby/2.7.6/gems/bundler-2.4.13/lib/bundler/cli/exec.rb:58:in `load'
/Users/sobrinho/.gem/ruby/2.7.6/gems/bundler-2.4.13/lib/bundler/cli/exec.rb:58:in `kernel_load'
/Users/sobrinho/.gem/ruby/2.7.6/gems/bundler-2.4.13/lib/bundler/cli/exec.rb:23:in `run'
/Users/sobrinho/.gem/ruby/2.7.6/gems/bundler-2.4.13/lib/bundler/cli.rb:492:in `exec'
/Users/sobrinho/.gem/ruby/2.7.6/gems/bundler-2.4.13/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/Users/sobrinho/.gem/ruby/2.7.6/gems/bundler-2.4.13/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/Users/sobrinho/.gem/ruby/2.7.6/gems/bundler-2.4.13/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
/Users/sobrinho/.gem/ruby/2.7.6/gems/bundler-2.4.13/lib/bundler/cli.rb:34:in `dispatch'
/Users/sobrinho/.gem/ruby/2.7.6/gems/bundler-2.4.13/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
/Users/sobrinho/.gem/ruby/2.7.6/gems/bundler-2.4.13/lib/bundler/cli.rb:28:in `start'
/Users/sobrinho/.gem/ruby/2.7.6/gems/bundler-2.4.13/exe/bundle:45:in `block in <top (required)>'
/Users/sobrinho/.gem/ruby/2.7.6/gems/bundler-2.4.13/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
/Users/sobrinho/.gem/ruby/2.7.6/gems/bundler-2.4.13/exe/bundle:33:in `<top (required)>'
/Users/sobrinho/.gem/ruby/2.7.6/bin/bundle:25:in `load'
/Users/sobrinho/.gem/ruby/2.7.6/bin/bundle:25:in `<main>'
Tasks: TOP => test
(See full trace by running task with --trace)
from graphql-ruby.
That's how we fixed it for our current version:
# Normalize enum values to its custom value when triggering subscriptions.
#
# In a nutshell, Event#topic normalizes "ENUM_VALUE" to "enum_value" when
# writing a subscription while when triggering it doesn't.
#
# This monkey-patch will allow us to call either way:
#
# RootSchema.subscriptions.trigger(:my_subscription, my_enum: "enum_value")
# RootSchema.subscriptions.trigger(:my_subscription, my_enum: "ENUM_VALUE")
#
# See https://github.com/rmosolgo/graphql-ruby/issues/4713
module NormalizeTriggerSubscriptionEnumValues
def stringify_args(arg_owner, args, context)
result = super
if arg_owner.is_a?(Class) && arg_owner < GraphQL::Schema::Enum
arg_owner.coerce_isolated_input(result) || result
else
result
end
end
end
GraphQL::Subscriptions::Event.singleton_class.prepend(NormalizeTriggerSubscriptionEnumValues)
from graphql-ruby.
Hey, sorry for the trouble and thanks for the great report and work-around! I bet a patch very similar to what you shared will fix this in the gem. I'll take a look soon, or feel free to submit a PR if you're interested 👍
from graphql-ruby.
Thanks @rmosolgo ! ❤️
from graphql-ruby.
Related Issues (20)
- Runtime manipulation of arguments breaks with commit "Cache resolved arguments better" HOT 7
- ignore HOT 1
- Can't get ActionCable subscriptions to work HOT 1
- [PRO] Changelog does not include upgrade information on the breaking change HOT 18
- More website improvements
- GraphQL::Analysis::AST::FieldUsage does not detect deprecated arguments inside mutation input objects HOT 2
- hasNextPage always is blank, unless 'first' argument is specified. HOT 5
- data loader cache shared between mutation loading and mutation resolving HOT 6
- Revisit argument / input_object validation
- Scoped context example breaks normalized stores HOT 3
- "stack level too deep" error when installing `2.2.0`+ HOT 3
- Put errors first in response HOT 1
- authorized? for GraphQL::Schema::EnumValue is not working HOT 2
- ActiveOperationLimiter does not work when I have enabled SentryTrace HOT 6
- Sentry tracing fails when Sentry is configured but no DSN is set
- Pro: operation store sync endpoint is not compatible for Rack 3's new `body` expectations HOT 3
- Complexity computations for fields on connections HOT 2
- JavaScript client should use strong typing for `onError` argument HOT 2
- `GraphQL::Schema::Interface#resolve_type` appears to resolve lazy results too early HOT 2
- Complexity calculation is not respecting the value in the resolver HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql-ruby.