Skip to content

Commit

Permalink
accept a method to override graphql error formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jaemk committed Aug 17, 2020
1 parent 08e533b commit 31b3f10
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion starlette/graphql.py
Expand Up @@ -26,9 +26,11 @@ def __init__(
executor: typing.Any = None,
executor_class: type = None,
graphiql: bool = True,
format_error: typing.Optional[typing.Callable[Exception, dict]] = None,
) -> None:
self.schema = schema
self.graphiql = graphiql
self._format_error_override = format_error
if executor is None:
# New style in 0.10.0. Use 'executor_class'.
# See issue https://github.com/encode/starlette/issues/242
Expand Down Expand Up @@ -116,7 +118,8 @@ async def handle_graphql(self, request: Request) -> Response:
)

def format_error(self, error: Exception) -> dict:
return format_graphql_error(error)
fmt = self._format_error_override or format_graphql_error
return fmt(error)

async def execute( # type: ignore
self, query, variables=None, context=None, operation_name=None
Expand Down

0 comments on commit 31b3f10

Please sign in to comment.