According to the documentation in https://www.howtographql.com/graphql-python/6-error-handling/ I use raise GraphQLError
to show errors in my Flask GraphQL app mutate functions, like this one:
import graphene
from graphql import GraphQLError
from ...extensions import db
from ...models import User as UserModel
from ..types import User as UserType
class Update(graphene.Mutation):
class Input:
id = graphene.ID(required=True)
# phone = graphene.String()
name = graphene.String(required=False, default_value=None)
# active = graphene.Boolean()
Output = UserType
@staticmethod
def mutate(root, info, **kwargs):
user = graphene.Node.get_node_from_global_id(info, kwargs.pop('id'))
# print(info.context)
# if not user:
raise GraphQLError('eeee')
# user.update(**kwargs)
# db.session.commit()
return user
I'm expecting to get something like a 400 status code with graphql error json schema. But I get 200 and also the exception is printed in console with traceback. Am I doing something wrong here?
An error occurred while resolving field Mutation.updateUser
Traceback (most recent call last):
File "/.local/share/virtualenvs/Server-CvYlbWSB/lib/python3.7/site-packages/graphql/execution/executor.py", line 447, in resolve_or_error
return executor.execute(resolve_fn, source, info, **args)
File "/.local/share/virtualenvs/Server-CvYlbWSB/lib/python3.7/site-packages/graphql/execution/executors/sync.py", line 16, in execute
return fn(*args, **kwargs)
File "/application/schema/mutation/user.py", line 40, in mutate
raise GraphQLError('eeee')
graphql.error.base.GraphQLError: eeee
Traceback (most recent call last):
File "/.local/share/virtualenvs/Server-CvYlbWSB/lib/python3.7/site-packages/graphql/execution/executor.py", line 447, in resolve_or_error
return executor.execute(resolve_fn, source, info, **args)
File "/.local/share/virtualenvs/Server-CvYlbWSB/lib/python3.7/site-packages/graphql/execution/executors/sync.py", line 16, in execute
return fn(*args, **kwargs)
File "/application/schema/mutation/user.py", line 40, in mutate
raise GraphQLError('eeee')
graphql.error.located_error.GraphQLLocatedError: eeee
127.0.0.1 - - [17/Oct/2018 01:46:54] "POST /graphql? HTTP/1.1" 200 -