Commit 323f5146 authored by Luke Duncalfe's avatar Luke Duncalfe

Use GraphQL errors_on_object for collecting errors

Around 50% of our mutations were calling `object.errors.full_messages`
within their `#resolve` method, while others were using the
`#errors_on_object` helper in `BaseMutation`.

This MR changes all mutations to use `#errors_on_object`, and tweaks
the GraphQL API developer docs to mention the helper.
parent b94dac6a
...@@ -9,7 +9,7 @@ module Mutations ...@@ -9,7 +9,7 @@ module Mutations
field :errors, [GraphQL::STRING_TYPE], field :errors, [GraphQL::STRING_TYPE],
null: false, null: false,
description: "Errors encountered during execution of the mutation." description: 'Errors encountered during execution of the mutation.'
def current_user def current_user
context[:current_user] context[:current_user]
......
...@@ -19,7 +19,7 @@ module Mutations ...@@ -19,7 +19,7 @@ module Mutations
{ {
issue: issue, issue: issue,
errors: issue.errors.full_messages errors: errors_on_object(issue)
} }
end end
end end
......
...@@ -19,7 +19,7 @@ module Mutations ...@@ -19,7 +19,7 @@ module Mutations
{ {
issue: issue, issue: issue,
errors: issue.errors.full_messages errors: errors_on_object(issue)
} }
end end
end end
......
...@@ -33,7 +33,7 @@ module Mutations ...@@ -33,7 +33,7 @@ module Mutations
{ {
issue: issue, issue: issue,
errors: issue.errors.full_messages errors: errors_on_object(issue)
} }
end end
end end
......
...@@ -40,7 +40,7 @@ module Mutations ...@@ -40,7 +40,7 @@ module Mutations
{ {
merge_request: merge_request, merge_request: merge_request,
errors: merge_request.errors.full_messages errors: errors_on_object(merge_request)
} }
end end
end end
......
...@@ -41,7 +41,7 @@ module Mutations ...@@ -41,7 +41,7 @@ module Mutations
{ {
merge_request: merge_request, merge_request: merge_request,
errors: merge_request.errors.full_messages errors: errors_on_object(merge_request)
} }
end end
......
...@@ -21,7 +21,7 @@ module Mutations ...@@ -21,7 +21,7 @@ module Mutations
{ {
merge_request: merge_request, merge_request: merge_request,
errors: merge_request.errors.full_messages errors: errors_on_object(merge_request)
} }
end end
end end
......
...@@ -22,7 +22,7 @@ module Mutations ...@@ -22,7 +22,7 @@ module Mutations
{ {
merge_request: merge_request, merge_request: merge_request,
errors: merge_request.errors.full_messages errors: errors_on_object(merge_request)
} }
end end
end end
......
...@@ -18,7 +18,7 @@ module Mutations ...@@ -18,7 +18,7 @@ module Mutations
{ {
merge_request: merge_request, merge_request: merge_request,
errors: merge_request.errors.full_messages errors: errors_on_object(merge_request)
} }
end end
end end
......
...@@ -21,7 +21,7 @@ module Mutations ...@@ -21,7 +21,7 @@ module Mutations
{ {
merge_request: merge_request, merge_request: merge_request,
errors: merge_request.errors.full_messages errors: errors_on_object(merge_request)
} }
end end
......
...@@ -690,8 +690,9 @@ should look like this: ...@@ -690,8 +690,9 @@ should look like this:
# The merge request modified, this will be wrapped in the type # The merge request modified, this will be wrapped in the type
# defined on the field # defined on the field
merge_request: merge_request, merge_request: merge_request,
# An array if strings if the mutation failed after authorization # An array of strings if the mutation failed after authorization.
errors: merge_request.errors.full_messages # The `errors_on_object` helper collects `errors.full_messages`
errors: errors_on_object(merge_request)
} }
``` ```
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment