lib/graphql/subscriptions.rb in graphql-1.13.23 vs lib/graphql/subscriptions.rb in graphql-2.0.0
- old
+ new
@@ -3,11 +3,10 @@
require "graphql/subscriptions/broadcast_analyzer"
require "graphql/subscriptions/event"
require "graphql/subscriptions/instrumentation"
require "graphql/subscriptions/serialize"
require "graphql/subscriptions/action_cable_subscriptions"
-require "graphql/subscriptions/subscription_root"
require "graphql/subscriptions/default_subscription_resolve_extension"
module GraphQL
class Subscriptions
# Raised when either:
@@ -31,25 +30,19 @@
raise ArgumentError, "Can't reinstall subscriptions. #{schema} is using #{schema.subscriptions}, can't also add #{self}"
end
instrumentation = Subscriptions::Instrumentation.new(schema: schema)
defn.instrument(:query, instrumentation)
- if !schema.is_a?(Class)
- defn.instrument(:field, instrumentation)
- end
options[:schema] = schema
schema.subscriptions = self.new(**options)
schema.add_subscription_extension_if_necessary
nil
end
# @param schema [Class] the GraphQL schema this manager belongs to
def initialize(schema:, broadcast: false, default_broadcastable: false, **rest)
if broadcast
- if !schema.using_ast_analysis?
- raise ArgumentError, "`broadcast: true` requires AST analysis, add `using GraphQL::Analysis::AST` to your schema or see https://graphql-ruby.org/queries/ast_analysis.html."
- end
schema.query_analyzer(Subscriptions::BroadcastAnalyzer)
end
@default_broadcastable = default_broadcastable
@schema = schema
end
@@ -231,11 +224,11 @@
# @param arg_owner [GraphQL::Field, GraphQL::BaseType]
# @param args [Hash, Array, Any] some GraphQL input value to coerce as `arg_owner`
# @return [Any] normalized arguments value
def normalize_arguments(event_name, arg_owner, args, context)
case arg_owner
- when GraphQL::Field, GraphQL::InputObjectType, GraphQL::Schema::Field, Class
+ when GraphQL::Schema::Field, Class
if arg_owner.is_a?(Class) && !arg_owner.kind.input_object?
# it's a type, but not an input object
return args
end
normalized_args = {}
@@ -272,25 +265,23 @@
normalized_args[arg_defn.name] = arg_defn.prepare_value(nil, default_value, context: context)
end
end
if missing_arg_names.any?
- arg_owner_name = if arg_owner.is_a?(GraphQL::Field)
- "Subscription.#{arg_owner.name}"
- elsif arg_owner.is_a?(GraphQL::Schema::Field)
+ arg_owner_name = if arg_owner.is_a?(GraphQL::Schema::Field)
arg_owner.path
elsif arg_owner.is_a?(Class)
arg_owner.graphql_name
else
arg_owner.to_s
end
raise InvalidTriggerError, "Can't trigger Subscription.#{event_name}, received undefined arguments: #{missing_arg_names.join(", ")}. (Should match arguments of #{arg_owner_name}.)"
end
normalized_args
- when GraphQL::ListType, GraphQL::Schema::List
+ when GraphQL::Schema::List
args.map { |a| normalize_arguments(event_name, arg_owner.of_type, a, context) }
- when GraphQL::NonNullType, GraphQL::Schema::NonNull
+ when GraphQL::Schema::NonNull
normalize_arguments(event_name, arg_owner.of_type, args, context)
else
args
end
end