diff --git a/lib/graphql/schema.rb b/lib/graphql/schema.rb index f8b3fd45fb..0a52b0ffc5 100644 --- a/lib/graphql/schema.rb +++ b/lib/graphql/schema.rb @@ -492,7 +492,7 @@ def mutation(new_mutation_object = nil, &lazy_load_block) nil elsif @mutation_object.is_a?(Proc) @mutation_object = @mutation_object.call - self.visibility&.mutation_configured(@query_object) + self.visibility&.mutation_configured(@mutation_object) @mutation_object else @mutation_object || find_inherited_value(:mutation) diff --git a/spec/graphql/schema/visibility_spec.rb b/spec/graphql/schema/visibility_spec.rb index bf9928475d..bd3fdd714c 100644 --- a/spec/graphql/schema/visibility_spec.rb +++ b/spec/graphql/schema/visibility_spec.rb @@ -121,9 +121,10 @@ class OrphanType < GraphQL::Schema::Object end end # This one is added before `Visibility` - mutation(Mutation) - use GraphQL::Schema::Visibility, preload: true subscription(Subscription) + use GraphQL::Schema::Visibility, preload: true + query { Query } + mutation { Mutation } orphan_types(OrphanType) module CustomIntrospection @@ -138,9 +139,15 @@ class DynamicFields < GraphQL::Introspection::DynamicFields it "still preloads" do assert_equal [], NoProfileSchema::Query.all_field_definitions.first.extensions.map(&:class) - NoProfileSchema.query(NoProfileSchema::Query) - assert_equal [NoProfileSchema::ExampleExtension], NoProfileSchema::Query.all_field_definitions.first.extensions.map(&:class) + assert_equal [], NoProfileSchema::Mutation.all_field_definitions.first.extensions.map(&:class) + NoProfileSchema.mutation assert_equal [NoProfileSchema::ExampleExtension], NoProfileSchema::Mutation.all_field_definitions.first.extensions.map(&:class) + # Didn't load this: + assert_equal [], NoProfileSchema::Query.all_field_definitions.first.extensions.map(&:class) + + NoProfileSchema.query + assert_equal [NoProfileSchema::ExampleExtension], NoProfileSchema::Query.all_field_definitions.first.extensions.map(&:class) + assert_equal [NoProfileSchema::ExampleExtension], NoProfileSchema::Subscription.all_field_definitions.first.extensions.map(&:class) assert_equal [NoProfileSchema::ExampleExtension, NoProfileSchema::OtherExampleExtension], NoProfileSchema::OrphanType.all_field_definitions.first.extensions.map(&:class) custom_int_field = NoProfileSchema::CustomIntrospection::DynamicFields.all_field_definitions.find { |f| f.original_name == :__hello }