Skip to content

Commit

Permalink
Add automatic RecordInvalid handling in GraphQL
Browse files Browse the repository at this point in the history
  • Loading branch information
NuckChorris committed Oct 31, 2020
1 parent 910e033 commit 4a950a5
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions app/graphql/errors/active_record/record_invalid.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module Errors
module ActiveRecord
class RecordInvalid
def self.graphql_error(error)
record = error.record
errors = record.errors.map do |attribute, message|
{
code: 'ValidationError',
message: record.errors.full_message(attribute, message),
path: ['attributes', attribute.to_s.camelize(:lower)]
}
end

{
errors: errors
}
end
end
end
end

0 comments on commit 4a950a5

Please sign in to comment.