Skip to content

Commit

Permalink
Use latest graphql-core 3.1.0b1 instead of 3.0.3
Browse files Browse the repository at this point in the history
Adapt Schema, because there is no type reducer in core 3.1 any more.
  • Loading branch information
Cito committed Mar 4, 2020
1 parent ffb7701 commit 5e6f689
Show file tree
Hide file tree
Showing 13 changed files with 293 additions and 328 deletions.
2 changes: 1 addition & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[settings]
known_third_party = aniso8601,graphql,graphql_relay,promise,pytest,pytz,pyutils,setuptools,six,snapshottest,sphinx_graphene_theme
known_third_party = aniso8601,graphql,graphql_relay,promise,pytest,pytz,pyutils,setuptools,snapshottest,sphinx_graphene_theme
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,16 @@

snapshots[
"test_str_schema 1"
] = '''"""A faction in the Star Wars saga"""
] = '''type Query {
rebels: Faction
empire: Faction
node(
"""The ID of the object"""
id: ID!
): Node
}
"""A faction in the Star Wars saga"""
type Faction implements Node {
"""The ID of the object"""
id: ID!
Expand All @@ -43,28 +52,20 @@
ships(before: String = null, after: String = null, first: Int = null, last: Int = null): ShipConnection
}
input IntroduceShipInput {
shipName: String!
factionId: String!
clientMutationId: String
}
type IntroduceShipPayload {
ship: Ship
faction: Faction
clientMutationId: String
}
type Mutation {
introduceShip(input: IntroduceShipInput!): IntroduceShipPayload
}
"""An object with an ID"""
interface Node {
"""The ID of the object"""
id: ID!
}
type ShipConnection {
"""Pagination data for this connection."""
pageInfo: PageInfo!
"""Contains the nodes in this connection."""
edges: [ShipEdge]!
}
"""
The Relay compliant `PageInfo` type, containing data necessary to paginate this connection.
"""
Expand All @@ -82,13 +83,13 @@
endCursor: String
}
type Query {
rebels: Faction
empire: Faction
node(
"""The ID of the object"""
id: ID!
): Node
"""A Relay edge containing a `Ship` and its cursor."""
type ShipEdge {
"""The item at the end of the edge"""
node: Ship
"""A cursor for use in pagination"""
cursor: String!
}
"""A ship in the Star Wars saga"""
Expand All @@ -100,20 +101,19 @@
name: String
}
type ShipConnection {
"""Pagination data for this connection."""
pageInfo: PageInfo!
"""Contains the nodes in this connection."""
edges: [ShipEdge]!
type Mutation {
introduceShip(input: IntroduceShipInput!): IntroduceShipPayload
}
"""A Relay edge containing a `Ship` and its cursor."""
type ShipEdge {
"""The item at the end of the edge"""
node: Ship
type IntroduceShipPayload {
ship: Ship
faction: Faction
clientMutationId: String
}
"""A cursor for use in pagination"""
cursor: String!
input IntroduceShipInput {
shipName: String!
factionId: String!
clientMutationId: String
}
'''
2 changes: 1 addition & 1 deletion graphene/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from .utils.module_loading import lazy_import


VERSION = (3, 0, 0, "alpha", 1)
VERSION = (3, 0, 0, "beta", 0)


__version__ = get_version(VERSION)
Expand Down
12 changes: 6 additions & 6 deletions graphene/relay/tests/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,18 +183,18 @@ def test_str_schema():
name: String
}
type MyOtherNode implements Node {
"""An object with an ID"""
interface Node {
"""The ID of the object"""
id: ID!
shared: String
somethingElse: String
extraField: String
}
"""An object with an ID"""
interface Node {
type MyOtherNode implements Node {
"""The ID of the object"""
id: ID!
shared: String
somethingElse: String
extraField: String
}
type RootQuery {
Expand Down
22 changes: 11 additions & 11 deletions graphene/relay/tests/test_node_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@ def test_str_schema_correct():
query: RootQuery
}
interface BasePhoto {
"""The width of the photo in pixels"""
width: Int
type User implements Node {
"""The ID of the object"""
id: ID!
"""The full name of the user"""
name: String
}
interface Node {
Expand All @@ -77,20 +80,17 @@ def test_str_schema_correct():
width: Int
}
interface BasePhoto {
"""The width of the photo in pixels"""
width: Int
}
type RootQuery {
node(
"""The ID of the object"""
id: ID!
): Node
}
type User implements Node {
"""The ID of the object"""
id: ID!
"""The full name of the user"""
name: String
}
'''
)

Expand Down
2 changes: 1 addition & 1 deletion graphene/tests/issues/test_356.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Query(graphene.ObjectType):
graphene.Schema(query=Query)

assert str(exc_info.value) == (
"Query fields cannot be resolved:"
"Query fields cannot be resolved."
" IterableConnectionField type has to be a subclass of Connection."
' Received "MyUnion".'
)
81 changes: 49 additions & 32 deletions graphene/types/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import datetime

from aniso8601 import parse_date, parse_datetime, parse_time
from graphql import Undefined
from graphql.language import StringValueNode
from graphql.error import GraphQLError
from graphql.language import StringValueNode, print_ast

from .scalars import Scalar

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

@classmethod
def parse_literal(cls, node):
if isinstance(node, StringValueNode):
return cls.parse_value(node.value)
if not isinstance(node, StringValueNode):
raise GraphQLError(
"Date cannot represent non-string value: {}".format(print_ast(node))
)
return cls.parse_value(node.value)

@staticmethod
def parse_value(value):
if isinstance(value, datetime.date):
return value
if not isinstance(value, str):
raise GraphQLError(
"Date cannot represent non-string value: {}".format(repr(value))
)
try:
if isinstance(value, datetime.date):
return value
elif isinstance(value, str):
return parse_date(value)
return parse_date(value)
except ValueError:
return Undefined
raise GraphQLError("Date cannot represent value: {}".format(repr(value)))


class DateTime(Scalar):
Expand All @@ -50,25 +55,32 @@ class DateTime(Scalar):

@staticmethod
def serialize(dt):
assert isinstance(
dt, (datetime.datetime, datetime.date)
), 'Received not compatible datetime "{}"'.format(repr(dt))
if not isinstance(dt, (datetime.datetime, datetime.date)):
raise GraphQLError("DateTime cannot represent value: {}".format(repr(dt)))
return dt.isoformat()

@classmethod
def parse_literal(cls, node):
if isinstance(node, StringValueNode):
return cls.parse_value(node.value)
if not isinstance(node, StringValueNode):
raise GraphQLError(
"DateTime cannot represent non-string value: {}".format(print_ast(node))
)
return cls.parse_value(node.value)

@staticmethod
def parse_value(value):
if isinstance(value, datetime.datetime):
return value
if not isinstance(value, str):
raise GraphQLError(
"DateTime cannot represent non-string value: {}".format(repr(value))
)
try:
if isinstance(value, datetime.datetime):
return value
elif isinstance(value, str):
return parse_datetime(value)
return parse_datetime(value)
except ValueError:
return Undefined
raise GraphQLError(
"DateTime cannot represent value: {}".format(repr(value))
)


class Time(Scalar):
Expand All @@ -80,22 +92,27 @@ class Time(Scalar):

@staticmethod
def serialize(time):
assert isinstance(
time, datetime.time
), 'Received not compatible time "{}"'.format(repr(time))
if not isinstance(time, datetime.time):
raise GraphQLError("Time cannot represent value: {}".format(repr(time)))
return time.isoformat()

@classmethod
def parse_literal(cls, node):
if isinstance(node, StringValueNode):
return cls.parse_value(node.value)
if not isinstance(node, StringValueNode):
raise GraphQLError(
"Time cannot represent non-string value: {}".format(print_ast(node))
)
return cls.parse_value(node.value)

@classmethod
def parse_value(cls, value):
if isinstance(value, datetime.time):
return value
if not isinstance(value, str):
raise GraphQLError(
"Time cannot represent non-string value: {}".format(repr(value))
)
try:
if isinstance(value, datetime.time):
return value
elif isinstance(value, str):
return parse_time(value)
return parse_time(value)
except ValueError:
return Undefined
raise GraphQLError("Time cannot represent value: {}".format(repr(value)))
1 change: 1 addition & 0 deletions graphene/types/inputfield.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from graphql import Undefined

from .mountedtype import MountedType
from .structures import NonNull
from .utils import get_type
Expand Down
Loading

0 comments on commit 5e6f689

Please sign in to comment.