-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Investigate ability to improve error messages #128
Comments
Dealing with errors in mutationsThey occur due wrong user input and should provide useful feedback to the user. Solution was suggested by Dmitry Tsepelev in his article GraphQL on Rails: On the way to perfection. module Types
class ValidationErrorsType < Types::BaseObject
field :details, String, null: false
field :full_messages, [String], null: false
def details
object.details.to_json
end
end
end and customize type of returned object in mutation: module Mutations
class SignUp < BaseMutation
argument :input, Types::SignUpInput, required: true
field :authentication, Types::AuthenticationType, null: true
field :errors, Types::ValidationErrorsType, null: true
def resolve(input:)
signup_user = SignupUser.call(input.to_h)
if signup_user.success?
{ authentication: signup_user }
else
{ errors: signup_user.user.errors }
end
end
end
end But in this case we can miss other types of errors such as authentication errors or 'wrong file type' (when we try to upload avatar image). So maybe it would be better to define common module Types
class ErrorType < Types::BaseObject
field :message, String, null: false
end
end and use it like this: module Mutations
class SignUp < BaseMutation
argument :input, Types::SignUpInput, required: true
field :authentication, Types::AuthenticationType, null: true
field :errors, [Types::ErrorType], null: true
def resolve(input:)
signup_user = SignupUser.call(input.to_h)
if signup_user.success?
{ authentication: signup_user }
else
{ errors: signup_user.error_data }
end
end
end
end |
After discussing with FE developers I think we don't need to implement this feature for now |
The goal is to make error messages more readable and clear for FE applications. It would be nice if the structure of error message will be displayed in the docs
The text was updated successfully, but these errors were encountered: