Skip to content

Commit 5e6f689

Browse files
committed
Use latest graphql-core 3.1.0b1 instead of 3.0.3
Adapt Schema, because there is no type reducer in core 3.1 any more.
1 parent ffb7701 commit 5e6f689

File tree

13 files changed

+293
-328
lines changed

13 files changed

+293
-328
lines changed

.isort.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[settings]
2-
known_third_party = aniso8601,graphql,graphql_relay,promise,pytest,pytz,pyutils,setuptools,six,snapshottest,sphinx_graphene_theme
2+
known_third_party = aniso8601,graphql,graphql_relay,promise,pytest,pytz,pyutils,setuptools,snapshottest,sphinx_graphene_theme

examples/starwars_relay/tests/snapshots/snap_test_objectidentification.py

+36-36
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,16 @@
3131

3232
snapshots[
3333
"test_str_schema 1"
34-
] = '''"""A faction in the Star Wars saga"""
34+
] = '''type Query {
35+
rebels: Faction
36+
empire: Faction
37+
node(
38+
"""The ID of the object"""
39+
id: ID!
40+
): Node
41+
}
42+
43+
"""A faction in the Star Wars saga"""
3544
type Faction implements Node {
3645
"""The ID of the object"""
3746
id: ID!
@@ -43,28 +52,20 @@
4352
ships(before: String = null, after: String = null, first: Int = null, last: Int = null): ShipConnection
4453
}
4554
46-
input IntroduceShipInput {
47-
shipName: String!
48-
factionId: String!
49-
clientMutationId: String
50-
}
51-
52-
type IntroduceShipPayload {
53-
ship: Ship
54-
faction: Faction
55-
clientMutationId: String
56-
}
57-
58-
type Mutation {
59-
introduceShip(input: IntroduceShipInput!): IntroduceShipPayload
60-
}
61-
6255
"""An object with an ID"""
6356
interface Node {
6457
"""The ID of the object"""
6558
id: ID!
6659
}
6760
61+
type ShipConnection {
62+
"""Pagination data for this connection."""
63+
pageInfo: PageInfo!
64+
65+
"""Contains the nodes in this connection."""
66+
edges: [ShipEdge]!
67+
}
68+
6869
"""
6970
The Relay compliant `PageInfo` type, containing data necessary to paginate this connection.
7071
"""
@@ -82,13 +83,13 @@
8283
endCursor: String
8384
}
8485
85-
type Query {
86-
rebels: Faction
87-
empire: Faction
88-
node(
89-
"""The ID of the object"""
90-
id: ID!
91-
): Node
86+
"""A Relay edge containing a `Ship` and its cursor."""
87+
type ShipEdge {
88+
"""The item at the end of the edge"""
89+
node: Ship
90+
91+
"""A cursor for use in pagination"""
92+
cursor: String!
9293
}
9394
9495
"""A ship in the Star Wars saga"""
@@ -100,20 +101,19 @@
100101
name: String
101102
}
102103
103-
type ShipConnection {
104-
"""Pagination data for this connection."""
105-
pageInfo: PageInfo!
106-
107-
"""Contains the nodes in this connection."""
108-
edges: [ShipEdge]!
104+
type Mutation {
105+
introduceShip(input: IntroduceShipInput!): IntroduceShipPayload
109106
}
110107
111-
"""A Relay edge containing a `Ship` and its cursor."""
112-
type ShipEdge {
113-
"""The item at the end of the edge"""
114-
node: Ship
108+
type IntroduceShipPayload {
109+
ship: Ship
110+
faction: Faction
111+
clientMutationId: String
112+
}
115113
116-
"""A cursor for use in pagination"""
117-
cursor: String!
114+
input IntroduceShipInput {
115+
shipName: String!
116+
factionId: String!
117+
clientMutationId: String
118118
}
119119
'''

graphene/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
from .utils.module_loading import lazy_import
4343

4444

45-
VERSION = (3, 0, 0, "alpha", 1)
45+
VERSION = (3, 0, 0, "beta", 0)
4646

4747

4848
__version__ = get_version(VERSION)

graphene/relay/tests/test_node.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -183,18 +183,18 @@ def test_str_schema():
183183
name: String
184184
}
185185
186-
type MyOtherNode implements Node {
186+
"""An object with an ID"""
187+
interface Node {
187188
"""The ID of the object"""
188189
id: ID!
189-
shared: String
190-
somethingElse: String
191-
extraField: String
192190
}
193191
194-
"""An object with an ID"""
195-
interface Node {
192+
type MyOtherNode implements Node {
196193
"""The ID of the object"""
197194
id: ID!
195+
shared: String
196+
somethingElse: String
197+
extraField: String
198198
}
199199
200200
type RootQuery {

graphene/relay/tests/test_node_custom.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,12 @@ def test_str_schema_correct():
5959
query: RootQuery
6060
}
6161
62-
interface BasePhoto {
63-
"""The width of the photo in pixels"""
64-
width: Int
62+
type User implements Node {
63+
"""The ID of the object"""
64+
id: ID!
65+
66+
"""The full name of the user"""
67+
name: String
6568
}
6669
6770
interface Node {
@@ -77,20 +80,17 @@ def test_str_schema_correct():
7780
width: Int
7881
}
7982
83+
interface BasePhoto {
84+
"""The width of the photo in pixels"""
85+
width: Int
86+
}
87+
8088
type RootQuery {
8189
node(
8290
"""The ID of the object"""
8391
id: ID!
8492
): Node
8593
}
86-
87-
type User implements Node {
88-
"""The ID of the object"""
89-
id: ID!
90-
91-
"""The full name of the user"""
92-
name: String
93-
}
9494
'''
9595
)
9696

graphene/tests/issues/test_356.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Query(graphene.ObjectType):
2727
graphene.Schema(query=Query)
2828

2929
assert str(exc_info.value) == (
30-
"Query fields cannot be resolved:"
30+
"Query fields cannot be resolved."
3131
" IterableConnectionField type has to be a subclass of Connection."
3232
' Received "MyUnion".'
3333
)

graphene/types/datetime.py

+49-32
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import datetime
44

55
from aniso8601 import parse_date, parse_datetime, parse_time
6-
from graphql import Undefined
7-
from graphql.language import StringValueNode
6+
from graphql.error import GraphQLError
7+
from graphql.language import StringValueNode, print_ast
88

99
from .scalars import Scalar
1010

@@ -20,25 +20,30 @@ class Date(Scalar):
2020
def serialize(date):
2121
if isinstance(date, datetime.datetime):
2222
date = date.date()
23-
assert isinstance(
24-
date, datetime.date
25-
), 'Received not compatible date "{}"'.format(repr(date))
23+
if not isinstance(date, datetime.date):
24+
raise GraphQLError("Date cannot represent value: {}".format(repr(date)))
2625
return date.isoformat()
2726

2827
@classmethod
2928
def parse_literal(cls, node):
30-
if isinstance(node, StringValueNode):
31-
return cls.parse_value(node.value)
29+
if not isinstance(node, StringValueNode):
30+
raise GraphQLError(
31+
"Date cannot represent non-string value: {}".format(print_ast(node))
32+
)
33+
return cls.parse_value(node.value)
3234

3335
@staticmethod
3436
def parse_value(value):
37+
if isinstance(value, datetime.date):
38+
return value
39+
if not isinstance(value, str):
40+
raise GraphQLError(
41+
"Date cannot represent non-string value: {}".format(repr(value))
42+
)
3543
try:
36-
if isinstance(value, datetime.date):
37-
return value
38-
elif isinstance(value, str):
39-
return parse_date(value)
44+
return parse_date(value)
4045
except ValueError:
41-
return Undefined
46+
raise GraphQLError("Date cannot represent value: {}".format(repr(value)))
4247

4348

4449
class DateTime(Scalar):
@@ -50,25 +55,32 @@ class DateTime(Scalar):
5055

5156
@staticmethod
5257
def serialize(dt):
53-
assert isinstance(
54-
dt, (datetime.datetime, datetime.date)
55-
), 'Received not compatible datetime "{}"'.format(repr(dt))
58+
if not isinstance(dt, (datetime.datetime, datetime.date)):
59+
raise GraphQLError("DateTime cannot represent value: {}".format(repr(dt)))
5660
return dt.isoformat()
5761

5862
@classmethod
5963
def parse_literal(cls, node):
60-
if isinstance(node, StringValueNode):
61-
return cls.parse_value(node.value)
64+
if not isinstance(node, StringValueNode):
65+
raise GraphQLError(
66+
"DateTime cannot represent non-string value: {}".format(print_ast(node))
67+
)
68+
return cls.parse_value(node.value)
6269

6370
@staticmethod
6471
def parse_value(value):
72+
if isinstance(value, datetime.datetime):
73+
return value
74+
if not isinstance(value, str):
75+
raise GraphQLError(
76+
"DateTime cannot represent non-string value: {}".format(repr(value))
77+
)
6578
try:
66-
if isinstance(value, datetime.datetime):
67-
return value
68-
elif isinstance(value, str):
69-
return parse_datetime(value)
79+
return parse_datetime(value)
7080
except ValueError:
71-
return Undefined
81+
raise GraphQLError(
82+
"DateTime cannot represent value: {}".format(repr(value))
83+
)
7284

7385

7486
class Time(Scalar):
@@ -80,22 +92,27 @@ class Time(Scalar):
8092

8193
@staticmethod
8294
def serialize(time):
83-
assert isinstance(
84-
time, datetime.time
85-
), 'Received not compatible time "{}"'.format(repr(time))
95+
if not isinstance(time, datetime.time):
96+
raise GraphQLError("Time cannot represent value: {}".format(repr(time)))
8697
return time.isoformat()
8798

8899
@classmethod
89100
def parse_literal(cls, node):
90-
if isinstance(node, StringValueNode):
91-
return cls.parse_value(node.value)
101+
if not isinstance(node, StringValueNode):
102+
raise GraphQLError(
103+
"Time cannot represent non-string value: {}".format(print_ast(node))
104+
)
105+
return cls.parse_value(node.value)
92106

93107
@classmethod
94108
def parse_value(cls, value):
109+
if isinstance(value, datetime.time):
110+
return value
111+
if not isinstance(value, str):
112+
raise GraphQLError(
113+
"Time cannot represent non-string value: {}".format(repr(value))
114+
)
95115
try:
96-
if isinstance(value, datetime.time):
97-
return value
98-
elif isinstance(value, str):
99-
return parse_time(value)
116+
return parse_time(value)
100117
except ValueError:
101-
return Undefined
118+
raise GraphQLError("Time cannot represent value: {}".format(repr(value)))

graphene/types/inputfield.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from graphql import Undefined
2+
23
from .mountedtype import MountedType
34
from .structures import NonNull
45
from .utils import get_type

0 commit comments

Comments
 (0)