Skip to content

Commit

Permalink
Fix lazy mutation loading
Browse files Browse the repository at this point in the history
  • Loading branch information
rmosolgo committed Nov 11, 2024
1 parent a964042 commit 8ba1e31
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/graphql/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 11 additions & 4 deletions spec/graphql/schema/visibility_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }
Expand Down

0 comments on commit 8ba1e31

Please sign in to comment.