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
Example #2
0
 def converts_input_objects_with_explicit_nulls():
     assert ast_from_value({
         "foo": None
     }, input_obj) == ObjectValueNode(fields=[
         ObjectFieldNode(name=NameNode(value="foo"), value=NullValueNode())
     ])