Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions graphene/types/tests/test_uuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ def test_uuidstring_query_variable():
assert result.data == {"uuid": uuid_value}


def test_uuidstring_invalid_argument():
uuid_value = {"not": "a string"}

result = schema.execute(
"""query Test($uuid: UUID){ uuid(input: $uuid) }""",
variables={"uuid": uuid_value},
)
assert result.errors
assert len(result.errors) == 1
assert (
result.errors[0].message
== "Variable '$uuid' got invalid value {'not': 'a string'}; UUID cannot represent value: {'not': 'a string'}"
)


def test_uuidstring_optional_uuid_input():
"""
Test that we can provide a null value to an optional input
Expand Down
8 changes: 7 additions & 1 deletion graphene/types/uuid.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from uuid import UUID as _UUID

from graphql.error import GraphQLError
from graphql.language.ast import StringValueNode
from graphql import Undefined

Expand Down Expand Up @@ -28,4 +29,9 @@

@staticmethod
def parse_value(value):
return _UUID(value)
if isinstance(value, _UUID):
return value

Check warning on line 33 in graphene/types/uuid.py

View check run for this annotation

Codecov / codecov/patch

graphene/types/uuid.py#L33

Added line #L33 was not covered by tests
try:
return _UUID(value)
except (ValueError, AttributeError):
raise GraphQLError(f"UUID cannot represent value: {repr(value)}")
Loading