From 57fc5c4fc63b065c8138da33172efef6f82145e7 Mon Sep 17 00:00:00 2001 From: Robert Mosolgo Date: Tue, 30 May 2023 11:01:17 -0400 Subject: [PATCH] Fix Lookahead with AlwaysVisible --- lib/graphql/schema/warden.rb | 4 ++-- spec/graphql/execution/lookahead_spec.rb | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/graphql/schema/warden.rb b/lib/graphql/schema/warden.rb index fb7c26de7..36c8b3e54 100644 --- a/lib/graphql/schema/warden.rb +++ b/lib/graphql/schema/warden.rb @@ -99,13 +99,13 @@ def visible_enum_value?(enum_value, _ctx = nil); true; end def visible_type_membership?(type_membership, _ctx = nil); true; end def interface_type_memberships(obj_type, _ctx = nil); obj_type.interface_type_memberships; end def get_type(type_name); @schema.get_type(type_name); end # rubocop:disable Development/ContextIsPassedCop - def arguments(argument_owner, ctx = nil); argument_owner.arguments(ctx).values; end + def arguments(argument_owner, ctx = nil); argument_owner.all_argument_definitions; end def enum_values(enum_defn); enum_defn.enum_values; end # rubocop:disable Development/ContextIsPassedCop def get_argument(parent_type, argument_name); parent_type.get_argument(argument_name); end # rubocop:disable Development/ContextIsPassedCop def types; @schema.types; end # rubocop:disable Development/ContextIsPassedCop def root_type_for_operation(op_name); @schema.root_type_for_operation(op_name); end def directives; @schema.directives.values; end - def fields(type_defn); type_defn.fields; end # rubocop:disable Development/ContextIsPassedCop + def fields(type_defn); type_defn.all_field_definitions; end # rubocop:disable Development/ContextIsPassedCop def get_field(parent_type, field_name); @schema.get_field(parent_type, field_name); end def reachable_type?(type_name); true; end def reachable_types; @schema.types.values; end # rubocop:disable Development/ContextIsPassedCop diff --git a/spec/graphql/execution/lookahead_spec.rb b/spec/graphql/execution/lookahead_spec.rb index c7ed1a56a..39e2638c5 100644 --- a/spec/graphql/execution/lookahead_spec.rb +++ b/spec/graphql/execution/lookahead_spec.rb @@ -102,6 +102,10 @@ class Schema < GraphQL::Schema query(Query) instrument :query, LookaheadInstrumenter end + + class AlwaysVisibleSchema < Schema + use GraphQL::Schema::AlwaysVisible + end end describe "looking ahead" do @@ -118,8 +122,9 @@ class Schema < GraphQL::Schema } GRAPHQL } + let(:schema) { LookaheadTest::Schema } let(:query) { - GraphQL::Query.new(LookaheadTest::Schema, document: document, variables: { name: "Cardinal" }) + GraphQL::Query.new(schema, document: document, variables: { name: "Cardinal" }) } it "has a good test setup" do @@ -139,6 +144,18 @@ class Schema < GraphQL::Schema assert_equal true, query.lookahead.selects?("__typename") end + describe "with a NullWarden" do + let(:schema) { LookaheadTest::AlwaysVisibleSchema } + + it "works" do + lookahead = query.lookahead.selection("findBirdSpecies") + assert_equal true, lookahead.selects?("similarSpecies") + assert_equal true, lookahead.selects?(:similar_species) + assert_equal false, lookahead.selects?("isWaterfowl") + assert_equal false, lookahead.selects?(:is_waterfowl) + end + end + describe "on unions" do let(:document) { GraphQL.parse <<-GRAPHQL