mirror of
https://github.com/graphql-python/graphene.git
synced 2025-09-21 11:22:33 +03:00
We can assume that dicts are ordered in Py 3.6+
This commit is contained in:
parent
029dde32a2
commit
5752b48a0b
|
@ -1,5 +1,5 @@
|
||||||
import re
|
import re
|
||||||
from collections import Iterable, OrderedDict
|
from collections import Iterable
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from graphql_relay import connection_from_list
|
from graphql_relay import connection_from_list
|
||||||
|
@ -86,26 +86,18 @@ class Connection(ObjectType):
|
||||||
|
|
||||||
options["name"] = name
|
options["name"] = name
|
||||||
_meta.node = node
|
_meta.node = node
|
||||||
_meta.fields = OrderedDict(
|
_meta.fields = {
|
||||||
[
|
"page_info": Field(
|
||||||
(
|
|
||||||
"page_info",
|
|
||||||
Field(
|
|
||||||
PageInfo,
|
PageInfo,
|
||||||
name="pageInfo",
|
name="pageInfo",
|
||||||
required=True,
|
required=True,
|
||||||
description="Pagination data for this connection.",
|
description="Pagination data for this connection.",
|
||||||
),
|
),
|
||||||
),
|
"edges": Field(
|
||||||
(
|
|
||||||
"edges",
|
|
||||||
Field(
|
|
||||||
NonNull(List(edge)),
|
NonNull(List(edge)),
|
||||||
description="Contains the nodes in this connection.",
|
description="Contains the nodes in this connection.",
|
||||||
),
|
),
|
||||||
),
|
}
|
||||||
]
|
|
||||||
)
|
|
||||||
return super(Connection, cls).__init_subclass_with_meta__(
|
return super(Connection, cls).__init_subclass_with_meta__(
|
||||||
_meta=_meta, **options
|
_meta=_meta, **options
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import re
|
import re
|
||||||
from collections import OrderedDict
|
|
||||||
|
|
||||||
from ..types import Field, InputObjectType, String
|
from ..types import Field, InputObjectType, String
|
||||||
from ..types.mutation import Mutation
|
from ..types.mutation import Mutation
|
||||||
|
@ -30,12 +29,12 @@ class ClientIDMutation(Mutation):
|
||||||
cls.Input = type(
|
cls.Input = type(
|
||||||
"{}Input".format(base_name),
|
"{}Input".format(base_name),
|
||||||
bases,
|
bases,
|
||||||
OrderedDict(
|
dict(
|
||||||
input_fields, client_mutation_id=String(name="clientMutationId")
|
input_fields, client_mutation_id=String(name="clientMutationId")
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
arguments = OrderedDict(
|
arguments = dict(
|
||||||
input=cls.Input(required=True)
|
input=cls.Input(required=True)
|
||||||
# 'client_mutation_id': String(name='clientMutationId')
|
# 'client_mutation_id': String(name='clientMutationId')
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
from collections import OrderedDict
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from inspect import isclass
|
from inspect import isclass
|
||||||
|
|
||||||
|
@ -72,9 +71,9 @@ class AbstractNode(Interface):
|
||||||
@classmethod
|
@classmethod
|
||||||
def __init_subclass_with_meta__(cls, **options):
|
def __init_subclass_with_meta__(cls, **options):
|
||||||
_meta = InterfaceOptions(cls)
|
_meta = InterfaceOptions(cls)
|
||||||
_meta.fields = OrderedDict(
|
_meta.fields = {
|
||||||
id=GlobalID(cls, description="The ID of the object")
|
'id': GlobalID(cls, description="The ID of the object")
|
||||||
)
|
}
|
||||||
super(AbstractNode, cls).__init_subclass_with_meta__(_meta=_meta, **options)
|
super(AbstractNode, cls).__init_subclass_with_meta__(_meta=_meta, **options)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
from collections import OrderedDict
|
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
|
|
||||||
from .dynamic import Dynamic
|
from .dynamic import Dynamic
|
||||||
|
@ -50,7 +49,7 @@ def to_arguments(args, extra_args=None):
|
||||||
else:
|
else:
|
||||||
extra_args = []
|
extra_args = []
|
||||||
iter_arguments = chain(args.items(), extra_args)
|
iter_arguments = chain(args.items(), extra_args)
|
||||||
arguments = OrderedDict()
|
arguments = {}
|
||||||
for default_name, arg in iter_arguments:
|
for default_name, arg in iter_arguments:
|
||||||
if isinstance(arg, Dynamic):
|
if isinstance(arg, Dynamic):
|
||||||
arg = arg.get_type()
|
arg = arg.get_type()
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
from collections import OrderedDict
|
|
||||||
from enum import Enum as PyEnum
|
from enum import Enum as PyEnum
|
||||||
|
|
||||||
from graphene.utils.subclass_with_meta import SubclassWithMeta_Meta
|
from graphene.utils.subclass_with_meta import SubclassWithMeta_Meta
|
||||||
|
@ -23,13 +22,13 @@ class EnumOptions(BaseOptions):
|
||||||
|
|
||||||
class EnumMeta(SubclassWithMeta_Meta):
|
class EnumMeta(SubclassWithMeta_Meta):
|
||||||
def __new__(cls, name, bases, classdict, **options):
|
def __new__(cls, name, bases, classdict, **options):
|
||||||
enum_members = OrderedDict(classdict, __eq__=eq_enum)
|
enum_members = dict(classdict, __eq__=eq_enum)
|
||||||
# We remove the Meta attribute from the class to not collide
|
# We remove the Meta attribute from the class to not collide
|
||||||
# with the enum values.
|
# with the enum values.
|
||||||
enum_members.pop("Meta", None)
|
enum_members.pop("Meta", None)
|
||||||
enum = PyEnum(cls.__name__, enum_members)
|
enum = PyEnum(cls.__name__, enum_members)
|
||||||
return SubclassWithMeta_Meta.__new__(
|
return SubclassWithMeta_Meta.__new__(
|
||||||
cls, name, bases, OrderedDict(classdict, __enum__=enum), **options
|
cls, name, bases, dict(classdict, __enum__=enum), **options
|
||||||
)
|
)
|
||||||
|
|
||||||
def get(cls, value):
|
def get(cls, value):
|
||||||
|
@ -39,7 +38,7 @@ class EnumMeta(SubclassWithMeta_Meta):
|
||||||
return cls._meta.enum[value]
|
return cls._meta.enum[value]
|
||||||
|
|
||||||
def __prepare__(name, bases, **kwargs): # noqa: N805
|
def __prepare__(name, bases, **kwargs): # noqa: N805
|
||||||
return OrderedDict()
|
return {}
|
||||||
|
|
||||||
def __call__(cls, *args, **kwargs): # noqa: N805
|
def __call__(cls, *args, **kwargs): # noqa: N805
|
||||||
if cls is Enum:
|
if cls is Enum:
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
from collections import OrderedDict
|
|
||||||
|
|
||||||
from .base import BaseOptions, BaseType
|
from .base import BaseOptions, BaseType
|
||||||
from .inputfield import InputField
|
from .inputfield import InputField
|
||||||
from .unmountedtype import UnmountedType
|
from .unmountedtype import UnmountedType
|
||||||
|
@ -44,7 +42,7 @@ class InputObjectType(UnmountedType, BaseType):
|
||||||
if not _meta:
|
if not _meta:
|
||||||
_meta = InputObjectTypeOptions(cls)
|
_meta = InputObjectTypeOptions(cls)
|
||||||
|
|
||||||
fields = OrderedDict()
|
fields = {}
|
||||||
for base in reversed(cls.__mro__):
|
for base in reversed(cls.__mro__):
|
||||||
fields.update(yank_fields_from_attrs(base.__dict__, _as=InputField))
|
fields.update(yank_fields_from_attrs(base.__dict__, _as=InputField))
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
from collections import OrderedDict
|
|
||||||
|
|
||||||
from .base import BaseOptions, BaseType
|
from .base import BaseOptions, BaseType
|
||||||
from .field import Field
|
from .field import Field
|
||||||
from .utils import yank_fields_from_attrs
|
from .utils import yank_fields_from_attrs
|
||||||
|
@ -29,7 +27,7 @@ class Interface(BaseType):
|
||||||
if not _meta:
|
if not _meta:
|
||||||
_meta = InterfaceOptions(cls)
|
_meta = InterfaceOptions(cls)
|
||||||
|
|
||||||
fields = OrderedDict()
|
fields = {}
|
||||||
for base in reversed(cls.__mro__):
|
for base in reversed(cls.__mro__):
|
||||||
fields.update(yank_fields_from_attrs(base.__dict__, _as=Field))
|
fields.update(yank_fields_from_attrs(base.__dict__, _as=Field))
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
from collections import OrderedDict
|
|
||||||
|
|
||||||
from ..utils.deprecated import warn_deprecation
|
from ..utils.deprecated import warn_deprecation
|
||||||
from ..utils.get_unbound_function import get_unbound_function
|
from ..utils.get_unbound_function import get_unbound_function
|
||||||
from ..utils.props import props
|
from ..utils.props import props
|
||||||
|
@ -36,7 +34,7 @@ class Mutation(ObjectType):
|
||||||
fields = {}
|
fields = {}
|
||||||
if not output:
|
if not output:
|
||||||
# If output is defined, we don't need to get the fields
|
# If output is defined, we don't need to get the fields
|
||||||
fields = OrderedDict()
|
fields = {}
|
||||||
for base in reversed(cls.__mro__):
|
for base in reversed(cls.__mro__):
|
||||||
fields.update(yank_fields_from_attrs(base.__dict__, _as=Field))
|
fields.update(yank_fields_from_attrs(base.__dict__, _as=Field))
|
||||||
output = cls
|
output = cls
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
from collections import OrderedDict
|
|
||||||
|
|
||||||
from .base import BaseOptions, BaseType
|
from .base import BaseOptions, BaseType
|
||||||
from .field import Field
|
from .field import Field
|
||||||
from .interface import Interface
|
from .interface import Interface
|
||||||
|
@ -36,7 +34,7 @@ class ObjectType(BaseType):
|
||||||
if not _meta:
|
if not _meta:
|
||||||
_meta = ObjectTypeOptions(cls)
|
_meta = ObjectTypeOptions(cls)
|
||||||
|
|
||||||
fields = OrderedDict()
|
fields = {}
|
||||||
|
|
||||||
for interface in interfaces:
|
for interface in interfaces:
|
||||||
assert issubclass(interface, Interface), (
|
assert issubclass(interface, Interface), (
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import inspect
|
import inspect
|
||||||
from collections import OrderedDict
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from ..utils.module_loading import import_string
|
from ..utils.module_loading import import_string
|
||||||
|
@ -33,7 +32,7 @@ def yank_fields_from_attrs(attrs, _as=None, sort=True):
|
||||||
|
|
||||||
if sort:
|
if sort:
|
||||||
fields_with_names = sorted(fields_with_names, key=lambda f: f[1])
|
fields_with_names = sorted(fields_with_names, key=lambda f: f[1])
|
||||||
return OrderedDict(fields_with_names)
|
return dict(fields_with_names)
|
||||||
|
|
||||||
|
|
||||||
def get_type(_type):
|
def get_type(_type):
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from collections import Mapping, OrderedDict
|
from collections import Mapping
|
||||||
|
|
||||||
|
|
||||||
def deflate(node, index=None, path=None):
|
def deflate(node, index=None, path=None):
|
||||||
|
@ -16,10 +16,9 @@ def deflate(node, index=None, path=None):
|
||||||
else:
|
else:
|
||||||
index[cache_key] = True
|
index[cache_key] = True
|
||||||
|
|
||||||
field_names = node.keys()
|
result = {}
|
||||||
result = OrderedDict()
|
|
||||||
|
|
||||||
for field_name in field_names:
|
for field_name in node:
|
||||||
value = node[field_name]
|
value = node[field_name]
|
||||||
|
|
||||||
new_path = path + [field_name]
|
new_path = path + [field_name]
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import pytest
|
import pytest
|
||||||
from collections import OrderedDict
|
|
||||||
|
|
||||||
from ..crunch import crunch
|
from ..crunch import crunch
|
||||||
|
|
||||||
|
@ -28,28 +27,26 @@ from ..crunch import crunch
|
||||||
["single-item object", {"a": None}, [None, {"a": 0}]],
|
["single-item object", {"a": None}, [None, {"a": 0}]],
|
||||||
[
|
[
|
||||||
"multi-item all distinct object",
|
"multi-item all distinct object",
|
||||||
OrderedDict([("a", None), ("b", 0), ("c", True), ("d", "string")]),
|
{"a": None, "b": 0, "c": True, "d": "string"},
|
||||||
[None, 0, True, "string", {"a": 0, "b": 1, "c": 2, "d": 3}],
|
[None, 0, True, "string", {"a": 0, "b": 1, "c": 2, "d": 3}],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"multi-item repeated object",
|
"multi-item repeated object",
|
||||||
OrderedDict([("a", True), ("b", True), ("c", True), ("d", True)]),
|
{"a": True, "b": True, "c": True, "d": True},
|
||||||
[True, {"a": 0, "b": 0, "c": 0, "d": 0}],
|
[True, {"a": 0, "b": 0, "c": 0, "d": 0}],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"complex array",
|
"complex array",
|
||||||
[OrderedDict([("a", True), ("b", [1, 2, 3])]), [1, 2, 3]],
|
[{"a": True, "b": [1, 2, 3]}, [1, 2, 3]],
|
||||||
[True, 1, 2, 3, [1, 2, 3], {"a": 0, "b": 4}, [5, 4]],
|
[True, 1, 2, 3, [1, 2, 3], {"a": 0, "b": 4}, [5, 4]],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"complex object",
|
"complex object",
|
||||||
OrderedDict(
|
{
|
||||||
[
|
"a": True,
|
||||||
("a", True),
|
"b": [1, 2, 3],
|
||||||
("b", [1, 2, 3]),
|
"c": {"a": True, "b": [1, 2, 3]},
|
||||||
("c", OrderedDict([("a", True), ("b", [1, 2, 3])])),
|
},
|
||||||
]
|
|
||||||
),
|
|
||||||
[True, 1, 2, 3, [1, 2, 3], {"a": 0, "b": 4}, {"a": 0, "b": 4, "c": 5}],
|
[True, 1, 2, 3, [1, 2, 3], {"a": 0, "b": 4}, {"a": 0, "b": 4, "c": 5}],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in New Issue
Block a user