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
|
||||
|
||||
|
||||
class JSON(Scalar):
|
||||
class Generic(Scalar):
|
||||
"""
|
||||
The `JSON` scalar type represents JSON values as specified by
|
||||
[ECMA-404](http://www.ecma-international.org/
|
||||
publications/files/ECMA-ST/ECMA-404.pdf).
|
||||
The `Generic` scalar type represents a generic
|
||||
GraphQL scalar value that could be:
|
||||
String, Boolean, Int, Float, List or Object.
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
|
@ -32,8 +32,8 @@ class JSON(Scalar):
|
|||
elif isinstance(ast, FloatValue):
|
||||
return float(ast.value)
|
||||
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):
|
||||
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:
|
||||
return None
|
|
@ -1,12 +1,12 @@
|
|||
from ..jsontype import JSON
|
||||
from ..generic import Generic
|
||||
from ..objecttype import ObjectType
|
||||
from ..schema import Schema
|
||||
|
||||
|
||||
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')
|
||||
return input
|
||||
|
||||
|
@ -14,8 +14,8 @@ class Query(ObjectType):
|
|||
schema = Schema(query=Query)
|
||||
|
||||
|
||||
def test_json_query_variable():
|
||||
for json_value in [
|
||||
def test_generic_query_variable():
|
||||
for generic_value in [
|
||||
1,
|
||||
1.1,
|
||||
True,
|
||||
|
@ -45,20 +45,20 @@ def test_json_query_variable():
|
|||
None
|
||||
]:
|
||||
result = schema.execute(
|
||||
'''query Test($json: JSON){ json(input: $json) }''',
|
||||
variable_values={'json': json_value}
|
||||
'''query Test($generic: Generic){ generic(input: $generic) }''',
|
||||
variable_values={'generic': generic_value}
|
||||
)
|
||||
assert not result.errors
|
||||
assert result.data == {
|
||||
'json': json_value
|
||||
'generic': generic_value
|
||||
}
|
||||
|
||||
|
||||
def test_json_parse_literal_query():
|
||||
def test_generic_parse_literal_query():
|
||||
result = schema.execute(
|
||||
'''
|
||||
query {
|
||||
json(input: {
|
||||
generic(input: {
|
||||
int: 1,
|
||||
float: 1.1
|
||||
boolean: true,
|
||||
|
@ -78,7 +78,7 @@ def test_json_parse_literal_query():
|
|||
)
|
||||
assert not result.errors
|
||||
assert result.data == {
|
||||
'json': {
|
||||
'generic': {
|
||||
'int': 1,
|
||||
'float': 1.1,
|
||||
'boolean': True,
|
Loading…
Reference in New Issue
Block a user