Skip to content

Commit 9e7e08d

Browse files
committed
Make Graphene compatible with Core 3.2
1 parent e37ef00 commit 9e7e08d

File tree

11 files changed

+53
-62
lines changed

11 files changed

+53
-62
lines changed

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/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_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

0 commit comments

Comments
 (0)