mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-09 08:00:39 +03:00
* expose livehtml autobuild in Makefile * add API documentation for schema * document graphene core API * fixes black lint * Update graphene/types/union.py Co-Authored-By: Jonathan Kim <jkimbo@gmail.com> * Update graphene/types/argument.py Co-Authored-By: Jonathan Kim <jkimbo@gmail.com> * Update graphene/types/field.py Co-Authored-By: Jonathan Kim <jkimbo@gmail.com> * Update graphene/types/inputfield.py Co-Authored-By: Jonathan Kim <jkimbo@gmail.com> * add note about non-functional `interfaces` meta argument in mutation * update with other virtual environment configuration * pin autobuild * format argument example code * format enum input object and interface examples * format enum mutation union examples * revise documentation with imports, capitalization
34 lines
785 B
Python
34 lines
785 B
Python
from __future__ import absolute_import
|
|
import six
|
|
from uuid import UUID as _UUID
|
|
|
|
from graphql.language import ast
|
|
|
|
from .scalars import Scalar
|
|
|
|
|
|
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, six.string_types):
|
|
uuid = _UUID(uuid)
|
|
|
|
assert isinstance(uuid, _UUID), "Expected UUID instance, received {}".format(
|
|
uuid
|
|
)
|
|
return str(uuid)
|
|
|
|
@staticmethod
|
|
def parse_literal(node):
|
|
if isinstance(node, ast.StringValue):
|
|
return _UUID(node.value)
|
|
|
|
@staticmethod
|
|
def parse_value(value):
|
|
return _UUID(value)
|