How useful is GraphQLError() provided in Graphene?

3k Views Asked by At

The python graphene documentation does not mention anything about graphQL error. Under what scenarios is it useful, does it have any advantage over a simple raise Exception('Authenication Failure : User is not registered') ?

I did my homework and found this in it's constructor,

def __init__(
    self,
    message,  # type: str
    nodes=None,  # type: Any
    stack=None,  # type: Optional[TracebackType]
    source=None,  # type: Optional[Any]
    positions=None,  # type: Optional[Any]
    locations=None,  # type: Optional[Any]
    path=None,  # type: Union[List[Union[int, str]], List[str], None]
    extensions=None,  # type: Optional[Dict[str, Any]]
)

But apart from message, I don't understand when the other options would be most useful. Some help would be greatly appreciated.

1

There are 1 best solutions below

0
On

The GraphQLError class on Graphene comes from graphql-core which is the Python implementation of GraphQL-JS, where you can find the same GraphQLError class.

This is used to get extra information about the location, the node kind and the stack trace of any validation/parsing error while executing a graphql query.

You can read more at the official spec doc :)