async def observe_async_results(self, results: AsyncGenerator, operation_id: str) -> None: try: async for result in results: payload = {} if result.data: payload["data"] = result.data if result.errors: for error in result.errors: log_error(error, self.logger) payload["errors"] = [ format_error(error, self.debug) for error in result.errors ] await self.send_json({ "type": GQL_DATA, "id": operation_id, "payload": payload }) except Exception as error: if not isinstance(error, GraphQLError): error = GraphQLError(str(error), original_error=error) log_error(error, self.logger) payload = {"errors": [format_error(error, self.debug)]} await self.send_json({ "type": GQL_DATA, "id": operation_id, "payload": payload }) await self.send_json({"type": GQL_COMPLETE, "id": operation_id})
def test_default_formatter_fills_context_with_reprs_of_python_context( schema, erroring_resolvers, failing_repr_mock): result = graphql_sync(schema, "{ hello }") error = format_error(result.errors[0], debug=True) context = error["extensions"]["exception"]["context"] assert context["test_int"] == repr(123) assert context["test_str"] == repr("test") assert context["test_dict"] == repr({"test": "dict"}) assert context["test_failing_repr"] == repr(failing_repr_mock) assert context["test_obj"] == repr(erroring_resolvers)
def test_default_formatter_is_not_extending_plain_graphql_error(schema): result = graphql_sync(schema, "{ error }") error = format_error(result.errors[0], debug=True) assert error["extensions"]["exception"] is None
def test_default_formatter_extends_error_with_context(schema): result = graphql_sync(schema, "{ hello }") error = format_error(result.errors[0], debug=True) assert error["extensions"]["exception"]["context"]
def test_default_formatter_is_not_extending_error_by_default(schema): result = graphql_sync(schema, "{ hello }") error = format_error(result.errors[0]) assert not error.get("extensions")