def converts_id_values_to_int_or_string_asts(): assert ast_from_value('hello', GraphQLID) == StringValueNode(value='hello') assert ast_from_value('VALUE', GraphQLID) == StringValueNode(value='VALUE') # Note: EnumValues cannot contain non-identifier characters assert ast_from_value('VA\nLUE', GraphQLID) == StringValueNode(value='VA\nLUE') # Note: IntValues are used when possible. assert ast_from_value(-1, GraphQLID) == IntValueNode(value='-1') assert ast_from_value(123, GraphQLID) == IntValueNode(value='123') assert ast_from_value('123', GraphQLID) == IntValueNode(value='123') assert ast_from_value('01', GraphQLID) == StringValueNode(value='01') with raises(TypeError) as exc_info: assert ast_from_value(False, GraphQLID) assert str(exc_info.value) == 'ID cannot represent value: False' assert ast_from_value(None, GraphQLID) == NullValueNode() assert ast_from_value(INVALID, GraphQLString) is None
def converts_list_values_to_list_asts(): assert ast_from_value( ["FOO", "BAR"], GraphQLList(GraphQLString)) == ListValueNode(values=[ StringValueNode(value="FOO"), StringValueNode(value="BAR") ]) assert ast_from_value(["HELLO", "GOODBYE"], GraphQLList(my_enum)) == ListValueNode(values=[ EnumValueNode(value="HELLO"), EnumValueNode(value="GOODBYE") ]) def list_generator(): yield 1 yield 2 yield 3 assert ast_from_value( list_generator(), GraphQLList(GraphQLInt)) == (ListValueNode(values=[ IntValueNode(value="1"), IntValueNode(value="2"), IntValueNode(value="3"), ]))
def converts_id_values_to_int_or_string_asts(): assert ast_from_value("hello", GraphQLID) == StringValueNode(value="hello") assert ast_from_value("VALUE", GraphQLID) == StringValueNode(value="VALUE") # Note: EnumValues cannot contain non-identifier characters assert ast_from_value("VA\nLUE", GraphQLID) == StringValueNode(value="VA\nLUE") # Note: IntValues are used when possible. assert ast_from_value(-1, GraphQLID) == IntValueNode(value="-1") assert ast_from_value(123, GraphQLID) == IntValueNode(value="123") assert ast_from_value("123", GraphQLID) == IntValueNode(value="123") assert ast_from_value("01", GraphQLID) == StringValueNode(value="01") with raises(GraphQLError) as exc_info: assert ast_from_value(False, GraphQLID) assert str(exc_info.value) == "ID cannot represent value: False" assert ast_from_value(None, GraphQLID) == NullValueNode() assert ast_from_value(Undefined, GraphQLString) is None
def check_value_node(): assert not is_value_node(Node()) assert not is_value_node(DocumentNode()) assert is_value_node(ValueNode()) assert is_value_node(IntValueNode()) assert is_value_node(ObjectValueNode()) assert not is_value_node(TypeNode())
def converts_int_values_to_int_asts(): assert ast_from_value(-1, GraphQLInt) == IntValueNode(value="-1") assert ast_from_value(123.0, GraphQLInt) == IntValueNode(value="123") assert ast_from_value(1e4, GraphQLInt) == IntValueNode(value="10000") # GraphQL spec does not allow coercing non-integer values to Int to # avoid accidental data loss. with raises(GraphQLError) as exc_info: assert ast_from_value(123.5, GraphQLInt) msg = str(exc_info.value) assert msg == "Int cannot represent non-integer value: 123.5" # Note: outside the bounds of 32bit signed int. with raises(GraphQLError) as exc_info: assert ast_from_value(1e40, GraphQLInt) msg = str(exc_info.value) assert msg == "Int cannot represent non 32-bit signed integer value: 1e+40"
def parse_invalid_int_as_nan(): assert value_from_ast_untyped(IntValueNode(value="invalid")) is nan