mirror of
https://github.com/graphql-python/graphene.git
synced 2025-09-21 19:32:33 +03:00
Converted Scalars
This commit is contained in:
parent
e23184fe13
commit
a0428d749f
|
@ -3,7 +3,7 @@ from __future__ import absolute_import
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from aniso8601 import parse_date, parse_datetime, parse_time
|
from aniso8601 import parse_date, parse_datetime, parse_time
|
||||||
from graphql.language import ast
|
from graphql.language.ast import StringValueNode
|
||||||
|
|
||||||
from .scalars import Scalar
|
from .scalars import Scalar
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ class Date(Scalar):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse_literal(cls, node):
|
def parse_literal(cls, node):
|
||||||
if isinstance(node, ast.StringValue):
|
if isinstance(node, StringValueNode):
|
||||||
return cls.parse_value(node.value)
|
return cls.parse_value(node.value)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -56,7 +56,7 @@ class DateTime(Scalar):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse_literal(cls, node):
|
def parse_literal(cls, node):
|
||||||
if isinstance(node, ast.StringValue):
|
if isinstance(node, StringValueNode):
|
||||||
return cls.parse_value(node.value)
|
return cls.parse_value(node.value)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -86,7 +86,7 @@ class Time(Scalar):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse_literal(cls, node):
|
def parse_literal(cls, node):
|
||||||
if isinstance(node, ast.StringValue):
|
if isinstance(node, StringValueNode):
|
||||||
return cls.parse_value(node.value)
|
return cls.parse_value(node.value)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
@ -2,7 +2,7 @@ from __future__ import absolute_import
|
||||||
|
|
||||||
from decimal import Decimal as _Decimal
|
from decimal import Decimal as _Decimal
|
||||||
|
|
||||||
from graphql.language import ast
|
from graphql.language.ast import StringValueNode
|
||||||
|
|
||||||
from .scalars import Scalar
|
from .scalars import Scalar
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ class Decimal(Scalar):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse_literal(cls, node):
|
def parse_literal(cls, node):
|
||||||
if isinstance(node, ast.StringValue):
|
if isinstance(node, StringValueNode):
|
||||||
return cls.parse_value(node.value)
|
return cls.parse_value(node.value)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from graphql.language.ast import (
|
from graphql.language.ast import (
|
||||||
BooleanValue,
|
BooleanValueNode,
|
||||||
FloatValue,
|
FloatValueNode,
|
||||||
IntValue,
|
IntValueNode,
|
||||||
ListValue,
|
ListValueNode,
|
||||||
ObjectValue,
|
ObjectValueNode,
|
||||||
StringValue,
|
StringValueNode,
|
||||||
)
|
)
|
||||||
|
|
||||||
from graphene.types.scalars import MAX_INT, MIN_INT
|
from graphene.types.scalars import MAX_INT, MIN_INT
|
||||||
|
@ -30,17 +30,17 @@ class GenericScalar(Scalar):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_literal(ast):
|
def parse_literal(ast):
|
||||||
if isinstance(ast, (StringValue, BooleanValue)):
|
if isinstance(ast, (StringValueNode, BooleanValueNode)):
|
||||||
return ast.value
|
return ast.value
|
||||||
elif isinstance(ast, IntValue):
|
elif isinstance(ast, IntValueNode):
|
||||||
num = int(ast.value)
|
num = int(ast.value)
|
||||||
if MIN_INT <= num <= MAX_INT:
|
if MIN_INT <= num <= MAX_INT:
|
||||||
return num
|
return num
|
||||||
elif isinstance(ast, FloatValue):
|
elif isinstance(ast, FloatValueNode):
|
||||||
return float(ast.value)
|
return float(ast.value)
|
||||||
elif isinstance(ast, ListValue):
|
elif isinstance(ast, ListValueNode):
|
||||||
return [GenericScalar.parse_literal(value) for value in ast.values]
|
return [GenericScalar.parse_literal(value) for value in ast.values]
|
||||||
elif isinstance(ast, ObjectValue):
|
elif isinstance(ast, ObjectValueNode):
|
||||||
return {
|
return {
|
||||||
field.name.value: GenericScalar.parse_literal(field.value)
|
field.name.value: GenericScalar.parse_literal(field.value)
|
||||||
for field in ast.fields
|
for field in ast.fields
|
||||||
|
|
|
@ -2,7 +2,7 @@ from __future__ import absolute_import
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from graphql.language import ast
|
from graphql.language.ast import StringValueNode
|
||||||
|
|
||||||
from .scalars import Scalar
|
from .scalars import Scalar
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ class JSONString(Scalar):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_literal(node):
|
def parse_literal(node):
|
||||||
if isinstance(node, ast.StringValue):
|
if isinstance(node, StringValueNode):
|
||||||
return json.loads(node.value)
|
return json.loads(node.value)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from graphql.language.ast import BooleanValue, FloatValue, IntValue, StringValue
|
from graphql.language.ast import (
|
||||||
|
BooleanValueNode,
|
||||||
|
FloatValueNode,
|
||||||
|
IntValueNode,
|
||||||
|
StringValueNode,
|
||||||
|
)
|
||||||
|
|
||||||
from .base import BaseOptions, BaseType
|
from .base import BaseOptions, BaseType
|
||||||
from .unmountedtype import UnmountedType
|
from .unmountedtype import UnmountedType
|
||||||
|
@ -71,7 +76,7 @@ class Int(Scalar):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_literal(ast):
|
def parse_literal(ast):
|
||||||
if isinstance(ast, IntValue):
|
if isinstance(ast, IntValueNode):
|
||||||
num = int(ast.value)
|
num = int(ast.value)
|
||||||
if MIN_INT <= num <= MAX_INT:
|
if MIN_INT <= num <= MAX_INT:
|
||||||
return num
|
return num
|
||||||
|
@ -97,7 +102,7 @@ class Float(Scalar):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_literal(ast):
|
def parse_literal(ast):
|
||||||
if isinstance(ast, (FloatValue, IntValue)):
|
if isinstance(ast, (FloatValueNode, IntValueNode)):
|
||||||
return float(ast.value)
|
return float(ast.value)
|
||||||
|
|
||||||
|
|
||||||
|
@ -119,7 +124,7 @@ class String(Scalar):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_literal(ast):
|
def parse_literal(ast):
|
||||||
if isinstance(ast, StringValue):
|
if isinstance(ast, StringValueNode):
|
||||||
return ast.value
|
return ast.value
|
||||||
|
|
||||||
|
|
||||||
|
@ -133,7 +138,7 @@ class Boolean(Scalar):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_literal(ast):
|
def parse_literal(ast):
|
||||||
if isinstance(ast, BooleanValue):
|
if isinstance(ast, BooleanValueNode):
|
||||||
return ast.value
|
return ast.value
|
||||||
|
|
||||||
|
|
||||||
|
@ -151,5 +156,5 @@ class ID(Scalar):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_literal(ast):
|
def parse_literal(ast):
|
||||||
if isinstance(ast, (StringValue, IntValue)):
|
if isinstance(ast, (StringValueNode, IntValueNode)):
|
||||||
return ast.value
|
return ast.value
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
from uuid import UUID as _UUID
|
from uuid import UUID as _UUID
|
||||||
|
|
||||||
from graphql.language import ast
|
from graphql.language.ast import StringValueNode
|
||||||
|
|
||||||
from .scalars import Scalar
|
from .scalars import Scalar
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ class UUID(Scalar):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_literal(node):
|
def parse_literal(node):
|
||||||
if isinstance(node, ast.StringValue):
|
if isinstance(node, StringValueNode):
|
||||||
return _UUID(node.value)
|
return _UUID(node.value)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
Loading…
Reference in New Issue
Block a user