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"))]
                        ),
                    )
示例#2
0
 def check_selection_node():
     assert not is_selection_node(Node())
     assert not is_selection_node(DocumentNode())
     assert is_selection_node(SelectionNode())
     assert is_selection_node(FieldNode())
     assert is_selection_node(InlineFragmentNode())
     assert not is_selection_node(SelectionSetNode())
示例#3
0
 def converts_recursive_ast_to_recursive_dict():
     field = FieldNode(name="foo", arguments=(), selection_set=())
     ast = SelectionSetNode(selections=(field, ))
     field.selection_set = ast
     res = ast_to_dict(ast)
     assert res == {
         "kind":
         "selection_set",
         "selections": [{
             "kind": "field",
             "name": "foo",
             "alias": None,
             "arguments": [],
             "directives": None,
             "selection_set": res,
         }],
     }
示例#4
0
 def produces_helpful_error_messages():
     bad_ast = {"random": "Data"}
     with raises(TypeError) as exc_info:
         # noinspection PyTypeChecker
         print_ast(bad_ast)  # type: ignore
     assert str(exc_info.value) == "Not an AST Node: {'random': 'Data'}."
     corrupt_ast = FieldNode(name="random data")
     with raises(TypeError) as exc_info:
         print_ast(corrupt_ast)
     assert str(exc_info.value) == "Invalid AST Node: 'random data'."
示例#5
0
 def prints_minimal_ast():
     ast = FieldNode(name=NameNode(value="foo"))
     assert print_ast(ast) == "foo"