예제 #1
0
    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
예제 #2
0
    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"),
            ]))
예제 #3
0
    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
예제 #4
0
    def skips_invalid_list_items():
        ast = ast_from_value(["FOO", None, "BAR"],
                             GraphQLList(GraphQLNonNull(GraphQLString)))

        assert ast == ListValueNode(values=[
            StringValueNode(value="FOO"),
            StringValueNode(value="BAR")
        ])
    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")]
        )
예제 #6
0
    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 converts_string_values_to_string_asts():
        assert ast_from_value("hello", GraphQLString) == StringValueNode(value="hello")

        assert ast_from_value("VALUE", GraphQLString) == StringValueNode(value="VALUE")

        assert ast_from_value("VA\nLUE", GraphQLString) == StringValueNode(
            value="VA\nLUE"
        )

        assert ast_from_value(123, GraphQLString) == StringValueNode(value="123")

        assert ast_from_value(False, GraphQLString) == StringValueNode(value="false")

        assert ast_from_value(None, GraphQLString) == NullValueNode()

        assert ast_from_value(INVALID, GraphQLString) is None
    def converts_using_serialize_from_a_custom_scalar_type():
        pass_through_scalar = GraphQLScalarType(
            "PassThroughScalar", serialize=lambda value: value,
        )

        assert ast_from_value("value", pass_through_scalar) == StringValueNode(
            value="value"
        )

        return_null_scalar = GraphQLScalarType(
            "ReturnNullScalar", serialize=lambda value: None,
        )

        assert ast_from_value("value", return_null_scalar) is None

        class SomeClass:
            pass

        return_custom_class_scalar = GraphQLScalarType(
            "ReturnCustomClassScalar", serialize=lambda value: SomeClass(),
        )

        with raises(TypeError) as exc_info:
            ast_from_value("value", return_custom_class_scalar)
        msg = str(exc_info.value)
        assert msg == "Cannot convert value to AST: <SomeClass instance>."
예제 #9
0
 def returns_description_of_type_definition_node():
     assert (
         get_description(
             TypeDefinitionNode(
                 description=StringValueNode(value="This is a type definition")
             )
         )
         == "This is a type definition"
     )
예제 #10
0
    def converts_string_values_to_string_asts():
        assert ast_from_value('hello',
                              GraphQLString) == StringValueNode(value='hello')

        assert ast_from_value('VALUE',
                              GraphQLString) == StringValueNode(value='VALUE')

        assert ast_from_value(
            'VA\nLUE', GraphQLString) == StringValueNode(value='VA\nLUE')

        assert ast_from_value(123,
                              GraphQLString) == StringValueNode(value='123')

        assert ast_from_value(False,
                              GraphQLString) == StringValueNode(value='false')

        assert ast_from_value(None, GraphQLString) == NullValueNode()

        assert ast_from_value(INVALID, GraphQLString) is None
예제 #11
0
def string_value_node(value: str, block: Optional[bool], loc: Location):
    return StringValueNode(value=value, block=block, loc=loc)
예제 #12
0
 def returns_none_for_node_without_description():
     assert get_description(
         StringValueNode(value="Just a string value")) is None
예제 #13
0
 def converts_list_singletons():
     assert ast_from_value(
         'FOO', GraphQLList(GraphQLString)) == StringValueNode(value='FOO')
예제 #14
0
def string_value_node(value, block, loc):
    return StringValueNode(value=value, block=block, loc=loc)