From e5a1d295d1032f248d5693f7f7517835dbbaee90 Mon Sep 17 00:00:00 2001 From: Jonathan Kim Date: Thu, 21 Jun 2018 17:25:30 +0100 Subject: [PATCH 1/2] Rename `resolve_type` method on Interface and Unions to `_resolve_type` --- graphene/types/interface.py | 2 +- graphene/types/typemap.py | 8 ++++---- graphene/types/union.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/graphene/types/interface.py b/graphene/types/interface.py index dbc3b4760..f8227cdc1 100644 --- a/graphene/types/interface.py +++ b/graphene/types/interface.py @@ -42,7 +42,7 @@ def __init_subclass_with_meta__(cls, _meta=None, **options): super(Interface, cls).__init_subclass_with_meta__(_meta=_meta, **options) @classmethod - def resolve_type(cls, instance, info): + def _resolve_type(cls, instance, info): from .objecttype import ObjectType if isinstance(instance, ObjectType): return type(instance) diff --git a/graphene/types/typemap.py b/graphene/types/typemap.py index b2bc4a0e9..2b8856b0d 100644 --- a/graphene/types/typemap.py +++ b/graphene/types/typemap.py @@ -194,8 +194,8 @@ def construct_interface(self, map, type): return _type _resolve_type = None - if type.resolve_type: - _resolve_type = partial(resolve_type, type.resolve_type, map, + if type._resolve_type: + _resolve_type = partial(resolve_type, type._resolve_type, map, type._meta.name) return GrapheneInterfaceType( graphene_type=type, @@ -216,8 +216,8 @@ def construct_inputobjecttype(self, map, type): def construct_union(self, map, type): _resolve_type = None - if type.resolve_type: - _resolve_type = partial(resolve_type, type.resolve_type, map, + if type._resolve_type: + _resolve_type = partial(resolve_type, type._resolve_type, map, type._meta.name) def types(): diff --git a/graphene/types/union.py b/graphene/types/union.py index 45e03b0c7..d1fab3576 100644 --- a/graphene/types/union.py +++ b/graphene/types/union.py @@ -40,7 +40,7 @@ def get_type(cls): return cls @classmethod - def resolve_type(cls, instance, info): + def _resolve_type(cls, instance, info): from .objecttype import ObjectType # NOQA if isinstance(instance, ObjectType): return type(instance) From 4c17b783128920a59c83fac0c358c9a23b90382a Mon Sep 17 00:00:00 2001 From: Jonathan Kim Date: Thu, 21 Jun 2018 17:26:06 +0100 Subject: [PATCH 2/2] Update docs --- docs/types/interfaces.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/types/interfaces.rst b/docs/types/interfaces.rst index 21cf21732..05623dbaa 100644 --- a/docs/types/interfaces.rst +++ b/docs/types/interfaces.rst @@ -154,7 +154,7 @@ Interfaces you might come across this error: This happens because Graphene doesn't have enough information to convert the data object into a Graphene type needed to resolve the ``Interface``. To solve -this you can define a ``resolve_type`` class method on the ``Interface`` which +this you can define a ``_resolve_type`` class method on the ``Interface`` which maps a data object to a Graphene type: .. code:: python @@ -164,7 +164,7 @@ maps a data object to a Graphene type: name = graphene.String(required=True) @classmethod - def resolve_type(cls, instance, info): + def _resolve_type(cls, instance, info): if instance.type == 'DROID': return Droid return Human