mirror of
https://github.com/graphql-python/graphene.git
synced 2025-07-22 13:59:51 +03:00
mypy and black fix
This commit is contained in:
parent
31321e1e41
commit
187e3ba805
|
@ -1,7 +1,12 @@
|
|||
from .node import Node, is_node, GlobalID
|
||||
from .mutation import ClientIDMutation
|
||||
from .connection import Connection, ConnectionField, PageInfo
|
||||
from .id_type import BaseGlobalIDType, DefaultGlobalIDType, SimpleGlobalIDType, UUIDGlobalIDType
|
||||
from .id_type import (
|
||||
BaseGlobalIDType,
|
||||
DefaultGlobalIDType,
|
||||
SimpleGlobalIDType,
|
||||
UUIDGlobalIDType,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"Node",
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
from graphql_relay import from_global_id, to_global_id
|
||||
|
||||
from ..types import ID, UUID
|
||||
from ..types.base import BaseType
|
||||
|
||||
from typing import Type
|
||||
|
||||
|
||||
class BaseGlobalIDType:
|
||||
|
@ -8,7 +11,7 @@ class BaseGlobalIDType:
|
|||
Base class that define the required attributes/method for a type.
|
||||
"""
|
||||
|
||||
graphene_type = None
|
||||
graphene_type: Type[BaseType] = ID
|
||||
|
||||
@classmethod
|
||||
def resolve_global_id(cls, info, global_id):
|
||||
|
|
|
@ -26,8 +26,18 @@ def is_node(objecttype):
|
|||
|
||||
|
||||
class GlobalID(Field):
|
||||
def __init__(self, node=None, parent_type=None, required=True, global_id_type=DefaultGlobalIDType, *args, **kwargs):
|
||||
super(GlobalID, self).__init__(global_id_type.graphene_type, required=required, *args, **kwargs)
|
||||
def __init__(
|
||||
self,
|
||||
node=None,
|
||||
parent_type=None,
|
||||
required=True,
|
||||
global_id_type=DefaultGlobalIDType,
|
||||
*args,
|
||||
**kwargs
|
||||
):
|
||||
super(GlobalID, self).__init__(
|
||||
global_id_type.graphene_type, required=required, *args, **kwargs
|
||||
)
|
||||
self.node = node or Node
|
||||
self.parent_type_name = parent_type._meta.name if parent_type else None
|
||||
|
||||
|
@ -70,12 +80,15 @@ class AbstractNode(Interface):
|
|||
|
||||
@classmethod
|
||||
def __init_subclass_with_meta__(cls, global_id_type=DefaultGlobalIDType, **options):
|
||||
assert issubclass(global_id_type, BaseGlobalIDType), \
|
||||
"Custom ID type need to be implemented as a subclass of BaseGlobalIDType."
|
||||
assert issubclass(
|
||||
global_id_type, BaseGlobalIDType
|
||||
), "Custom ID type need to be implemented as a subclass of BaseGlobalIDType."
|
||||
_meta = InterfaceOptions(cls)
|
||||
_meta.global_id_type = global_id_type
|
||||
_meta.fields = OrderedDict(
|
||||
id=GlobalID(cls, global_id_type=global_id_type, description="The ID of the object.")
|
||||
id=GlobalID(
|
||||
cls, global_id_type=global_id_type, description="The ID of the object."
|
||||
)
|
||||
)
|
||||
super(AbstractNode, cls).__init_subclass_with_meta__(_meta=_meta, **options)
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ from uuid import uuid4
|
|||
|
||||
from graphql import graphql
|
||||
|
||||
from ..connection import Connection, ConnectionField
|
||||
from ..id_type import BaseGlobalIDType, SimpleGlobalIDType, UUIDGlobalIDType
|
||||
from ..node import Node
|
||||
from ...types import Int, ObjectType, Schema, String
|
||||
|
@ -60,7 +59,9 @@ class TestUUIDGlobalID:
|
|||
}
|
||||
}"""
|
||||
# UUID need to be converted to string for serialization
|
||||
result = graphql(self.schema, query, variable_values={"id": str(self.user_list[0]["id"])})
|
||||
result = graphql(
|
||||
self.schema, query, variable_values={"id": str(self.user_list[0]["id"])}
|
||||
)
|
||||
assert not result.errors
|
||||
assert result.data["user"]["id"] == str(self.user_list[0]["id"])
|
||||
assert result.data["user"]["name"] == self.user_list[0]["name"]
|
||||
|
|
|
@ -399,7 +399,7 @@ def test_big_list_of_containers_multiple_fields_query_benchmark(benchmark):
|
|||
|
||||
|
||||
def test_big_list_of_containers_multiple_fields_custom_resolvers_query_benchmark(
|
||||
benchmark
|
||||
benchmark,
|
||||
):
|
||||
class Container(ObjectType):
|
||||
x = Int()
|
||||
|
|
Loading…
Reference in New Issue
Block a user