Skip to content

Make Graphene compatible with GraphQL-Core 3.2 #1421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ default_language_version:

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
rev: v4.2.0
hooks:
- id: check-merge-conflict
- id: check-json
Expand All @@ -17,11 +17,11 @@ repos:
- id: trailing-whitespace
exclude: README.md
- repo: https://github.com/asottile/pyupgrade
rev: v2.31.0
rev: v2.32.1
hooks:
- id: pyupgrade
- repo: https://github.com/ambv/black
rev: 21.12b0
rev: 22.3.0
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
Expand Down
16 changes: 8 additions & 8 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,18 @@
master_doc = "index"

# General information about the project.
project = u"Graphene"
copyright = u"Graphene 2016"
author = u"Syrus Akbary"
project = "Graphene"
copyright = "Graphene 2016"
author = "Syrus Akbary"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = u"1.0"
version = "1.0"
# The full version, including alpha/beta/rc tags.
release = u"1.0"
release = "1.0"

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

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

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

# If true, show URL addresses after external links.
#
Expand All @@ -334,7 +334,7 @@
(
master_doc,
"Graphene",
u"Graphene Documentation",
"Graphene Documentation",
author,
"Graphene",
"One line description of project.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,4 @@
shipName: String!
factionId: String!
clientMutationId: String
}
'''
}'''
2 changes: 1 addition & 1 deletion examples/starwars_relay/tests/test_objectidentification.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


def test_str_schema(snapshot):
snapshot.assert_match(str(schema))
snapshot.assert_match(str(schema).strip())


def test_correctly_fetches_id_name_rebels(snapshot):
Expand Down
11 changes: 7 additions & 4 deletions graphene/relay/tests/test_node.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
from graphql_relay import to_global_id
from textwrap import dedent

from graphene.tests.utils import dedent
from graphql_relay import to_global_id

from ...types import ObjectType, Schema, String
from ..node import Node, is_node
Expand Down Expand Up @@ -171,8 +171,10 @@ def test_node_field_only_lazy_type_wrong():


def test_str_schema():
assert str(schema) == dedent(
'''
assert (
str(schema).strip()
== dedent(
'''
schema {
query: RootQuery
}
Expand Down Expand Up @@ -213,4 +215,5 @@ def test_str_schema():
): MyNode
}
'''
).strip()
)
11 changes: 7 additions & 4 deletions graphene/relay/tests/test_node_custom.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from graphql import graphql_sync
from textwrap import dedent

from graphene.tests.utils import dedent
from graphql import graphql_sync

from ...types import Interface, ObjectType, Schema
from ...types.scalars import Int, String
Expand Down Expand Up @@ -54,8 +54,10 @@ class RootQuery(ObjectType):


def test_str_schema_correct():
assert str(schema) == dedent(
'''
assert (
str(schema).strip()
== dedent(
'''
schema {
query: RootQuery
}
Expand Down Expand Up @@ -93,6 +95,7 @@ def test_str_schema_correct():
): Node
}
'''
).strip()
)


Expand Down
3 changes: 1 addition & 2 deletions graphene/test/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from promise import Promise, is_thenable
from graphql.error import format_error as format_graphql_error
from graphql.error import GraphQLError

from graphene.types.schema import Schema


def default_format_error(error):
if isinstance(error, GraphQLError):
return format_graphql_error(error)
return error.formatted
return {"message": str(error)}


Expand Down
9 changes: 0 additions & 9 deletions graphene/tests/utils.py

This file was deleted.

3 changes: 1 addition & 2 deletions graphene/types/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
GraphQLObjectType,
GraphQLScalarType,
GraphQLUnionType,
Undefined,
)


Expand Down Expand Up @@ -50,7 +49,7 @@ def serialize(self, value):
try:
value = enum[value]
except KeyError:
return Undefined
pass
return super(GrapheneEnumType, self).serialize(value)


Expand Down
2 changes: 1 addition & 1 deletion graphene/types/scalars.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class String(Scalar):
@staticmethod
def coerce_string(value):
if isinstance(value, bool):
return u"true" if value else u"false"
return "true" if value else "false"
return str(value)

serialize = coerce_string
Expand Down
14 changes: 3 additions & 11 deletions graphene/types/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,19 +376,11 @@ def get_function_for_type(self, graphene_type, func_name, name, default_value):
def resolve_type(self, resolve_type_func, type_name, root, info, _type):
type_ = resolve_type_func(root, info)

if not type_:
return_type = self[type_name]
return default_type_resolver(root, info, return_type)

if inspect.isclass(type_) and issubclass(type_, ObjectType):
graphql_type = self.get(type_._meta.name)
assert graphql_type, f"Can't find type {type_._meta.name} in schema"
assert (
graphql_type.graphene_type == type_
), f"The type {type_} does not match with the associated graphene type {graphql_type.graphene_type}."
return graphql_type
return type_._meta.name

return type_
return_type = self[type_name]
return default_type_resolver(root, info, return_type)


class Schema:
Expand Down
43 changes: 22 additions & 21 deletions graphene/types/tests/test_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,19 +251,22 @@ def resolve_color(_, info):

schema = Schema(query=Query)

assert str(schema) == dedent(
'''\
type Query {
color: Color!
}
assert (
str(schema).strip()
== dedent(
'''
type Query {
color: Color!
}

"""Primary colors"""
enum Color {
RED
YELLOW
BLUE
}
'''
"""Primary colors"""
enum Color {
RED
YELLOW
BLUE
}
'''
).strip()
)


Expand Down Expand Up @@ -345,10 +348,7 @@ def resolve_color(_, info):

results = schema.execute("query { color }")
assert results.errors
assert (
results.errors[0].message
== "Expected a value of type 'Color' but received: 'BLACK'"
)
assert results.errors[0].message == "Enum 'Color' cannot represent value: 'BLACK'"


def test_field_enum_argument():
Expand Down Expand Up @@ -460,12 +460,13 @@ class Query(ObjectType):

schema = Schema(query=Query, mutation=MyMutation)
result = schema.execute(
""" mutation MyMutation {
createPaint(colorInput: { color: RED }) {
color
"""
mutation MyMutation {
createPaint(colorInput: { color: RED }) {
color
}
}
}
"""
"""
)
assert not result.errors
assert result.data == {"createPaint": {"color": "RED"}}
Expand Down
20 changes: 10 additions & 10 deletions graphene/types/tests/test_scalar.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ class JSONScalar(Scalar):


def test_ints():
assert Int.parse_value(2 ** 31 - 1) is not None
assert Int.parse_value(2**31 - 1) is not None
assert Int.parse_value("2.0") is not None
assert Int.parse_value(2 ** 31) is None
assert Int.parse_value(2**31) is None

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

assert Int.parse_value(-(2 ** 31)) is not None
assert Int.parse_value(-(2 ** 31) - 1) is None
assert Int.parse_value(-(2**31)) is not None
assert Int.parse_value(-(2**31) - 1) is None

assert BigInt.parse_value(2 ** 31) is not None
assert BigInt.parse_value(2**31) is not None
assert BigInt.parse_value("2.0") is not None
assert BigInt.parse_value(-(2 ** 31) - 1) is not None
assert BigInt.parse_value(-(2**31) - 1) is not None

assert BigInt.parse_literal(IntValueNode(value=str(2 ** 31 - 1))) == 2 ** 31 - 1
assert BigInt.parse_literal(IntValueNode(value=str(2 ** 31))) == 2 ** 31
assert BigInt.parse_literal(IntValueNode(value=str(2**31 - 1))) == 2**31 - 1
assert BigInt.parse_literal(IntValueNode(value=str(2**31))) == 2**31
2 changes: 1 addition & 1 deletion graphene/types/tests/test_scalars_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_serializes_output_string():
assert String.serialize(-1.1) == "-1.1"
assert String.serialize(True) == "true"
assert String.serialize(False) == "false"
assert String.serialize(u"\U0001F601") == u"\U0001F601"
assert String.serialize("\U0001F601") == "\U0001F601"


def test_serializes_output_boolean():
Expand Down
12 changes: 8 additions & 4 deletions graphene/types/tests/test_schema.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from graphql.type import GraphQLObjectType, GraphQLSchema
from textwrap import dedent

from pytest import raises

from graphene.tests.utils import dedent
from graphql.type import GraphQLObjectType, GraphQLSchema

from ..field import Field
from ..objecttype import ObjectType
Expand Down Expand Up @@ -43,8 +44,10 @@ def test_schema_get_type_error():

def test_schema_str():
schema = Schema(Query)
assert str(schema) == dedent(
"""
assert (
str(schema).strip()
== dedent(
"""
type Query {
inner: MyOtherType
}
Expand All @@ -53,6 +56,7 @@ def test_schema_str():
field: String
}
"""
).strip()
)


Expand Down
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ def run_tests(self):
"snapshottest>=0.6,<1",
"coveralls>=3.3,<4",
"promise>=2.3,<3",
"mock>=4.0,<5",
"pytz==2021.3",
"mock>=4,<5",
"pytz==2022.1",
"iso8601>=1,<2",
]

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

setup(
name="graphene",
Expand All @@ -84,8 +84,8 @@ def run_tests(self):
keywords="api graphql protocol rest relay graphene",
packages=find_packages(exclude=["examples*"]),
install_requires=[
"graphql-core~=3.1.2",
"graphql-relay>=3.0,<4",
"graphql-core>=3.1,<3.3",
"graphql-relay>=3.1,<3.3",
"aniso8601>=8,<10",
],
tests_require=tests_require,
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ commands =
[testenv:mypy]
basepython = python3.9
deps =
mypy>=0.931,<1
mypy>=0.950,<1
commands =
mypy graphene

Expand Down