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
|
||||
from collections import Iterable, OrderedDict
|
||||
from collections import Iterable
|
||||
from functools import partial
|
||||
|
||||
from graphql_relay import connection_from_list
|
||||
|
@ -86,26 +86,18 @@ class Connection(ObjectType):
|
|||
|
||||
options["name"] = name
|
||||
_meta.node = node
|
||||
_meta.fields = OrderedDict(
|
||||
[
|
||||
(
|
||||
"page_info",
|
||||
Field(
|
||||
PageInfo,
|
||||
name="pageInfo",
|
||||
required=True,
|
||||
description="Pagination data for this connection.",
|
||||
),
|
||||
),
|
||||
(
|
||||
"edges",
|
||||
Field(
|
||||
NonNull(List(edge)),
|
||||
description="Contains the nodes in this connection.",
|
||||
),
|
||||
),
|
||||
]
|
||||
)
|
||||
_meta.fields = {
|
||||
"page_info": Field(
|
||||
PageInfo,
|
||||
name="pageInfo",
|
||||
required=True,
|
||||
description="Pagination data for this connection.",
|
||||
),
|
||||
"edges": Field(
|
||||
NonNull(List(edge)),
|
||||
description="Contains the nodes in this connection.",
|
||||
),
|
||||
}
|
||||
return super(Connection, cls).__init_subclass_with_meta__(
|
||||
_meta=_meta, **options
|
||||
)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import re
|
||||
from collections import OrderedDict
|
||||
|
||||
from ..types import Field, InputObjectType, String
|
||||
from ..types.mutation import Mutation
|
||||
|
@ -30,12 +29,12 @@ class ClientIDMutation(Mutation):
|
|||
cls.Input = type(
|
||||
"{}Input".format(base_name),
|
||||
bases,
|
||||
OrderedDict(
|
||||
dict(
|
||||
input_fields, client_mutation_id=String(name="clientMutationId")
|
||||
),
|
||||
)
|
||||
|
||||
arguments = OrderedDict(
|
||||
arguments = dict(
|
||||
input=cls.Input(required=True)
|
||||
# 'client_mutation_id': String(name='clientMutationId')
|
||||
)
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
from collections import OrderedDict
|
||||
from functools import partial
|
||||
from inspect import isclass
|
||||
|
||||
|
@ -72,9 +71,9 @@ class AbstractNode(Interface):
|
|||
@classmethod
|
||||
def __init_subclass_with_meta__(cls, **options):
|
||||
_meta = InterfaceOptions(cls)
|
||||
_meta.fields = OrderedDict(
|
||||
id=GlobalID(cls, description="The ID of the object")
|
||||
)
|
||||
_meta.fields = {
|
||||
'id': GlobalID(cls, description="The ID of the object")
|
||||
}
|
||||
super(AbstractNode, cls).__init_subclass_with_meta__(_meta=_meta, **options)
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
from collections import OrderedDict
|
||||
from itertools import chain
|
||||
|
||||
from .dynamic import Dynamic
|
||||
|
@ -50,7 +49,7 @@ def to_arguments(args, extra_args=None):
|
|||
else:
|
||||
extra_args = []
|
||||
iter_arguments = chain(args.items(), extra_args)
|
||||
arguments = OrderedDict()
|
||||
arguments = {}
|
||||
for default_name, arg in iter_arguments:
|
||||
if isinstance(arg, Dynamic):
|
||||
arg = arg.get_type()
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
from collections import OrderedDict
|
||||
from enum import Enum as PyEnum
|
||||
|
||||
from graphene.utils.subclass_with_meta import SubclassWithMeta_Meta
|
||||
|
@ -23,13 +22,13 @@ class EnumOptions(BaseOptions):
|
|||
|
||||
class EnumMeta(SubclassWithMeta_Meta):
|
||||
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
|
||||
# with the enum values.
|
||||
enum_members.pop("Meta", None)
|
||||
enum = PyEnum(cls.__name__, enum_members)
|
||||
return SubclassWithMeta_Meta.__new__(
|
||||
cls, name, bases, OrderedDict(classdict, __enum__=enum), **options
|
||||
cls, name, bases, dict(classdict, __enum__=enum), **options
|
||||
)
|
||||
|
||||
def get(cls, value):
|
||||
|
@ -39,7 +38,7 @@ class EnumMeta(SubclassWithMeta_Meta):
|
|||
return cls._meta.enum[value]
|
||||
|
||||
def __prepare__(name, bases, **kwargs): # noqa: N805
|
||||
return OrderedDict()
|
||||
return {}
|
||||
|
||||
def __call__(cls, *args, **kwargs): # noqa: N805
|
||||
if cls is Enum:
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
from collections import OrderedDict
|
||||
|
||||
from .base import BaseOptions, BaseType
|
||||
from .inputfield import InputField
|
||||
from .unmountedtype import UnmountedType
|
||||
|
@ -44,7 +42,7 @@ class InputObjectType(UnmountedType, BaseType):
|
|||
if not _meta:
|
||||
_meta = InputObjectTypeOptions(cls)
|
||||
|
||||
fields = OrderedDict()
|
||||
fields = {}
|
||||
for base in reversed(cls.__mro__):
|
||||
fields.update(yank_fields_from_attrs(base.__dict__, _as=InputField))
|
||||
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
from collections import OrderedDict
|
||||
|
||||
from .base import BaseOptions, BaseType
|
||||
from .field import Field
|
||||
from .utils import yank_fields_from_attrs
|
||||
|
@ -29,7 +27,7 @@ class Interface(BaseType):
|
|||
if not _meta:
|
||||
_meta = InterfaceOptions(cls)
|
||||
|
||||
fields = OrderedDict()
|
||||
fields = {}
|
||||
for base in reversed(cls.__mro__):
|
||||
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.get_unbound_function import get_unbound_function
|
||||
from ..utils.props import props
|
||||
|
@ -36,7 +34,7 @@ class Mutation(ObjectType):
|
|||
fields = {}
|
||||
if not output:
|
||||
# If output is defined, we don't need to get the fields
|
||||
fields = OrderedDict()
|
||||
fields = {}
|
||||
for base in reversed(cls.__mro__):
|
||||
fields.update(yank_fields_from_attrs(base.__dict__, _as=Field))
|
||||
output = cls
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
from collections import OrderedDict
|
||||
|
||||
from .base import BaseOptions, BaseType
|
||||
from .field import Field
|
||||
from .interface import Interface
|
||||
|
@ -36,7 +34,7 @@ class ObjectType(BaseType):
|
|||
if not _meta:
|
||||
_meta = ObjectTypeOptions(cls)
|
||||
|
||||
fields = OrderedDict()
|
||||
fields = {}
|
||||
|
||||
for interface in interfaces:
|
||||
assert issubclass(interface, Interface), (
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import inspect
|
||||
from collections import OrderedDict
|
||||
from functools import partial
|
||||
|
||||
from ..utils.module_loading import import_string
|
||||
|
@ -33,7 +32,7 @@ def yank_fields_from_attrs(attrs, _as=None, sort=True):
|
|||
|
||||
if sort:
|
||||
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):
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from collections import Mapping, OrderedDict
|
||||
from collections import Mapping
|
||||
|
||||
|
||||
def deflate(node, index=None, path=None):
|
||||
|
@ -16,10 +16,9 @@ def deflate(node, index=None, path=None):
|
|||
else:
|
||||
index[cache_key] = True
|
||||
|
||||
field_names = node.keys()
|
||||
result = OrderedDict()
|
||||
result = {}
|
||||
|
||||
for field_name in field_names:
|
||||
for field_name in node:
|
||||
value = node[field_name]
|
||||
|
||||
new_path = path + [field_name]
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import pytest
|
||||
from collections import OrderedDict
|
||||
|
||||
from ..crunch import crunch
|
||||
|
||||
|
@ -28,28 +27,26 @@ from ..crunch import crunch
|
|||
["single-item object", {"a": None}, [None, {"a": 0}]],
|
||||
[
|
||||
"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}],
|
||||
],
|
||||
[
|
||||
"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}],
|
||||
],
|
||||
[
|
||||
"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]],
|
||||
],
|
||||
[
|
||||
"complex object",
|
||||
OrderedDict(
|
||||
[
|
||||
("a", True),
|
||||
("b", [1, 2, 3]),
|
||||
("c", OrderedDict([("a", True), ("b", [1, 2, 3])])),
|
||||
]
|
||||
),
|
||||
{
|
||||
"a": True,
|
||||
"b": [1, 2, 3],
|
||||
"c": {"a": True, "b": [1, 2, 3]},
|
||||
},
|
||||
[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