mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-22 17:46:57 +03:00
Renamed from JSON to Generic
As it's implementation is abstract of the serializer/unserializer used.
This commit is contained in:
parent
2044d29edb
commit
51b72d8dc8
|
@ -7,11 +7,11 @@ from graphene.types.scalars import MIN_INT, MAX_INT
|
||||||
from .scalars import Scalar
|
from .scalars import Scalar
|
||||||
|
|
||||||
|
|
||||||
class JSON(Scalar):
|
class Generic(Scalar):
|
||||||
"""
|
"""
|
||||||
The `JSON` scalar type represents JSON values as specified by
|
The `Generic` scalar type represents a generic
|
||||||
[ECMA-404](http://www.ecma-international.org/
|
GraphQL scalar value that could be:
|
||||||
publications/files/ECMA-ST/ECMA-404.pdf).
|
String, Boolean, Int, Float, List or Object.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -32,8 +32,8 @@ class JSON(Scalar):
|
||||||
elif isinstance(ast, FloatValue):
|
elif isinstance(ast, FloatValue):
|
||||||
return float(ast.value)
|
return float(ast.value)
|
||||||
elif isinstance(ast, ListValue):
|
elif isinstance(ast, ListValue):
|
||||||
return [JSON.parse_literal(value) for value in ast.values]
|
return [Generic.parse_literal(value) for value in ast.values]
|
||||||
elif isinstance(ast, ObjectValue):
|
elif isinstance(ast, ObjectValue):
|
||||||
return {field.name.value: JSON.parse_literal(field.value) for field in ast.fields}
|
return {field.name.value: Generic.parse_literal(field.value) for field in ast.fields}
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
|
@ -1,12 +1,12 @@
|
||||||
from ..jsontype import JSON
|
from ..generic import Generic
|
||||||
from ..objecttype import ObjectType
|
from ..objecttype import ObjectType
|
||||||
from ..schema import Schema
|
from ..schema import Schema
|
||||||
|
|
||||||
|
|
||||||
class Query(ObjectType):
|
class Query(ObjectType):
|
||||||
json = JSON(input=JSON())
|
generic = Generic(input=Generic())
|
||||||
|
|
||||||
def resolve_json(self, args, context, info):
|
def resolve_generic(self, args, context, info):
|
||||||
input = args.get('input')
|
input = args.get('input')
|
||||||
return input
|
return input
|
||||||
|
|
||||||
|
@ -14,8 +14,8 @@ class Query(ObjectType):
|
||||||
schema = Schema(query=Query)
|
schema = Schema(query=Query)
|
||||||
|
|
||||||
|
|
||||||
def test_json_query_variable():
|
def test_generic_query_variable():
|
||||||
for json_value in [
|
for generic_value in [
|
||||||
1,
|
1,
|
||||||
1.1,
|
1.1,
|
||||||
True,
|
True,
|
||||||
|
@ -45,20 +45,20 @@ def test_json_query_variable():
|
||||||
None
|
None
|
||||||
]:
|
]:
|
||||||
result = schema.execute(
|
result = schema.execute(
|
||||||
'''query Test($json: JSON){ json(input: $json) }''',
|
'''query Test($generic: Generic){ generic(input: $generic) }''',
|
||||||
variable_values={'json': json_value}
|
variable_values={'generic': generic_value}
|
||||||
)
|
)
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
assert result.data == {
|
assert result.data == {
|
||||||
'json': json_value
|
'generic': generic_value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def test_json_parse_literal_query():
|
def test_generic_parse_literal_query():
|
||||||
result = schema.execute(
|
result = schema.execute(
|
||||||
'''
|
'''
|
||||||
query {
|
query {
|
||||||
json(input: {
|
generic(input: {
|
||||||
int: 1,
|
int: 1,
|
||||||
float: 1.1
|
float: 1.1
|
||||||
boolean: true,
|
boolean: true,
|
||||||
|
@ -78,7 +78,7 @@ def test_json_parse_literal_query():
|
||||||
)
|
)
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
assert result.data == {
|
assert result.data == {
|
||||||
'json': {
|
'generic': {
|
||||||
'int': 1,
|
'int': 1,
|
||||||
'float': 1.1,
|
'float': 1.1,
|
||||||
'boolean': True,
|
'boolean': True,
|
Loading…
Reference in New Issue
Block a user