Added optional parent type to allow usage of GlobalID in mutations.

This commit is contained in:
markus 2016-11-10 10:54:03 +00:00
parent 5f7af3e43f
commit 8fa6d61271

View File

@ -35,17 +35,19 @@ def get_default_connection(cls):
class GlobalID(Field):
def __init__(self, node=None, required=True, *args, **kwargs):
def __init__(self, node=None, parent_type=None, required=True, *args, **kwargs):
super(GlobalID, self).__init__(ID, required=required, *args, **kwargs)
self.node = node or Node
self.parent_type_name = parent_type._meta.name if parent_type else None
@staticmethod
def id_resolver(parent_resolver, node, root, args, context, info):
id = parent_resolver(root, args, context, info)
return node.to_global_id(info.parent_type.name, id) # root._meta.name
def id_resolver(parent_resolver, node, root, args, context, info, parent_type_name=None):
type_id = parent_resolver(root, args, context, info)
parent_type_name = parent_type_name or info.parent_type.name
return node.to_global_id(parent_type_name, type_id) # root._meta.name
def get_resolver(self, parent_resolver):
return partial(self.id_resolver, parent_resolver, self.node)
return partial(self.id_resolver, parent_resolver, self.node, parent_type_name=self._parent_type_name)
class NodeMeta(InterfaceMeta):