コード例 #1
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"),
            ]))
コード例 #2
0
    def converts_string_values_to_enum_asts_if_possible():
        assert ast_from_value("HELLO", my_enum) == EnumValueNode(value="HELLO")

        assert ast_from_value(complex_value, my_enum) == EnumValueNode(value="COMPLEX")

        # Note: case sensitive
        assert ast_from_value("hello", my_enum) is None

        # Note: not a valid enum value
        assert ast_from_value("VALUE", my_enum) is None
コード例 #3
0
    def converts_string_values_to_enum_asts_if_possible():
        assert ast_from_value('HELLO', my_enum) == EnumValueNode(value='HELLO')

        assert ast_from_value(complex_value,
                              my_enum) == EnumValueNode(value='COMPLEX')

        # Note: case sensitive
        assert ast_from_value('hello', my_enum) is None

        # Note: not a valid enum value
        assert ast_from_value('VALUE', my_enum) is None
コード例 #4
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")]
        )
コード例 #5
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')
                              ])
コード例 #6
0
    def converts_string_values_to_enum_asts_if_possible():
        assert ast_from_value("HELLO", my_enum) == EnumValueNode(value="HELLO")

        assert ast_from_value(complex_value,
                              my_enum) == EnumValueNode(value="COMPLEX")

        # Note: case sensitive
        with raises(GraphQLError) as exc_info:
            ast_from_value("hello", my_enum)
        assert exc_info.value.message == "Enum 'MyEnum' cannot represent value: 'hello'"

        # Note: not a valid enum value
        with raises(GraphQLError) as exc_info:
            ast_from_value("UNKNOWN_VALUE", my_enum)
        assert (exc_info.value.message ==
                "Enum 'MyEnum' cannot represent value: 'UNKNOWN_VALUE'")
コード例 #7
0
 def converts_input_objects():
     assert ast_from_value({
         "foo": 3,
         "bar": "HELLO"
     }, input_obj) == ObjectValueNode(fields=[
         ObjectFieldNode(name=NameNode(value="foo"),
                         value=FloatValueNode(value="3")),
         ObjectFieldNode(name=NameNode(value="bar"),
                         value=EnumValueNode(value="HELLO")),
     ])
コード例 #8
0
    def converts_input_objects():
        input_obj = GraphQLInputObjectType(
            'MyInputObj', {
                'foo': GraphQLInputField(GraphQLFloat),
                'bar': GraphQLInputField(my_enum)
            })

        assert ast_from_value({
            'foo': 3,
            'bar': 'HELLO'
        }, input_obj) == ObjectValueNode(fields=[
            ObjectFieldNode(name=NameNode(value='foo'),
                            value=FloatValueNode(value='3')),
            ObjectFieldNode(name=NameNode(value='bar'),
                            value=EnumValueNode(value='HELLO'))
        ])
コード例 #9
0
    def converts_input_objects():
        input_obj = GraphQLInputObjectType(
            "MyInputObj",
            {"foo": GraphQLInputField(GraphQLFloat), "bar": GraphQLInputField(my_enum)},
        )

        assert ast_from_value({"foo": 3, "bar": "HELLO"}, input_obj) == ObjectValueNode(
            fields=[
                ObjectFieldNode(
                    name=NameNode(value="foo"), value=FloatValueNode(value="3")
                ),
                ObjectFieldNode(
                    name=NameNode(value="bar"), value=EnumValueNode(value="HELLO")
                ),
            ]
        )