Exemple #1
0
 def converts_name_node_to_dict():
     node = NameNode(value="test")
     res = ast_to_dict(node)
     assert res == {"kind": "name", "value": "test"}
     assert list(res)[0] == "kind"
     assert ast_to_dict(node, locations=True) == res
     assert node.to_dict() == res
     assert node.to_dict(locations=True) == res
Exemple #2
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")),
     ])
Exemple #3
0
 def converts_two_name_nodes_to_list():
     nodes = [NameNode(value="foo"), NameNode(value="bar")]
     res = ast_to_dict(nodes)
     assert ast_to_dict(nodes, locations=True) == res
     assert res == [
         {
             "kind": "name",
             "value": "foo"
         },
         {
             "kind": "name",
             "value": "bar"
         },
     ]
            def enter(*args):
                parent_type = type_info.get_parent_type()
                type_ = type_info.get_type()
                input_type = type_info.get_input_type()
                node = args[0]
                visited.append(
                    (
                        "enter",
                        node.kind,
                        node.value if node.kind == "name" else None,
                        str(parent_type) if parent_type else None,
                        str(type_) if type_ else None,
                        str(input_type) if input_type else None,
                    )
                )

                # Make a query valid by adding missing selection sets.
                if (
                    node.kind == "field"
                    and not node.selection_set
                    and is_composite_type(get_named_type(type_))
                ):
                    return FieldNode(
                        alias=node.alias,
                        name=node.name,
                        arguments=node.arguments,
                        directives=node.directives,
                        selection_set=SelectionSetNode(
                            selections=[FieldNode(name=NameNode(value="__typename"))]
                        ),
                    )
    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'))
        ])
    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")
                ),
            ]
        )
    def converts_input_objects_with_explicit_nulls():
        input_obj = GraphQLInputObjectType(
            "MyInputObj",
            {"foo": GraphQLInputField(GraphQLFloat), "bar": GraphQLInputField(my_enum)},
        )

        assert ast_from_value({"foo": None}, input_obj) == ObjectValueNode(
            fields=[ObjectFieldNode(name=NameNode(value="foo"), value=NullValueNode())]
        )
    def converts_input_objects_with_explicit_nulls():
        input_obj = GraphQLInputObjectType(
            'MyInputObj', {
                'foo': GraphQLInputField(GraphQLFloat),
                'bar': GraphQLInputField(my_enum)
            })

        assert ast_from_value({
            'foo': None
        }, input_obj) == ObjectValueNode(fields=[
            ObjectFieldNode(name=NameNode(value='foo'), value=NullValueNode())
        ])
Exemple #9
0
def name_node(name: str, loc: Location):
    return NameNode(value=name, loc=loc)
Exemple #10
0
 def prints_minimal_ast():
     ast = FieldNode(name=NameNode(value="foo"))
     assert print_ast(ast) == "foo"
Exemple #11
0
 def prints_minimal_ast():
     node = ScalarTypeDefinitionNode(name=NameNode(value="foo"))
     assert print_ast(node) == "scalar foo"
def name_node(name, loc):
    return NameNode(value=name, loc=loc)
Exemple #13
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())
     ])