-
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.
- Loading branch information
Showing
3 changed files
with
50 additions
and
2 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 |
---|---|---|
@@ -1,9 +1,13 @@ | ||
from typing import Any | ||
|
||
from . import compare_roles | ||
from . import dates_delta | ||
from . import ( | ||
calc, | ||
compare_roles, | ||
dates_delta, | ||
) | ||
|
||
mutations: list[Any] = [ | ||
calc.Mutation, | ||
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,32 @@ | ||
from enum import StrEnum | ||
|
||
from ariadne_graphql_modules import GraphQLInput, GraphQLObject | ||
from graphql import GraphQLResolveInfo | ||
|
||
from ..scalars.date import DateScalar | ||
|
||
|
||
class CalcOperation(StrEnum): | ||
ADD = "add" | ||
SUB = "sub" | ||
MUL = "MUL" | ||
|
||
|
||
class CalcInput(GraphQLInput): | ||
a: int | ||
b: int | ||
op: CalcOperation | ||
|
||
|
||
class Mutation(GraphQLObject): | ||
@GraphQLObject.field(name="calc") | ||
@staticmethod | ||
def resolve_calc(obj, info: GraphQLResolveInfo, *, input: CalcInput) -> int: | ||
if input.op == CalcOperation.ADD: | ||
return input.a + input.b | ||
if input.op == CalcOperation.SUB: | ||
return input.a - input.b | ||
if input.op == CalcOperation.MUL: | ||
return input.a * input.b | ||
|
||
return 0 |
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