mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-26 03:23:55 +03:00
Added optional parent type to allow usage of GlobalID in mutations.
This commit is contained in:
parent
5f7af3e43f
commit
8fa6d61271
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue
Block a user