mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-07-11 08:42:32 +03:00
Use client_mutation_id
for update
When using relay, it overrides the id of the model and provides a global id. This id is often what is available when making queries. However, it is unusable to update the model object. This seeks to make the `client_mutation_id` usable for updating the SerializerMutation
This commit is contained in:
parent
e7f7d8da07
commit
f5b5d36f72
|
@ -9,6 +9,8 @@ from graphene.types import Field, InputField
|
||||||
from graphene.types.mutation import MutationOptions
|
from graphene.types.mutation import MutationOptions
|
||||||
from graphene.types.objecttype import yank_fields_from_attrs
|
from graphene.types.objecttype import yank_fields_from_attrs
|
||||||
|
|
||||||
|
from graphql_relay import from_global_id
|
||||||
|
|
||||||
from ..types import ErrorType
|
from ..types import ErrorType
|
||||||
from .serializer_converter import convert_serializer_field
|
from .serializer_converter import convert_serializer_field
|
||||||
|
|
||||||
|
@ -125,6 +127,13 @@ class SerializerMutation(ClientIDMutation):
|
||||||
|
|
||||||
if model_class:
|
if model_class:
|
||||||
if "update" in cls._meta.model_operations and lookup_field in input:
|
if "update" in cls._meta.model_operations and lookup_field in input:
|
||||||
|
if 'client_mutation_id' in input:
|
||||||
|
global_id = input.pop("client_mutation_id", None)
|
||||||
|
node_type, global_pk = from_global_id(global_id)
|
||||||
|
instance = get_object_or_404(
|
||||||
|
model_class, **{lookup_field: global_pk}
|
||||||
|
)
|
||||||
|
else:
|
||||||
instance = get_object_or_404(
|
instance = get_object_or_404(
|
||||||
model_class, **{lookup_field: input[lookup_field]}
|
model_class, **{lookup_field: input[lookup_field]}
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user