Skip to content

Commit d39dbcf

Browse files
Fix the issues with graphql core 3.2.7 (#405)
* Fix the issues with graphql core 3.2.7 * bump graphql core support to >=3.2.7
1 parent d192392 commit d39dbcf

File tree

21 files changed

+249
-392
lines changed

21 files changed

+249
-392
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ classifiers = [
2727

2828
dependencies = [
2929
"click~=8.3",
30-
"graphql-core>=3.2.0,<3.3",
30+
"graphql-core>=3.2.7,<3.3",
3131
"toml~=0.10",
3232
"httpx~=0.28",
3333
"pydantic>=2.0.0,<3.0.0",

tests/client_generators/test_input_fields.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@
66
BooleanValueNode,
77
EnumValueNode,
88
FloatValueNode,
9+
GraphQLBoolean,
910
GraphQLEnumType,
1011
GraphQLEnumValueMap,
12+
GraphQLFloat,
13+
GraphQLID,
1114
GraphQLInputObjectType,
15+
GraphQLInt,
1216
GraphQLList,
1317
GraphQLNonNull,
1418
GraphQLScalarType,
19+
GraphQLString,
1520
IntValueNode,
1621
ListValueNode,
1722
NameNode,
@@ -42,31 +47,31 @@
4247
@pytest.mark.parametrize(
4348
"type_, expected_annotation",
4449
[
45-
(GraphQLNonNull(GraphQLScalarType("String")), ast.Name(id="str")),
46-
(GraphQLNonNull(GraphQLScalarType("ID")), ast.Name(id="str")),
47-
(GraphQLNonNull(GraphQLScalarType("Int")), ast.Name(id="int")),
48-
(GraphQLNonNull(GraphQLScalarType("Boolean")), ast.Name(id="bool")),
49-
(GraphQLNonNull(GraphQLScalarType("Float")), ast.Name(id="float")),
50+
(GraphQLNonNull(GraphQLString), ast.Name(id="str")),
51+
(GraphQLNonNull(GraphQLID), ast.Name(id="str")),
52+
(GraphQLNonNull(GraphQLInt), ast.Name(id="int")),
53+
(GraphQLNonNull(GraphQLBoolean), ast.Name(id="bool")),
54+
(GraphQLNonNull(GraphQLFloat), ast.Name(id="float")),
5055
(GraphQLNonNull(GraphQLScalarType("Upload")), ast.Name(id=UPLOAD_CLASS_NAME)),
5156
(GraphQLNonNull(GraphQLScalarType("Other")), ast.Name(id="Any")),
5257
(
53-
GraphQLScalarType("String"),
58+
GraphQLString,
5459
ast.Subscript(value=ast.Name(id=OPTIONAL), slice=ast.Name(id="str")),
5560
),
5661
(
57-
GraphQLScalarType("ID"),
62+
GraphQLID,
5863
ast.Subscript(value=ast.Name(id=OPTIONAL), slice=ast.Name(id="str")),
5964
),
6065
(
61-
GraphQLScalarType("Int"),
66+
GraphQLInt,
6267
ast.Subscript(value=ast.Name(id=OPTIONAL), slice=ast.Name(id="int")),
6368
),
6469
(
65-
GraphQLScalarType("Boolean"),
70+
GraphQLBoolean,
6671
ast.Subscript(value=ast.Name(id=OPTIONAL), slice=ast.Name(id="bool")),
6772
),
6873
(
69-
GraphQLScalarType("Float"),
74+
GraphQLFloat,
7075
ast.Subscript(value=ast.Name(id=OPTIONAL), slice=ast.Name(id="float")),
7176
),
7277
(

tests/client_generators/test_result_fields.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@
77
FieldNode,
88
FragmentDefinitionNode,
99
FragmentSpreadNode,
10+
GraphQLBoolean,
1011
GraphQLEnumType,
1112
GraphQLEnumValueMap,
13+
GraphQLFloat,
14+
GraphQLID,
15+
GraphQLInt,
1216
GraphQLInterfaceType,
1317
GraphQLList,
1418
GraphQLNonNull,
1519
GraphQLObjectType,
1620
GraphQLScalarType,
1721
GraphQLSchema,
22+
GraphQLString,
1823
GraphQLUnionType,
1924
InlineFragmentNode,
2025
NamedTypeNode,
@@ -61,22 +66,22 @@
6166
[
6267
(
6368
INCLUDE_DIRECTIVE_NAME,
64-
GraphQLNonNull(GraphQLScalarType("String")),
69+
GraphQLNonNull(GraphQLString),
6570
ast.Subscript(value=ast.Name(id=OPTIONAL), slice=ast.Name(id="str")),
6671
),
6772
(
6873
INCLUDE_DIRECTIVE_NAME,
69-
GraphQLScalarType("String"),
74+
GraphQLString,
7075
ast.Subscript(value=ast.Name(id=OPTIONAL), slice=ast.Name(id="str")),
7176
),
7277
(
7378
SKIP_DIRECTIVE_NAME,
74-
GraphQLNonNull(GraphQLScalarType("String")),
79+
GraphQLNonNull(GraphQLString),
7580
ast.Subscript(value=ast.Name(id=OPTIONAL), slice=ast.Name(id="str")),
7681
),
7782
(
7883
SKIP_DIRECTIVE_NAME,
79-
GraphQLScalarType("String"),
84+
GraphQLString,
8085
ast.Subscript(value=ast.Name(id=OPTIONAL), slice=ast.Name(id="str")),
8186
),
8287
],
@@ -103,7 +108,7 @@ def test_parse_operation_field_returns_typename_annotation_with_multiple_values(
103108
annotation, _, _ = parse_operation_field(
104109
schema=GraphQLSchema(),
105110
field=FieldNode(name=NameNode(value=TYPENAME_FIELD_NAME)),
106-
type_=GraphQLNonNull(GraphQLScalarType("String")),
111+
type_=GraphQLNonNull(GraphQLString),
107112
typename_values=["TypeB", "TypeA"],
108113
)
109114

@@ -118,7 +123,7 @@ def test_parse_operation_field_returns_typename_annotation_with_single_value():
118123
annotation, _, _ = parse_operation_field(
119124
schema=GraphQLSchema(),
120125
field=FieldNode(name=NameNode(value=TYPENAME_FIELD_NAME)),
121-
type_=GraphQLNonNull(GraphQLScalarType("String")),
126+
type_=GraphQLNonNull(GraphQLString),
122127
typename_values=["TypeA"],
123128
)
124129

@@ -172,7 +177,7 @@ def test_parse_operation_field_returns_annotation_with_annotated_nested_unions()
172177
@pytest.mark.parametrize(
173178
"type_, expected_method_name",
174179
[
175-
(GraphQLScalarType("String"), "parse_scalar_type"),
180+
(GraphQLString, "parse_scalar_type"),
176181
(GraphQLInterfaceType("TestInterface", fields={}), "parse_interface_type"),
177182
(GraphQLObjectType("TestType", fields={}), "parse_object_type"),
178183
(
@@ -225,34 +230,34 @@ def test_parse_operation_field_type_calls_correct_method_for_type(
225230
@pytest.mark.parametrize(
226231
"type_, nullable, expected_annotation",
227232
[
228-
(GraphQLScalarType("String"), False, ast.Name(id="str")),
229-
(GraphQLScalarType("ID"), False, ast.Name(id="str")),
230-
(GraphQLScalarType("Int"), False, ast.Name(id="int")),
231-
(GraphQLScalarType("Boolean"), False, ast.Name(id="bool")),
232-
(GraphQLScalarType("Float"), False, ast.Name(id="float")),
233+
(GraphQLString, False, ast.Name(id="str")),
234+
(GraphQLID, False, ast.Name(id="str")),
235+
(GraphQLInt, False, ast.Name(id="int")),
236+
(GraphQLBoolean, False, ast.Name(id="bool")),
237+
(GraphQLFloat, False, ast.Name(id="float")),
233238
(GraphQLScalarType("Other"), False, ast.Name(id="Any")),
234239
(
235-
GraphQLScalarType("String"),
240+
GraphQLString,
236241
True,
237242
ast.Subscript(value=ast.Name(id=OPTIONAL), slice=ast.Name(id="str")),
238243
),
239244
(
240-
GraphQLScalarType("ID"),
245+
GraphQLID,
241246
True,
242247
ast.Subscript(value=ast.Name(id=OPTIONAL), slice=ast.Name(id="str")),
243248
),
244249
(
245-
GraphQLScalarType("Int"),
250+
GraphQLInt,
246251
True,
247252
ast.Subscript(value=ast.Name(id=OPTIONAL), slice=ast.Name(id="int")),
248253
),
249254
(
250-
GraphQLScalarType("Boolean"),
255+
GraphQLBoolean,
251256
True,
252257
ast.Subscript(value=ast.Name(id=OPTIONAL), slice=ast.Name(id="bool")),
253258
),
254259
(
255-
GraphQLScalarType("Float"),
260+
GraphQLFloat,
256261
True,
257262
ast.Subscript(value=ast.Name(id=OPTIONAL), slice=ast.Name(id="float")),
258263
),

tests/codegen/test_parsing_field_types.py

Lines changed: 39 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
11
import ast
2+
from typing import Any
23

34
import pytest
45
from graphql import (
6+
GraphQLBoolean,
57
GraphQLEnumType,
68
GraphQLEnumValue,
79
GraphQLField,
10+
GraphQLFloat,
11+
GraphQLID,
812
GraphQLInputField,
913
GraphQLInputObjectType,
14+
GraphQLInt,
1015
GraphQLInterfaceType,
1116
GraphQLList,
1217
GraphQLNonNull,
1318
GraphQLObjectType,
1419
GraphQLScalarType,
20+
GraphQLString,
1521
GraphQLUnionType,
1622
)
23+
from graphql.type.definition import GraphQLNamedType
1724

1825
from ariadne_codegen.client_generators.constants import (
1926
ANY,
@@ -26,43 +33,37 @@
2633

2734

2835
@pytest.mark.parametrize(
29-
"type_name, expected_repr",
36+
"type_, expected_repr",
3037
[
31-
("String", "str"),
32-
("ID", "str"),
33-
("Int", "int"),
34-
("Boolean", "bool"),
35-
("Float", "float"),
36-
("Unknown", ANY),
38+
(GraphQLString, "str"),
39+
(GraphQLID, "str"),
40+
(GraphQLInt, "int"),
41+
(GraphQLBoolean, "bool"),
42+
(GraphQLFloat, "float"),
43+
(GraphQLScalarType(name="Unknown"), ANY),
3744
],
3845
)
39-
def test_parse_field_type_given_scalar_type_returns_name_object(
40-
type_name, expected_repr
41-
):
42-
type_ = GraphQLScalarType(name=type_name)
43-
46+
def test_parse_field_type_given_scalar_type_returns_name_object(type_, expected_repr):
4447
result = parse_field_type(type_, False)
4548

4649
assert isinstance(result, ast.Name)
4750
assert result.id == expected_repr
4851

4952

5053
@pytest.mark.parametrize(
51-
"type_name, expected_repr",
54+
"type_, expected_repr",
5255
[
53-
("String", "str"),
54-
("ID", "str"),
55-
("Int", "int"),
56-
("Boolean", "bool"),
57-
("Float", "float"),
58-
("Unknown", ANY),
56+
(GraphQLString, "str"),
57+
(GraphQLID, "str"),
58+
(GraphQLInt, "int"),
59+
(GraphQLBoolean, "bool"),
60+
(GraphQLFloat, "float"),
61+
(GraphQLScalarType(name="Unknown"), ANY),
5962
],
6063
)
6164
def test_parse_field_type_given_scalar_type_returns_optional_annotation(
62-
type_name, expected_repr
65+
type_, expected_repr
6366
):
64-
type_ = GraphQLScalarType(name=type_name)
65-
6667
result = parse_field_type(type_, True)
6768

6869
assert isinstance(result, ast.Subscript)
@@ -80,7 +81,7 @@ def test_parse_field_type_given_custom_type_returns_name_object(type_class):
8081
type_name = "Xyz"
8182
type_ = type_class(
8283
name=type_name,
83-
fields={FIELD_CLASS: GraphQLField(type_=GraphQLScalarType(name="String"))},
84+
fields={FIELD_CLASS: GraphQLField(type_=GraphQLString)},
8485
)
8586

8687
result = parse_field_type(type_, False)
@@ -97,7 +98,7 @@ def test_parse_field_type_given_custom_type_returns_optional_annotation(type_cla
9798
type_name = "Xyz"
9899
type_ = type_class(
99100
name=type_name,
100-
fields={FIELD_CLASS: GraphQLField(type_=GraphQLScalarType(name="String"))},
101+
fields={FIELD_CLASS: GraphQLField(type_=GraphQLString)},
101102
)
102103

103104
result = parse_field_type(type_, True)
@@ -137,10 +138,8 @@ def test_parse_field_type_given_union_type_returns_union_annotation():
137138
name="xyz",
138139
types=[
139140
GraphQLObjectType(
140-
name="String",
141-
fields={
142-
FIELD_CLASS: GraphQLField(type_=GraphQLScalarType(name="String"))
143-
},
141+
name="TestType",
142+
fields={FIELD_CLASS: GraphQLField(type_=GraphQLString)},
144143
)
145144
],
146145
)
@@ -158,10 +157,8 @@ def test_parse_field_type_given_union_type_returns_optional_union_annotation():
158157
name="xyz",
159158
types=[
160159
GraphQLObjectType(
161-
name="String",
162-
fields={
163-
FIELD_CLASS: GraphQLField(type_=GraphQLScalarType(name="String"))
164-
},
160+
name="TestType",
161+
fields={FIELD_CLASS: GraphQLField(type_=GraphQLString)},
165162
)
166163
],
167164
)
@@ -178,7 +175,7 @@ def test_parse_field_type_given_union_type_returns_optional_union_annotation():
178175

179176

180177
def test_parse_field_type_given_list_type_returns_list_annotation():
181-
type_ = GraphQLList(GraphQLScalarType(name="String"))
178+
type_ = GraphQLList[GraphQLNamedType](GraphQLString)
182179

183180
result = parse_field_type(type_, False)
184181

@@ -188,7 +185,7 @@ def test_parse_field_type_given_list_type_returns_list_annotation():
188185

189186

190187
def test_parse_field_type_given_list_type_returns_optional_list_annotation():
191-
type_ = GraphQLList(GraphQLScalarType(name="String"))
188+
type_ = GraphQLList[GraphQLNamedType](GraphQLString)
192189

193190
result = parse_field_type(type_, True)
194191

@@ -203,20 +200,18 @@ def test_parse_field_type_given_list_type_returns_optional_list_annotation():
203200
@pytest.mark.parametrize(
204201
"subtype",
205202
[
206-
GraphQLScalarType(name="String"),
203+
GraphQLString,
207204
GraphQLObjectType(
208205
name="Xyz",
209-
fields={FIELD_CLASS: GraphQLField(type_=GraphQLScalarType(name="String"))},
206+
fields={FIELD_CLASS: GraphQLField(type_=GraphQLString)},
210207
),
211208
GraphQLInputObjectType(
212209
name="Xyz",
213-
fields={
214-
FIELD_CLASS: GraphQLInputField(type_=GraphQLScalarType(name="String"))
215-
},
210+
fields={FIELD_CLASS: GraphQLInputField(type_=GraphQLString)},
216211
),
217212
GraphQLInterfaceType(
218213
name="Xyz",
219-
fields={FIELD_CLASS: GraphQLField(type_=GraphQLScalarType(name="String"))},
214+
fields={FIELD_CLASS: GraphQLField(type_=GraphQLString)},
220215
),
221216
GraphQLEnumType(name="Xyz", values={"X": GraphQLEnumValue(value="X")}),
222217
],
@@ -232,7 +227,7 @@ def test_parse_field_type_given_non_null_type_returns_not_optional_annotation(
232227

233228

234229
def test_parse_field_type_given_non_null_list_type_returns_not_optional_annotation():
235-
type_ = GraphQLNonNull(GraphQLList(GraphQLScalarType(name="String")))
230+
type_ = GraphQLNonNull(GraphQLList(GraphQLString))
236231

237232
result = parse_field_type(type_)
238233

@@ -241,17 +236,13 @@ def test_parse_field_type_given_non_null_list_type_returns_not_optional_annotati
241236

242237

243238
def test_parse_field_type_given_non_null_union_type_returns_not_optional_annotation():
244-
type_ = GraphQLNonNull(
239+
type_ = GraphQLNonNull[Any](
245240
GraphQLUnionType(
246241
name="xyz",
247242
types=[
248243
GraphQLObjectType(
249-
name="String",
250-
fields={
251-
FIELD_CLASS: GraphQLField(
252-
type_=GraphQLScalarType(name="String")
253-
)
254-
},
244+
name="TestType",
245+
fields={FIELD_CLASS: GraphQLField(type_=GraphQLString)},
255246
)
256247
],
257248
)

0 commit comments

Comments
 (0)