-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Proxy errors and extensions in ProxySchema
- Loading branch information
Showing
3 changed files
with
99 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from typing import List, Optional, Tuple | ||
|
||
from ariadne.types import BaseProxyRootValue, GraphQLResult | ||
|
||
|
||
class ProxyRootValue(BaseProxyRootValue): | ||
__slots__ = ("root_value", "errors", "extensions") | ||
|
||
def __init__( | ||
self, | ||
root_value: Optional[dict] = None, | ||
errors: Optional[List[dict]] = None, | ||
extensions: Optional[dict] = None, | ||
): | ||
super().__init__(root_value) | ||
self.errors = errors | ||
self.extensions = extensions | ||
|
||
def update_result(self, result: Tuple[bool, dict]) -> Tuple[bool, dict]: | ||
success, data = super().update_result(result) | ||
|
||
if self.errors: | ||
data.setdefault("errors", []) | ||
data["errors"] += self.errors | ||
|
||
if self.extensions: | ||
data.setdefault("extensions", {}) | ||
data["extensions"].update(self.extensions) | ||
|
||
return success, data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters