Skip to content

Commit

Permalink
Merge pull request #2 from LyridInc/develop
Browse files Browse the repository at this point in the history
Added uuid support.
  • Loading branch information
ash-lyrid authored Sep 28, 2023
2 parents 6cb0045 + 7e0bcbf commit 2824751
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
17 changes: 9 additions & 8 deletions graphene_django_cud/mutations/core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import enum
import uuid
from typing import Iterable, Union

from django.db import models
Expand Down Expand Up @@ -328,8 +329,8 @@ def create_obj(
new_value = cls.resolve_id(value)
# The order here is important
elif isinstance(field, models.OneToOneField):
# If the value is an integer or a string, we assume it is an ID
if isinstance(value, str) or isinstance(value, int):
# If the value is an integer or a string or a uuid, we assume it is an ID
if isinstance(value, str) or isinstance(value, int) or isinstance(value, uuid.UUID):
name = getattr(field, "db_column", None) or name + "_id"
new_value = cls.resolve_id(value)
else:
Expand Down Expand Up @@ -395,8 +396,8 @@ def create_obj(

# Value was not transformed
if new_value == value:
# If the value is an integer or a string, we assume it is an ID
if isinstance(value, str) or isinstance(value, int):
# If the value is an integer or a string or a uuid, we assume it is an ID
if isinstance(value, str) or isinstance(value, int) or isinstance(value, uuid.UUID):
name = getattr(field, "db_column", None) or name + "_id"
new_value = cls.resolve_id(value)
else:
Expand Down Expand Up @@ -576,8 +577,8 @@ def update_obj(
if isinstance(field, models.AutoField):
new_value = cls.resolve_id(value)
elif isinstance(field, models.OneToOneField):
# If the value is an integer or a string, we assume it is an ID
if isinstance(value, str) or isinstance(value, int):
# If the value is an integer or a string or a uuid, we assume it is an ID
if isinstance(value, str) or isinstance(value, int) or isinstance(value, uuid.UUID):
name = getattr(field, "db_column", None) or name + "_id"
new_value = cls.resolve_id(value)
else:
Expand All @@ -586,8 +587,8 @@ def update_obj(
value[field.remote_field.name] = obj.pk
new_value = cls.create_or_update_one_to_one_relation(obj, field, value, extra_data, info)
elif isinstance(field, models.OneToOneRel):
# If the value is an integer or a string, we assume it is an ID
if isinstance(value, str) or isinstance(value, int):
# If the value is an integer or a string or a uuid, we assume it is an ID
if isinstance(value, str) or isinstance(value, int) or isinstance(value, uuid.UUID):
name = getattr(field, "db_column", None) or name + "_id"
new_value = cls.resolve_id(value)
else:
Expand Down
6 changes: 3 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2824751

Please sign in to comment.