-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_default_conversion_type_name.py
59 lines (47 loc) · 1.21 KB
/
test_default_conversion_type_name.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
from dataclasses import dataclass
from graphql.utilities import print_schema
from apischema import serializer
from apischema.graphql import graphql_schema
from apischema.json_schema import serialization_schema
@dataclass
class A:
a: int
@dataclass
class B:
b: int
@serializer
def to_a(self) -> A:
return A(self.b)
def b() -> B:
return B(0)
def test_default_conversion_type_name():
assert (
print_schema(graphql_schema(query=[b]))
== """\
type Query {
b: B!
}
type B {
a: Int!
}"""
)
assert serialization_schema(B, all_refs=True) == {
"$ref": "#/$defs/B",
"$defs": {
"B": {"$ref": "#/$defs/A"},
"A": {
"type": "object",
"properties": {"a": {"type": "integer"}},
"required": ["a"],
"additionalProperties": False,
},
},
"$schema": "http://json-schema.org/draft/2020-12/schema#",
}
assert serialization_schema(B) == {
"type": "object",
"properties": {"a": {"type": "integer"}},
"required": ["a"],
"additionalProperties": False,
"$schema": "http://json-schema.org/draft/2020-12/schema#",
}