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

Minor Request: assertUserError #14

Open
machineghost opened this issue Feb 6, 2018 · 0 comments
Open

Minor Request: assertUserError #14

machineghost opened this issue Feb 6, 2018 · 0 comments

Comments

@machineghost
Copy link

machineghost commented Feb 6, 2018

Currently without graphql-errors one can do:

const assert = require('assert');
assert(false, 'something was missing');

But of course, if you do that inside a graphql-errors call that error will get masked. If you want to assert in a way that shows the user what went wrong you need to make your own assert:

const { UserError } = require('graphql-errors');
const assertUserError = (condition, message) => { 
    if(!condition) throw new UserError(message);
};

Obviously it's not a big deal to write the above function yourself, but since it's basically just a one-liner I thought it might be nice if such a method was provided as a convenience by the library:

const {  assertUserError } = require('graphql-errors');
assertUserError(false, 'something was missing');

If you think such a function is within the library's scope I'd be happy to provide a PR.

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

1 participant