Skip to content

Instantly share code, notes, and snippets.

@frikille
Created June 22, 2017 12:06
Show Gist options
  • Save frikille/d6e86fdc33fb26a33d1daac0f752d9f5 to your computer and use it in GitHub Desktop.
Save frikille/d6e86fdc33fb26a33d1daac0f752d9f5 to your computer and use it in GitHub Desktop.
custom errors in graphql mutation
// query
mutation {
createUser(user: {username: "John Doe", email: "john.doe@test"}) {
user {
email
username
}
errors {
key
message
}
}
}
// response
{
data {
createUser {
user: null,
errors: [{
key: "email",
message: "Email address is invalid"
}]
}
}
}
type Mutation {
createUser(user: CreateUserInput!): UserMutationResponse
}
input CreateUserInput {
username
email
}
type CreateUserMutationResponse {
user: User
errors: [ServiceError]
}
type User {
email: String
username: String
}
type ServiceError {
key: String
message: String
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment