mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-02 12:44:15 +03:00
Merge pull request #1421 from Cito/upgrade-dev-env
Make Graphene compatible with GraphQL-Core 3.2
This commit is contained in:
commit
9c3e4bb7da
|
@ -3,7 +3,7 @@ default_language_version:
|
||||||
|
|
||||||
repos:
|
repos:
|
||||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
rev: v4.1.0
|
rev: v4.2.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: check-merge-conflict
|
- id: check-merge-conflict
|
||||||
- id: check-json
|
- id: check-json
|
||||||
|
@ -17,11 +17,11 @@ repos:
|
||||||
- id: trailing-whitespace
|
- id: trailing-whitespace
|
||||||
exclude: README.md
|
exclude: README.md
|
||||||
- repo: https://github.com/asottile/pyupgrade
|
- repo: https://github.com/asottile/pyupgrade
|
||||||
rev: v2.31.0
|
rev: v2.32.1
|
||||||
hooks:
|
hooks:
|
||||||
- id: pyupgrade
|
- id: pyupgrade
|
||||||
- repo: https://github.com/ambv/black
|
- repo: https://github.com/ambv/black
|
||||||
rev: 21.12b0
|
rev: 22.3.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: black
|
- id: black
|
||||||
- repo: https://github.com/PyCQA/flake8
|
- repo: https://github.com/PyCQA/flake8
|
||||||
|
|
16
docs/conf.py
16
docs/conf.py
|
@ -64,18 +64,18 @@ source_suffix = ".rst"
|
||||||
master_doc = "index"
|
master_doc = "index"
|
||||||
|
|
||||||
# General information about the project.
|
# General information about the project.
|
||||||
project = u"Graphene"
|
project = "Graphene"
|
||||||
copyright = u"Graphene 2016"
|
copyright = "Graphene 2016"
|
||||||
author = u"Syrus Akbary"
|
author = "Syrus Akbary"
|
||||||
|
|
||||||
# The version info for the project you're documenting, acts as replacement for
|
# The version info for the project you're documenting, acts as replacement for
|
||||||
# |version| and |release|, also used in various other places throughout the
|
# |version| and |release|, also used in various other places throughout the
|
||||||
# built documents.
|
# built documents.
|
||||||
#
|
#
|
||||||
# The short X.Y version.
|
# The short X.Y version.
|
||||||
version = u"1.0"
|
version = "1.0"
|
||||||
# The full version, including alpha/beta/rc tags.
|
# 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
|
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||||
# for a list of supported languages.
|
# for a list of supported languages.
|
||||||
|
@ -278,7 +278,7 @@ latex_elements = {
|
||||||
# (source start file, target name, title,
|
# (source start file, target name, title,
|
||||||
# author, documentclass [howto, manual, or own class]).
|
# author, documentclass [howto, manual, or own class]).
|
||||||
latex_documents = [
|
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
|
# The name of an image file (relative to this directory) to place at the top of
|
||||||
|
@ -318,7 +318,7 @@ latex_documents = [
|
||||||
|
|
||||||
# One entry per manual page. List of tuples
|
# One entry per manual page. List of tuples
|
||||||
# (source start file, name, description, authors, manual section).
|
# (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.
|
# If true, show URL addresses after external links.
|
||||||
#
|
#
|
||||||
|
@ -334,7 +334,7 @@ texinfo_documents = [
|
||||||
(
|
(
|
||||||
master_doc,
|
master_doc,
|
||||||
"Graphene",
|
"Graphene",
|
||||||
u"Graphene Documentation",
|
"Graphene Documentation",
|
||||||
author,
|
author,
|
||||||
"Graphene",
|
"Graphene",
|
||||||
"One line description of project.",
|
"One line description of project.",
|
||||||
|
|
|
@ -115,5 +115,4 @@ input IntroduceShipInput {
|
||||||
shipName: String!
|
shipName: String!
|
||||||
factionId: String!
|
factionId: String!
|
||||||
clientMutationId: String
|
clientMutationId: String
|
||||||
}
|
}'''
|
||||||
'''
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ client = Client(schema)
|
||||||
|
|
||||||
|
|
||||||
def test_str_schema(snapshot):
|
def test_str_schema(snapshot):
|
||||||
snapshot.assert_match(str(schema))
|
snapshot.assert_match(str(schema).strip())
|
||||||
|
|
||||||
|
|
||||||
def test_correctly_fetches_id_name_rebels(snapshot):
|
def test_correctly_fetches_id_name_rebels(snapshot):
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import re
|
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 ...types import ObjectType, Schema, String
|
||||||
from ..node import Node, is_node
|
from ..node import Node, is_node
|
||||||
|
@ -171,7 +171,9 @@ def test_node_field_only_lazy_type_wrong():
|
||||||
|
|
||||||
|
|
||||||
def test_str_schema():
|
def test_str_schema():
|
||||||
assert str(schema) == dedent(
|
assert (
|
||||||
|
str(schema).strip()
|
||||||
|
== dedent(
|
||||||
'''
|
'''
|
||||||
schema {
|
schema {
|
||||||
query: RootQuery
|
query: RootQuery
|
||||||
|
@ -213,4 +215,5 @@ def test_str_schema():
|
||||||
): MyNode
|
): MyNode
|
||||||
}
|
}
|
||||||
'''
|
'''
|
||||||
|
).strip()
|
||||||
)
|
)
|
||||||
|
|
|
@ -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 import Interface, ObjectType, Schema
|
||||||
from ...types.scalars import Int, String
|
from ...types.scalars import Int, String
|
||||||
|
@ -54,7 +54,9 @@ graphql_schema = schema.graphql_schema
|
||||||
|
|
||||||
|
|
||||||
def test_str_schema_correct():
|
def test_str_schema_correct():
|
||||||
assert str(schema) == dedent(
|
assert (
|
||||||
|
str(schema).strip()
|
||||||
|
== dedent(
|
||||||
'''
|
'''
|
||||||
schema {
|
schema {
|
||||||
query: RootQuery
|
query: RootQuery
|
||||||
|
@ -93,6 +95,7 @@ def test_str_schema_correct():
|
||||||
): Node
|
): Node
|
||||||
}
|
}
|
||||||
'''
|
'''
|
||||||
|
).strip()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
from promise import Promise, is_thenable
|
from promise import Promise, is_thenable
|
||||||
from graphql.error import format_error as format_graphql_error
|
|
||||||
from graphql.error import GraphQLError
|
from graphql.error import GraphQLError
|
||||||
|
|
||||||
from graphene.types.schema import Schema
|
from graphene.types.schema import Schema
|
||||||
|
@ -7,7 +6,7 @@ from graphene.types.schema import Schema
|
||||||
|
|
||||||
def default_format_error(error):
|
def default_format_error(error):
|
||||||
if isinstance(error, GraphQLError):
|
if isinstance(error, GraphQLError):
|
||||||
return format_graphql_error(error)
|
return error.formatted
|
||||||
return {"message": str(error)}
|
return {"message": str(error)}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
from textwrap import dedent as _dedent
|
|
||||||
|
|
||||||
|
|
||||||
def dedent(text: str) -> str:
|
|
||||||
"""Fix indentation of given text by removing leading spaces and tabs.
|
|
||||||
Also removes leading newlines and trailing spaces and tabs, but keeps trailing
|
|
||||||
newlines.
|
|
||||||
"""
|
|
||||||
return _dedent(text.lstrip("\n").rstrip(" \t"))
|
|
|
@ -7,7 +7,6 @@ from graphql import (
|
||||||
GraphQLObjectType,
|
GraphQLObjectType,
|
||||||
GraphQLScalarType,
|
GraphQLScalarType,
|
||||||
GraphQLUnionType,
|
GraphQLUnionType,
|
||||||
Undefined,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,7 +49,7 @@ class GrapheneEnumType(GrapheneGraphQLType, GraphQLEnumType):
|
||||||
try:
|
try:
|
||||||
value = enum[value]
|
value = enum[value]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return Undefined
|
pass
|
||||||
return super(GrapheneEnumType, self).serialize(value)
|
return super(GrapheneEnumType, self).serialize(value)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -143,7 +143,7 @@ class String(Scalar):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def coerce_string(value):
|
def coerce_string(value):
|
||||||
if isinstance(value, bool):
|
if isinstance(value, bool):
|
||||||
return u"true" if value else u"false"
|
return "true" if value else "false"
|
||||||
return str(value)
|
return str(value)
|
||||||
|
|
||||||
serialize = coerce_string
|
serialize = coerce_string
|
||||||
|
|
|
@ -376,20 +376,12 @@ class TypeMap(dict):
|
||||||
def resolve_type(self, resolve_type_func, type_name, root, info, _type):
|
def resolve_type(self, resolve_type_func, type_name, root, info, _type):
|
||||||
type_ = resolve_type_func(root, info)
|
type_ = resolve_type_func(root, info)
|
||||||
|
|
||||||
if not type_:
|
if inspect.isclass(type_) and issubclass(type_, ObjectType):
|
||||||
|
return type_._meta.name
|
||||||
|
|
||||||
return_type = self[type_name]
|
return_type = self[type_name]
|
||||||
return default_type_resolver(root, info, return_type)
|
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_
|
|
||||||
|
|
||||||
|
|
||||||
class Schema:
|
class Schema:
|
||||||
"""Schema Definition.
|
"""Schema Definition.
|
||||||
|
|
|
@ -251,8 +251,10 @@ def test_enum_types():
|
||||||
|
|
||||||
schema = Schema(query=Query)
|
schema = Schema(query=Query)
|
||||||
|
|
||||||
assert str(schema) == dedent(
|
assert (
|
||||||
'''\
|
str(schema).strip()
|
||||||
|
== dedent(
|
||||||
|
'''
|
||||||
type Query {
|
type Query {
|
||||||
color: Color!
|
color: Color!
|
||||||
}
|
}
|
||||||
|
@ -264,6 +266,7 @@ def test_enum_types():
|
||||||
BLUE
|
BLUE
|
||||||
}
|
}
|
||||||
'''
|
'''
|
||||||
|
).strip()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -345,10 +348,7 @@ def test_enum_resolver_invalid():
|
||||||
|
|
||||||
results = schema.execute("query { color }")
|
results = schema.execute("query { color }")
|
||||||
assert results.errors
|
assert results.errors
|
||||||
assert (
|
assert results.errors[0].message == "Enum 'Color' cannot represent value: 'BLACK'"
|
||||||
results.errors[0].message
|
|
||||||
== "Expected a value of type 'Color' but received: 'BLACK'"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_field_enum_argument():
|
def test_field_enum_argument():
|
||||||
|
@ -460,7 +460,8 @@ def test_mutation_enum_input_type():
|
||||||
|
|
||||||
schema = Schema(query=Query, mutation=MyMutation)
|
schema = Schema(query=Query, mutation=MyMutation)
|
||||||
result = schema.execute(
|
result = schema.execute(
|
||||||
""" mutation MyMutation {
|
"""
|
||||||
|
mutation MyMutation {
|
||||||
createPaint(colorInput: { color: RED }) {
|
createPaint(colorInput: { color: RED }) {
|
||||||
color
|
color
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,19 +11,19 @@ def test_scalar():
|
||||||
|
|
||||||
|
|
||||||
def test_ints():
|
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.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 - 1))) == 2**31 - 1
|
||||||
assert Int.parse_literal(IntValueNode(value=str(2 ** 31))) is None
|
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)) is not None
|
||||||
assert Int.parse_value(-(2 ** 31) - 1) is 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.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 - 1))) == 2**31 - 1
|
||||||
assert BigInt.parse_literal(IntValueNode(value=str(2 ** 31))) == 2 ** 31
|
assert BigInt.parse_literal(IntValueNode(value=str(2**31))) == 2**31
|
||||||
|
|
|
@ -38,7 +38,7 @@ def test_serializes_output_string():
|
||||||
assert String.serialize(-1.1) == "-1.1"
|
assert String.serialize(-1.1) == "-1.1"
|
||||||
assert String.serialize(True) == "true"
|
assert String.serialize(True) == "true"
|
||||||
assert String.serialize(False) == "false"
|
assert String.serialize(False) == "false"
|
||||||
assert String.serialize(u"\U0001F601") == u"\U0001F601"
|
assert String.serialize("\U0001F601") == "\U0001F601"
|
||||||
|
|
||||||
|
|
||||||
def test_serializes_output_boolean():
|
def test_serializes_output_boolean():
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
from graphql.type import GraphQLObjectType, GraphQLSchema
|
from textwrap import dedent
|
||||||
|
|
||||||
from pytest import raises
|
from pytest import raises
|
||||||
|
|
||||||
from graphene.tests.utils import dedent
|
from graphql.type import GraphQLObjectType, GraphQLSchema
|
||||||
|
|
||||||
from ..field import Field
|
from ..field import Field
|
||||||
from ..objecttype import ObjectType
|
from ..objecttype import ObjectType
|
||||||
|
@ -43,7 +44,9 @@ def test_schema_get_type_error():
|
||||||
|
|
||||||
def test_schema_str():
|
def test_schema_str():
|
||||||
schema = Schema(Query)
|
schema = Schema(Query)
|
||||||
assert str(schema) == dedent(
|
assert (
|
||||||
|
str(schema).strip()
|
||||||
|
== dedent(
|
||||||
"""
|
"""
|
||||||
type Query {
|
type Query {
|
||||||
inner: MyOtherType
|
inner: MyOtherType
|
||||||
|
@ -53,6 +56,7 @@ def test_schema_str():
|
||||||
field: String
|
field: String
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
).strip()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
10
setup.py
10
setup.py
|
@ -53,12 +53,12 @@ tests_require = [
|
||||||
"snapshottest>=0.6,<1",
|
"snapshottest>=0.6,<1",
|
||||||
"coveralls>=3.3,<4",
|
"coveralls>=3.3,<4",
|
||||||
"promise>=2.3,<3",
|
"promise>=2.3,<3",
|
||||||
"mock>=4.0,<5",
|
"mock>=4,<5",
|
||||||
"pytz==2021.3",
|
"pytz==2022.1",
|
||||||
"iso8601>=1,<2",
|
"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(
|
setup(
|
||||||
name="graphene",
|
name="graphene",
|
||||||
|
@ -84,8 +84,8 @@ setup(
|
||||||
keywords="api graphql protocol rest relay graphene",
|
keywords="api graphql protocol rest relay graphene",
|
||||||
packages=find_packages(exclude=["examples*"]),
|
packages=find_packages(exclude=["examples*"]),
|
||||||
install_requires=[
|
install_requires=[
|
||||||
"graphql-core~=3.1.2",
|
"graphql-core>=3.1,<3.3",
|
||||||
"graphql-relay>=3.0,<4",
|
"graphql-relay>=3.1,<3.3",
|
||||||
"aniso8601>=8,<10",
|
"aniso8601>=8,<10",
|
||||||
],
|
],
|
||||||
tests_require=tests_require,
|
tests_require=tests_require,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user