Skip to content
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

Error exception definition for mutations #532

Closed
HenrikFricke opened this issue Nov 9, 2018 · 3 comments
Closed

Error exception definition for mutations #532

HenrikFricke opened this issue Nov 9, 2018 · 3 comments

Comments

@HenrikFricke
Copy link

HenrikFricke commented Nov 9, 2018

Hey,

I tried to find an issue for that, but I couldn't, so I'd like to open this one. I was wondering why there is no way to define exceptions in the schema for mutations. I know there are some workarounds for that, for instance adding the errors as part of the return value of the mutations, but I would rather prefer to throw an error and define it also in the schema.

If we take a look at a short example:

In this case, I want to provide a mutation to change a password, but it might be the case that the customer typed the wrong current password or the new password is not valid. I'd like to distinguish between those different validation errors to provide the proper error message in the user interface.

input ChangePasswordInput {
  current: String!
  new: String!
}

mutation {
  changePassword(password: ChangePasswordInput!): Profile
}

Let's say I want to write down the same mutation in thrift, then I could do something like that:

struct Profile {                            
    1: required string id;
}

service ProfileService {
    Profile changePassword(
        1: string current,
        2: string new
    ) throws (
        1: InvalidCurrentPasswordException invalidCurrentPasswordException
	2: InvalidNewPasswordException invalidNewPasswordException 
    )
}

With that, I could easily generate a TypeScript client, that also provides type definitions for the errors. I wish I could do the same with a GraphQL schema.

What's your opinion about that?

@cmonty
Copy link

cmonty commented Nov 9, 2018

Hey @HenrikFricke,

You're not alone in wanting different error definitions: #135 & #391 have both been reviewed and closed. I've also recently introduced #528 to at least require a client handle errors defined in mutations. Not sure if that could also help with generating Typescript clients, but I'd be interested in your thoughts.

@HenrikFricke
Copy link
Author

@cmonty Hey, thanks for pointing to your issue, I will continue to write down my thoughts there …

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@cmonty @HenrikFricke and others