diff --git a/lib/graphql/schema/visibility/profile.rb b/lib/graphql/schema/visibility/profile.rb index db609391c1..078c46ec33 100644 --- a/lib/graphql/schema/visibility/profile.rb +++ b/lib/graphql/schema/visibility/profile.rb @@ -159,7 +159,7 @@ def field(owner, field_name) end end end - visible_f.ensure_loaded + visible_f&.ensure_loaded elsif f && @cached_visible_fields[owner][f.ensure_loaded] f else diff --git a/spec/graphql/schema/visibility/profile_spec.rb b/spec/graphql/schema/visibility/profile_spec.rb index c36ba6851c..bed2358515 100644 --- a/spec/graphql/schema/visibility/profile_spec.rb +++ b/spec/graphql/schema/visibility/profile_spec.rb @@ -32,4 +32,29 @@ class Query < GraphQL::Schema::Object loaded_type_names = query.types.loaded_types.map(&:graphql_name).reject { |n| n.start_with?("__") }.sort assert_equal ["Boolean", "Query", "String", "Thing"], loaded_type_names end + + + describe "when multiple field implementations are all hidden" do + class EnsureLoadedFixSchema < GraphQL::Schema + class BaseField < GraphQL::Schema::Field + def visible?(...) + false + end + end + class Query < GraphQL::Schema::Object + field_class(BaseField) + + field :f1, String + field :f1, String + end + + query(Query) + use GraphQL::Schema::Visibility + end + + it "handles it without raising an error" do + result = EnsureLoadedFixSchema.execute("{ f1 }") + assert 1, result["errors"].size + end + end end