mirror of
https://github.com/graphql-python/graphene.git
synced 2025-04-07 19:04:14 +03:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
8290326308 | ||
|
4a274b8424 | ||
|
b3db1c0cb2 | ||
|
3ed7bf6362 |
|
@ -46,7 +46,7 @@ from .types import (
|
|||
from .utils.module_loading import lazy_import
|
||||
from .utils.resolve_only_args import resolve_only_args
|
||||
|
||||
VERSION = (3, 4, 1, "final", 0)
|
||||
VERSION = (3, 4, 3, "final", 0)
|
||||
|
||||
|
||||
__version__ = get_version(VERSION)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -51,12 +51,14 @@ class Union(UnmountedType, BaseType):
|
|||
"""
|
||||
|
||||
@classmethod
|
||||
def __init_subclass_with_meta__(cls, types=None, **options):
|
||||
def __init_subclass_with_meta__(cls, types=None, _meta=None, **options):
|
||||
assert (
|
||||
isinstance(types, (list, tuple)) and len(types) > 0
|
||||
), f"Must provide types for Union {cls.__name__}."
|
||||
|
||||
_meta = UnionOptions(cls)
|
||||
if not _meta:
|
||||
_meta = UnionOptions(cls)
|
||||
|
||||
_meta.types = types
|
||||
super(Union, cls).__init_subclass_with_meta__(_meta=_meta, **options)
|
||||
|
||||
|
|
|
@ -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,9 @@ class UUID(Scalar):
|
|||
|
||||
@staticmethod
|
||||
def parse_value(value):
|
||||
return _UUID(value)
|
||||
if isinstance(value, _UUID):
|
||||
return value
|
||||
try:
|
||||
return _UUID(value)
|
||||
except (ValueError, AttributeError):
|
||||
raise GraphQLError(f"UUID cannot represent value: {repr(value)}")
|
||||
|
|
Loading…
Reference in New Issue
Block a user