Skip to content

Minor Request: assertUserError #14

@machineghost

Description

@machineghost

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions