mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-25 11:03:58 +03:00
Make Graphene compatible with Core 3.2
This commit is contained in:
parent
e37ef00ca4
commit
9e7e08d48a
|
@ -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,8 +171,10 @@ 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,8 +54,10 @@ 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)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -376,19 +376,11 @@ 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_:
|
|
||||||
return_type = self[type_name]
|
|
||||||
return default_type_resolver(root, info, return_type)
|
|
||||||
|
|
||||||
if inspect.isclass(type_) and issubclass(type_, ObjectType):
|
if inspect.isclass(type_) and issubclass(type_, ObjectType):
|
||||||
graphql_type = self.get(type_._meta.name)
|
return 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_
|
return_type = self[type_name]
|
||||||
|
return default_type_resolver(root, info, return_type)
|
||||||
|
|
||||||
|
|
||||||
class Schema:
|
class Schema:
|
||||||
|
|
|
@ -251,19 +251,22 @@ def test_enum_types():
|
||||||
|
|
||||||
schema = Schema(query=Query)
|
schema = Schema(query=Query)
|
||||||
|
|
||||||
assert str(schema) == dedent(
|
assert (
|
||||||
'''\
|
str(schema).strip()
|
||||||
type Query {
|
== dedent(
|
||||||
color: Color!
|
'''
|
||||||
}
|
type Query {
|
||||||
|
color: Color!
|
||||||
|
}
|
||||||
|
|
||||||
"""Primary colors"""
|
"""Primary colors"""
|
||||||
enum Color {
|
enum Color {
|
||||||
RED
|
RED
|
||||||
YELLOW
|
YELLOW
|
||||||
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,12 +460,13 @@ 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 {
|
"""
|
||||||
createPaint(colorInput: { color: RED }) {
|
mutation MyMutation {
|
||||||
color
|
createPaint(colorInput: { color: RED }) {
|
||||||
|
color
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
"""
|
||||||
"""
|
|
||||||
)
|
)
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
assert result.data == {"createPaint": {"color": "RED"}}
|
assert result.data == {"createPaint": {"color": "RED"}}
|
||||||
|
|
|
@ -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,8 +44,10 @@ 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()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
4
setup.py
4
setup.py
|
@ -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