Skip to content

Commit 9c3e4bb

Browse files
authored
Merge pull request #1421 from Cito/upgrade-dev-env
Make Graphene compatible with GraphQL-Core 3.2
2 parents 4e8a1e6 + 9e7e08d commit 9c3e4bb

17 files changed

+80
-89
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ default_language_version:
33

44
repos:
55
- repo: https://github.com/pre-commit/pre-commit-hooks
6-
rev: v4.1.0
6+
rev: v4.2.0
77
hooks:
88
- id: check-merge-conflict
99
- id: check-json
@@ -17,11 +17,11 @@ repos:
1717
- id: trailing-whitespace
1818
exclude: README.md
1919
- repo: https://github.com/asottile/pyupgrade
20-
rev: v2.31.0
20+
rev: v2.32.1
2121
hooks:
2222
- id: pyupgrade
2323
- repo: https://github.com/ambv/black
24-
rev: 21.12b0
24+
rev: 22.3.0
2525
hooks:
2626
- id: black
2727
- repo: https://github.com/PyCQA/flake8

docs/conf.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,18 @@
6464
master_doc = "index"
6565

6666
# General information about the project.
67-
project = u"Graphene"
68-
copyright = u"Graphene 2016"
69-
author = u"Syrus Akbary"
67+
project = "Graphene"
68+
copyright = "Graphene 2016"
69+
author = "Syrus Akbary"
7070

7171
# The version info for the project you're documenting, acts as replacement for
7272
# |version| and |release|, also used in various other places throughout the
7373
# built documents.
7474
#
7575
# The short X.Y version.
76-
version = u"1.0"
76+
version = "1.0"
7777
# The full version, including alpha/beta/rc tags.
78-
release = u"1.0"
78+
release = "1.0"
7979

8080
# The language for content autogenerated by Sphinx. Refer to documentation
8181
# for a list of supported languages.
@@ -278,7 +278,7 @@
278278
# (source start file, target name, title,
279279
# author, documentclass [howto, manual, or own class]).
280280
latex_documents = [
281-
(master_doc, "Graphene.tex", u"Graphene Documentation", u"Syrus Akbary", "manual")
281+
(master_doc, "Graphene.tex", "Graphene Documentation", "Syrus Akbary", "manual")
282282
]
283283

284284
# The name of an image file (relative to this directory) to place at the top of
@@ -318,7 +318,7 @@
318318

319319
# One entry per manual page. List of tuples
320320
# (source start file, name, description, authors, manual section).
321-
man_pages = [(master_doc, "graphene", u"Graphene Documentation", [author], 1)]
321+
man_pages = [(master_doc, "graphene", "Graphene Documentation", [author], 1)]
322322

323323
# If true, show URL addresses after external links.
324324
#
@@ -334,7 +334,7 @@
334334
(
335335
master_doc,
336336
"Graphene",
337-
u"Graphene Documentation",
337+
"Graphene Documentation",
338338
author,
339339
"Graphene",
340340
"One line description of project.",

examples/starwars_relay/tests/snapshots/snap_test_objectidentification.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,4 @@
115115
shipName: String!
116116
factionId: String!
117117
clientMutationId: String
118-
}
119-
'''
118+
}'''

examples/starwars_relay/tests/test_objectidentification.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
def test_str_schema(snapshot):
12-
snapshot.assert_match(str(schema))
12+
snapshot.assert_match(str(schema).strip())
1313

1414

1515
def test_correctly_fetches_id_name_rebels(snapshot):

graphene/relay/tests/test_node.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import re
2-
from graphql_relay import to_global_id
2+
from textwrap import dedent
33

4-
from graphene.tests.utils import dedent
4+
from graphql_relay import to_global_id
55

66
from ...types import ObjectType, Schema, String
77
from ..node import Node, is_node
@@ -171,8 +171,10 @@ def test_node_field_only_lazy_type_wrong():
171171

172172

173173
def test_str_schema():
174-
assert str(schema) == dedent(
175-
'''
174+
assert (
175+
str(schema).strip()
176+
== dedent(
177+
'''
176178
schema {
177179
query: RootQuery
178180
}
@@ -213,4 +215,5 @@ def test_str_schema():
213215
): MyNode
214216
}
215217
'''
218+
).strip()
216219
)

graphene/relay/tests/test_node_custom.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from graphql import graphql_sync
1+
from textwrap import dedent
22

3-
from graphene.tests.utils import dedent
3+
from graphql import graphql_sync
44

55
from ...types import Interface, ObjectType, Schema
66
from ...types.scalars import Int, String
@@ -54,8 +54,10 @@ class RootQuery(ObjectType):
5454

5555

5656
def test_str_schema_correct():
57-
assert str(schema) == dedent(
58-
'''
57+
assert (
58+
str(schema).strip()
59+
== dedent(
60+
'''
5961
schema {
6062
query: RootQuery
6163
}
@@ -93,6 +95,7 @@ def test_str_schema_correct():
9395
): Node
9496
}
9597
'''
98+
).strip()
9699
)
97100

98101

graphene/test/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
from promise import Promise, is_thenable
2-
from graphql.error import format_error as format_graphql_error
32
from graphql.error import GraphQLError
43

54
from graphene.types.schema import Schema
65

76

87
def default_format_error(error):
98
if isinstance(error, GraphQLError):
10-
return format_graphql_error(error)
9+
return error.formatted
1110
return {"message": str(error)}
1211

1312

graphene/tests/utils.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

graphene/types/definitions.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
GraphQLObjectType,
88
GraphQLScalarType,
99
GraphQLUnionType,
10-
Undefined,
1110
)
1211

1312

@@ -50,7 +49,7 @@ def serialize(self, value):
5049
try:
5150
value = enum[value]
5251
except KeyError:
53-
return Undefined
52+
pass
5453
return super(GrapheneEnumType, self).serialize(value)
5554

5655

graphene/types/scalars.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class String(Scalar):
143143
@staticmethod
144144
def coerce_string(value):
145145
if isinstance(value, bool):
146-
return u"true" if value else u"false"
146+
return "true" if value else "false"
147147
return str(value)
148148

149149
serialize = coerce_string

graphene/types/schema.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -376,19 +376,11 @@ def get_function_for_type(self, graphene_type, func_name, name, default_value):
376376
def resolve_type(self, resolve_type_func, type_name, root, info, _type):
377377
type_ = resolve_type_func(root, info)
378378

379-
if not type_:
380-
return_type = self[type_name]
381-
return default_type_resolver(root, info, return_type)
382-
383379
if inspect.isclass(type_) and issubclass(type_, ObjectType):
384-
graphql_type = self.get(type_._meta.name)
385-
assert graphql_type, f"Can't find type {type_._meta.name} in schema"
386-
assert (
387-
graphql_type.graphene_type == type_
388-
), f"The type {type_} does not match with the associated graphene type {graphql_type.graphene_type}."
389-
return graphql_type
380+
return type_._meta.name
390381

391-
return type_
382+
return_type = self[type_name]
383+
return default_type_resolver(root, info, return_type)
392384

393385

394386
class Schema:

graphene/types/tests/test_enum.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -251,19 +251,22 @@ def resolve_color(_, info):
251251

252252
schema = Schema(query=Query)
253253

254-
assert str(schema) == dedent(
255-
'''\
256-
type Query {
257-
color: Color!
258-
}
254+
assert (
255+
str(schema).strip()
256+
== dedent(
257+
'''
258+
type Query {
259+
color: Color!
260+
}
259261
260-
"""Primary colors"""
261-
enum Color {
262-
RED
263-
YELLOW
264-
BLUE
265-
}
266-
'''
262+
"""Primary colors"""
263+
enum Color {
264+
RED
265+
YELLOW
266+
BLUE
267+
}
268+
'''
269+
).strip()
267270
)
268271

269272

@@ -345,10 +348,7 @@ def resolve_color(_, info):
345348

346349
results = schema.execute("query { color }")
347350
assert results.errors
348-
assert (
349-
results.errors[0].message
350-
== "Expected a value of type 'Color' but received: 'BLACK'"
351-
)
351+
assert results.errors[0].message == "Enum 'Color' cannot represent value: 'BLACK'"
352352

353353

354354
def test_field_enum_argument():
@@ -460,12 +460,13 @@ class Query(ObjectType):
460460

461461
schema = Schema(query=Query, mutation=MyMutation)
462462
result = schema.execute(
463-
""" mutation MyMutation {
464-
createPaint(colorInput: { color: RED }) {
465-
color
463+
"""
464+
mutation MyMutation {
465+
createPaint(colorInput: { color: RED }) {
466+
color
467+
}
466468
}
467-
}
468-
"""
469+
"""
469470
)
470471
assert not result.errors
471472
assert result.data == {"createPaint": {"color": "RED"}}

graphene/types/tests/test_scalar.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ class JSONScalar(Scalar):
1111

1212

1313
def test_ints():
14-
assert Int.parse_value(2 ** 31 - 1) is not None
14+
assert Int.parse_value(2**31 - 1) is not None
1515
assert Int.parse_value("2.0") is not None
16-
assert Int.parse_value(2 ** 31) is None
16+
assert Int.parse_value(2**31) is None
1717

18-
assert Int.parse_literal(IntValueNode(value=str(2 ** 31 - 1))) == 2 ** 31 - 1
19-
assert Int.parse_literal(IntValueNode(value=str(2 ** 31))) is None
18+
assert Int.parse_literal(IntValueNode(value=str(2**31 - 1))) == 2**31 - 1
19+
assert Int.parse_literal(IntValueNode(value=str(2**31))) is None
2020

21-
assert Int.parse_value(-(2 ** 31)) is not None
22-
assert Int.parse_value(-(2 ** 31) - 1) is None
21+
assert Int.parse_value(-(2**31)) is not None
22+
assert Int.parse_value(-(2**31) - 1) is None
2323

24-
assert BigInt.parse_value(2 ** 31) is not None
24+
assert BigInt.parse_value(2**31) is not None
2525
assert BigInt.parse_value("2.0") is not None
26-
assert BigInt.parse_value(-(2 ** 31) - 1) is not None
26+
assert BigInt.parse_value(-(2**31) - 1) is not None
2727

28-
assert BigInt.parse_literal(IntValueNode(value=str(2 ** 31 - 1))) == 2 ** 31 - 1
29-
assert BigInt.parse_literal(IntValueNode(value=str(2 ** 31))) == 2 ** 31
28+
assert BigInt.parse_literal(IntValueNode(value=str(2**31 - 1))) == 2**31 - 1
29+
assert BigInt.parse_literal(IntValueNode(value=str(2**31))) == 2**31

graphene/types/tests/test_scalars_serialization.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def test_serializes_output_string():
3838
assert String.serialize(-1.1) == "-1.1"
3939
assert String.serialize(True) == "true"
4040
assert String.serialize(False) == "false"
41-
assert String.serialize(u"\U0001F601") == u"\U0001F601"
41+
assert String.serialize("\U0001F601") == "\U0001F601"
4242

4343

4444
def test_serializes_output_boolean():

graphene/types/tests/test_schema.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
from graphql.type import GraphQLObjectType, GraphQLSchema
1+
from textwrap import dedent
2+
23
from pytest import raises
34

4-
from graphene.tests.utils import dedent
5+
from graphql.type import GraphQLObjectType, GraphQLSchema
56

67
from ..field import Field
78
from ..objecttype import ObjectType
@@ -43,8 +44,10 @@ def test_schema_get_type_error():
4344

4445
def test_schema_str():
4546
schema = Schema(Query)
46-
assert str(schema) == dedent(
47-
"""
47+
assert (
48+
str(schema).strip()
49+
== dedent(
50+
"""
4851
type Query {
4952
inner: MyOtherType
5053
}
@@ -53,6 +56,7 @@ def test_schema_str():
5356
field: String
5457
}
5558
"""
59+
).strip()
5660
)
5761

5862

setup.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ def run_tests(self):
5353
"snapshottest>=0.6,<1",
5454
"coveralls>=3.3,<4",
5555
"promise>=2.3,<3",
56-
"mock>=4.0,<5",
57-
"pytz==2021.3",
56+
"mock>=4,<5",
57+
"pytz==2022.1",
5858
"iso8601>=1,<2",
5959
]
6060

61-
dev_requires = ["black==19.10b0", "flake8>=3.7,<4"] + tests_require
61+
dev_requires = ["black==22.3.0", "flake8>=4,<5"] + tests_require
6262

6363
setup(
6464
name="graphene",
@@ -84,8 +84,8 @@ def run_tests(self):
8484
keywords="api graphql protocol rest relay graphene",
8585
packages=find_packages(exclude=["examples*"]),
8686
install_requires=[
87-
"graphql-core~=3.1.2",
88-
"graphql-relay>=3.0,<4",
87+
"graphql-core>=3.1,<3.3",
88+
"graphql-relay>=3.1,<3.3",
8989
"aniso8601>=8,<10",
9090
],
9191
tests_require=tests_require,

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ commands =
2222
[testenv:mypy]
2323
basepython = python3.9
2424
deps =
25-
mypy>=0.931,<1
25+
mypy>=0.950,<1
2626
commands =
2727
mypy graphene
2828

0 commit comments

Comments
 (0)