Skip to content

Commit

Permalink
move graphql error formatting to a function that can be overridden
Browse files Browse the repository at this point in the history
  • Loading branch information
jaemk committed Aug 17, 2020
1 parent c566fc6 commit 08e533b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions starlette/graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,7 @@ async def handle_graphql(self, request: Request) -> Response:
query, variables=variables, context=context, operation_name=operation_name
)
error_data = (
[format_graphql_error(err) for err in result.errors]
if result.errors
else None
[self.format_error(err) for err in result.errors] if result.errors else None
)
response_data = {"data": result.data}
if error_data:
Expand All @@ -117,6 +115,9 @@ async def handle_graphql(self, request: Request) -> Response:
response_data, status_code=status_code, background=background
)

def format_error(self, error: Exception) -> dict:
return format_graphql_error(error)

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

0 comments on commit 08e533b

Please sign in to comment.