-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: add a default global ID encoder, add a id_field on the query type
BREAKING CHANGE: the global ID function takes only a str with the GID, the query type uses the `id_field` arg to determine which kwarg to pass to the decoder
- Loading branch information
Showing
8 changed files
with
38 additions
and
18 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
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
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 |
---|---|---|
@@ -1,10 +1,11 @@ | ||
from collections import namedtuple | ||
from typing import Any, Callable, Dict | ||
from typing import Callable | ||
|
||
from typing_extensions import TypeVar | ||
|
||
from ariadne.contrib.relay.connection import RelayConnection | ||
|
||
ConnectionResolver = TypeVar("ConnectionResolver", bound=Callable[..., RelayConnection]) | ||
GlobalIDTuple = namedtuple("GlobalIDTuple", ["type", "id"]) | ||
GlobalIDDecoder = Callable[[Dict[str, Any]], GlobalIDTuple] | ||
GlobalIDDecoder = Callable[[str], GlobalIDTuple] | ||
GlobalIDEncoder = Callable[[str, str], str] |
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,13 @@ | ||
from base64 import b64decode, b64encode | ||
|
||
from ariadne.contrib.relay.types import ( | ||
GlobalIDTuple, | ||
) | ||
|
||
|
||
def decode_global_id(gid: str) -> GlobalIDTuple: | ||
return GlobalIDTuple(*b64decode(gid).decode().split(":")) | ||
|
||
|
||
def encode_global_id(type_name: str, _id: str) -> str: | ||
return b64encode(f"{type_name}:{_id}".encode()).decode() |
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
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