mypy and black fix

This commit is contained in:
Thomas Leonard 2020-10-20 12:07:22 +02:00
parent 31321e1e41
commit 187e3ba805
5 changed files with 32 additions and 10 deletions

View File

@ -1,7 +1,12 @@
from .node import Node, is_node, GlobalID from .node import Node, is_node, GlobalID
from .mutation import ClientIDMutation from .mutation import ClientIDMutation
from .connection import Connection, ConnectionField, PageInfo from .connection import Connection, ConnectionField, PageInfo
from .id_type import BaseGlobalIDType, DefaultGlobalIDType, SimpleGlobalIDType, UUIDGlobalIDType from .id_type import (
BaseGlobalIDType,
DefaultGlobalIDType,
SimpleGlobalIDType,
UUIDGlobalIDType,
)
__all__ = [ __all__ = [
"Node", "Node",

View File

@ -1,6 +1,9 @@
from graphql_relay import from_global_id, to_global_id from graphql_relay import from_global_id, to_global_id
from ..types import ID, UUID from ..types import ID, UUID
from ..types.base import BaseType
from typing import Type
class BaseGlobalIDType: class BaseGlobalIDType:
@ -8,7 +11,7 @@ class BaseGlobalIDType:
Base class that define the required attributes/method for a type. Base class that define the required attributes/method for a type.
""" """
graphene_type = None graphene_type: Type[BaseType] = ID
@classmethod @classmethod
def resolve_global_id(cls, info, global_id): def resolve_global_id(cls, info, global_id):

View File

@ -26,8 +26,18 @@ def is_node(objecttype):
class GlobalID(Field): class GlobalID(Field):
def __init__(self, node=None, parent_type=None, required=True, global_id_type=DefaultGlobalIDType, *args, **kwargs): def __init__(
super(GlobalID, self).__init__(global_id_type.graphene_type, required=required, *args, **kwargs) 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.node = node or Node
self.parent_type_name = parent_type._meta.name if parent_type else None self.parent_type_name = parent_type._meta.name if parent_type else None
@ -70,12 +80,15 @@ class AbstractNode(Interface):
@classmethod @classmethod
def __init_subclass_with_meta__(cls, global_id_type=DefaultGlobalIDType, **options): def __init_subclass_with_meta__(cls, global_id_type=DefaultGlobalIDType, **options):
assert issubclass(global_id_type, BaseGlobalIDType), \ assert issubclass(
"Custom ID type need to be implemented as a subclass of BaseGlobalIDType." global_id_type, BaseGlobalIDType
), "Custom ID type need to be implemented as a subclass of BaseGlobalIDType."
_meta = InterfaceOptions(cls) _meta = InterfaceOptions(cls)
_meta.global_id_type = global_id_type _meta.global_id_type = global_id_type
_meta.fields = OrderedDict( _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) super(AbstractNode, cls).__init_subclass_with_meta__(_meta=_meta, **options)

View File

@ -3,7 +3,6 @@ from uuid import uuid4
from graphql import graphql from graphql import graphql
from ..connection import Connection, ConnectionField
from ..id_type import BaseGlobalIDType, SimpleGlobalIDType, UUIDGlobalIDType from ..id_type import BaseGlobalIDType, SimpleGlobalIDType, UUIDGlobalIDType
from ..node import Node from ..node import Node
from ...types import Int, ObjectType, Schema, String from ...types import Int, ObjectType, Schema, String
@ -60,7 +59,9 @@ class TestUUIDGlobalID:
} }
}""" }"""
# UUID need to be converted to string for serialization # 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 not result.errors
assert result.data["user"]["id"] == str(self.user_list[0]["id"]) assert result.data["user"]["id"] == str(self.user_list[0]["id"])
assert result.data["user"]["name"] == self.user_list[0]["name"] assert result.data["user"]["name"] == self.user_list[0]["name"]

View File

@ -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( def test_big_list_of_containers_multiple_fields_custom_resolvers_query_benchmark(
benchmark benchmark,
): ):
class Container(ObjectType): class Container(ObjectType):
x = Int() x = Int()