-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add mutation for enum arg and result
- Loading branch information
Showing
9 changed files
with
69 additions
and
3 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,9 @@ | ||
from ariadne_graphql_modules import GraphQLEnum | ||
|
||
|
||
class RoleEnum(GraphQLEnum): | ||
__members__ = [ | ||
"ADMIN", | ||
"MEMBER", | ||
"GUEST", | ||
] |
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 |
---|---|---|
|
@@ -6,3 +6,4 @@ class User: | |
id: int | ||
username: str | ||
group_id: int | ||
role: 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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
from typing import Any | ||
|
||
from . import compare_roles | ||
from . import dates_delta | ||
|
||
mutations: list[Any] = [ | ||
compare_roles.Mutation, | ||
dates_delta.Mutation, | ||
] |
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 enum import IntEnum | ||
|
||
from ariadne_graphql_modules import GraphQLObject | ||
from graphql import GraphQLResolveInfo | ||
|
||
from ..enums.role import RoleEnum | ||
|
||
|
||
class RoleDiff(IntEnum): | ||
EQUAL = 0 | ||
A_GREATER = 1 | ||
A_LOWER = 2 | ||
|
||
|
||
class Mutation(GraphQLObject): | ||
@GraphQLObject.field(name="compareRoles") | ||
@staticmethod | ||
def resolveCompareRoles( | ||
obj, info: GraphQLResolveInfo, *, a: RoleEnum, b: RoleEnum | ||
) -> RoleDiff: | ||
index_a = RoleEnum.__members__.index(a) | ||
index_b = RoleEnum.__members__.index(b) | ||
|
||
if index_a == index_b: | ||
return RoleDiff.EQUAL | ||
|
||
if index_a < index_b: | ||
return RoleDiff.A_GREATER | ||
|
||
return RoleDiff.A_LOWER |
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