From dd7eae21774fcc1be9e2c7d680b9a7d89a24d0e4 Mon Sep 17 00:00:00 2001 From: Codzter <32208000+cody-elhard@users.noreply.github.com> Date: Wed, 12 Jul 2023 06:22:01 -0500 Subject: [PATCH 1/2] Figure out introspection on execution working version error test test we are actually using class enable_introspection_entry_points on class itself allow to be set to true --- lib/graphql/execution/interpreter.rb | 8 ++++++++ lib/graphql/query.rb | 3 ++- lib/graphql/schema.rb | 6 ++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/graphql/execution/interpreter.rb b/lib/graphql/execution/interpreter.rb index f4735a1d76..730db79b53 100644 --- a/lib/graphql/execution/interpreter.rb +++ b/lib/graphql/execution/interpreter.rb @@ -22,6 +22,14 @@ class << self # @param max_complexity [Integer, nil] # @return [Array] One result per query def run_all(schema, query_options, context: {}, max_complexity: schema.max_complexity) + # Remove 'enable_introspection_entry_points' from the options hash + # before passing it to the query. + # This is a hack to avoid breaking the public API. + query_options = query_options.map do |opts| + opts = opts.dup + opts.delete(:enable_introspection_entry_points) + opts + end queries = query_options.map do |opts| case opts when Hash diff --git a/lib/graphql/query.rb b/lib/graphql/query.rb index f6c51f31dc..1b1c7c7445 100644 --- a/lib/graphql/query.rb +++ b/lib/graphql/query.rb @@ -97,7 +97,7 @@ def selected_operation_name # @param max_complexity [Numeric] the maximum field complexity for this query (falls back to schema-level value) # @param except [<#call(schema_member, context)>] If provided, objects will be hidden from the schema when `.call(schema_member, context)` returns truthy # @param only [<#call(schema_member, context)>] If provided, objects will be hidden from the schema when `.call(schema_member, context)` returns false - def initialize(schema, query_string = nil, query: nil, document: nil, context: nil, variables: nil, validate: true, static_validator: nil, subscription_topic: nil, operation_name: nil, root_value: nil, max_depth: schema.max_depth, max_complexity: schema.max_complexity, except: nil, only: nil, warden: nil) + def initialize(schema, query_string = nil, query: nil, document: nil, context: nil, variables: nil, validate: true, static_validator: nil, subscription_topic: nil, operation_name: nil, root_value: nil, max_depth: schema.max_depth, max_complexity: schema.max_complexity, except: nil, only: nil, warden: nil, disable_introspection_entry_points: true) # Even if `variables: nil` is passed, use an empty hash for simpler logic variables ||= {} @schema = schema @@ -114,6 +114,7 @@ def initialize(schema, query_string = nil, query: nil, document: nil, context: n self.static_validator = static_validator if static_validator context_tracers = (context ? context.fetch(:tracers, []) : []) @tracers = schema.tracers + context_tracers + @disable_introspection_entry_points = disable_introspection_entry_points # Support `ctx[:backtrace] = true` for wrapping backtraces if context && context[:backtrace] && !@tracers.include?(GraphQL::Backtrace::Tracer) diff --git a/lib/graphql/schema.rb b/lib/graphql/schema.rb index d8e580f899..416620becd 100644 --- a/lib/graphql/schema.rb +++ b/lib/graphql/schema.rb @@ -712,6 +712,11 @@ def disable_introspection_entry_points @introspection_system = nil end + def enable_introspection_entry_points + @disable_introspection_entry_points = false + introspection_system + end + def disable_schema_introspection_entry_point @disable_schema_introspection_entry_point = true # TODO: this clears the cache made in `def types`. But this is not a great solution. @@ -1045,6 +1050,7 @@ def execute(query_str = nil, **kwargs) if query_str kwargs[:query] = query_str end + enable_introspection_entry_points if kwargs[:enable_introspection_entry_points] # Some of the query context _should_ be passed to the multiplex, too multiplex_context = if (ctx = kwargs[:context]) { From 66f237c4510ade58ae335883ac98258bf4652374 Mon Sep 17 00:00:00 2001 From: Codzter <32208000+cody-elhard@users.noreply.github.com> Date: Wed, 12 Jul 2023 07:26:05 -0500 Subject: [PATCH 2/2] fix tests? --- lib/graphql/execution/interpreter.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/graphql/execution/interpreter.rb b/lib/graphql/execution/interpreter.rb index 730db79b53..2e5308ea5c 100644 --- a/lib/graphql/execution/interpreter.rb +++ b/lib/graphql/execution/interpreter.rb @@ -27,7 +27,9 @@ def run_all(schema, query_options, context: {}, max_complexity: schema.max_compl # This is a hack to avoid breaking the public API. query_options = query_options.map do |opts| opts = opts.dup - opts.delete(:enable_introspection_entry_points) + if opts.key?(:enable_introspection_entry_points) + opts.delete(:enable_introspection_entry_points) + end opts end queries = query_options.map do |opts|