Skip to content

How can I avoid repeated code in my mutations? #1288

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

Closed
IgnisDa opened this issue Nov 27, 2020 · 1 comment
Closed

How can I avoid repeated code in my mutations? #1288

IgnisDa opened this issue Nov 27, 2020 · 1 comment
Labels

Comments

@IgnisDa
Copy link

IgnisDa commented Nov 27, 2020

I find myself making this mutation often:

mutation {
  createMember(input: {name: "new name", email: "[email protected]", password: "123"}) {
    member {
      id
    }
    errors {
      field
      message
    }
  }
}

Similarly, I like to have an errors list returned in all my other mutations to make sure the mutation was performed correctly. This can be easily done for a single mutation by having a errors = graphene.List( graphene.NonNull(commons.Error), description='List of errors that occurred executing the mutation.', ) attribute in my schema.

But as my schema grows larger the amount of repeated code I have for these mutations increases.

Is there a way I can somehow abstract this errors attribute to a BaseMutation class and then inherit my mutations from that instead?

@hypnotic-frog
Copy link

This is not a bug of graphene. Error handling is out of the scope of this codebase and from Graphql definition in general, and is more a design desition of your particular implementation.

Please check out #902 for a more extensive discussion about some ways you could treat error handling in your queries or mutations.

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

No branches or pull requests

3 participants