Skip to content

Commit

Permalink
Merge pull request #4491 from rmosolgo/fix-lookahead-null-warden
Browse files Browse the repository at this point in the history
Fix Lookahead with AlwaysVisible
  • Loading branch information
rmosolgo authored May 30, 2023
2 parents 8a8b5e3 + 57fc5c4 commit dae519b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/graphql/schema/warden.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 18 additions & 1 deletion spec/graphql/execution/lookahead_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit dae519b

Please sign in to comment.