/
test_issue185.py
94 lines (77 loc) · 2.4 KB
/
test_issue185.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from typing import Union
import pytest
from tartiflette import Resolver, create_engine
from tartiflette.constants import UNDEFINED_VALUE
from tartiflette.language.ast import StringValueNode
from tartiflette.scalar.scalar import Scalar
_SDL = """
scalar CapitalizedString
type Person {
name: CapitalizedString
}
type ComplexPerson {
name: CapitalizedString
father: Person
mother: Person
}
input PersonInput {
name: CapitalizedString
}
input ComplexInput {
name: CapitalizedString
father: PersonInput
mother: PersonInput
}
type Query {
person(name: CapitalizedString): Person
complexPerson(details: ComplexInput): ComplexPerson
}
"""
@pytest.fixture(scope="module")
async def ttftt_engine():
@Scalar("CapitalizedString", schema_name="test_issue185")
class CapitalizedString:
@staticmethod
def coerce_output(val) -> str:
return str(val)
@staticmethod
def coerce_input(val: str) -> str:
return val.capitalize()
@staticmethod
def parse_literal(ast: "Node") -> Union[str, "UNDEFINED_VALUE"]:
return (
ast.value.capitalize()
if isinstance(ast, StringValueNode)
else UNDEFINED_VALUE
)
@Resolver("Query.person", schema_name="test_issue185")
async def the_query_person_resolver(_parents, args, _ctx, _info):
return args
@Resolver("Query.complexPerson", schema_name="test_issue185")
async def the_query_complexPerson_resolver(_parents, args, _ctx, _info):
return args["details"]
return await create_engine(sdl=_SDL, schema_name="test_issue185")
@pytest.mark.asyncio
@pytest.mark.parametrize(
"query,expected",
[
(
'query { person(name: "jack") { name } }',
{"data": {"person": {"name": "Jack"}}},
),
(
'query { complexPerson(details: { name: "roger", father: { name: "jean"}, mother: {name: "regina"}}){ name father {name} mother {name}}}',
{
"data": {
"complexPerson": {
"name": "Roger",
"father": {"name": "Jean"},
"mother": {"name": "Regina"},
}
}
},
),
],
)
async def test_issue185(query, expected, ttftt_engine):
assert await ttftt_engine.execute(query) == expected