Source code for graphene.types.uuid

from __future__ import absolute_import
from uuid import UUID as _UUID

from graphql.language.ast import StringValueNode

from .scalars import Scalar

[docs]class UUID(Scalar): """ Leverages the internal Python implmeentation of UUID (uuid.UUID) to provide native UUID objects in fields, resolvers and input. """ @staticmethod def serialize(uuid): if isinstance(uuid, str): uuid = _UUID(uuid) assert isinstance(uuid, _UUID), "Expected UUID instance, received {}".format( uuid ) return str(uuid) @staticmethod def parse_literal(node): if isinstance(node, StringValueNode): return _UUID(node.value) @staticmethod def parse_value(value): return _UUID(value)