Skip to content

Commit

Permalink
Fix FancyMutation logic for GraphQL 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
NuckChorris committed Apr 22, 2024
1 parent 3eb3a31 commit 84b2a3d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions app/graphql/concerns/fancy_mutation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,21 @@ def resolve(input:, ignore_warnings: false)
# mutation's #ready? and #authorized? methods, detecting the state of the error object after
# execution and changing the result if needed.
def ready?(input:)
ready, result = super(**input)
result = super(**input)

return [false, { errors: }] if errors.present?

[ready, result]
result
rescue ErrorWrapper => e
[false, { errors: [*errors, e.error] }]
end

def authorized?(input:)
ready, result = super(**input)
result = super(**input)

return [false, { errors: }] if errors.present?

[ready, result]
result
rescue ErrorWrapper => e
[false, { errors: [*errors, e.error] }]
end
Expand Down
4 changes: 2 additions & 2 deletions spec/graphql/concerns/fancy_mutation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
include FancyMutation

def ready?(**)
[true, 'test']
true
end
end

result = mutation.new.ready?(input: {})
expect(result).to eq([true, 'test'])
expect(result).to be(true)
end
end

Expand Down

0 comments on commit 84b2a3d

Please sign in to comment.