diff --git a/graphene/types/tests/test_uuid.py b/graphene/types/tests/test_uuid.py index d34f1664..c8f3947e 100644 --- a/graphene/types/tests/test_uuid.py +++ b/graphene/types/tests/test_uuid.py @@ -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 must be a string" + ) + + def test_uuidstring_optional_uuid_input(): """ Test that we can provide a null value to an optional input diff --git a/graphene/types/uuid.py b/graphene/types/uuid.py index 773e31c7..ba9e2c28 100644 --- a/graphene/types/uuid.py +++ b/graphene/types/uuid.py @@ -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 @@ -28,4 +29,6 @@ def parse_literal(node, _variables=None): @staticmethod def parse_value(value): + if not isinstance(value, str): + raise GraphQLError("UUID must be a string") return _UUID(value)