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.
Currently without
graphql-errorsone can do:But of course, if you do that inside a
graphql-errorscall 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 ownassert: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:
If you think such a function is within the library's scope I'd be happy to provide a PR.