Exemple #1
0
def test_it_parses_variable_definition_with_default_and_directives():
    assert_node_equal(
        parse("query ($foo: Int = 42 @bar @baz) { foo }", no_location=True),
        _ast.Document(
            definitions=[
                _ast.OperationDefinition(
                    "query",
                    _ast.SelectionSet(
                        selections=[_ast.Field(name=_ast.Name(value="foo"),)],
                    ),
                    variable_definitions=[
                        _ast.VariableDefinition(
                            variable=_ast.Variable(
                                name=_ast.Name(value="foo"),
                            ),
                            type=_ast.NamedType(name=_ast.Name(value="Int"),),
                            default_value=_ast.IntValue(value="42"),
                            directives=[
                                _ast.Directive(name=_ast.Name(value="bar")),
                                _ast.Directive(name=_ast.Name(value="baz")),
                            ],
                        )
                    ],
                )
            ],
        ),
    )
Exemple #2
0
def test_parse_type_it_parses_non_null_types():
    assert_node_equal(
        parse_type("MyType!"),
        _ast.NonNullType(
            loc=(0, 7),
            type=_ast.NamedType(
                loc=(0, 6), name=_ast.Name(loc=(0, 6), value="MyType")
            ),
        ),
    )
Exemple #3
0
def test_parse_type_it_parses_list_types():
    assert_node_equal(
        parse_type("[MyType]"),
        _ast.ListType(
            loc=(0, 8),
            type=_ast.NamedType(
                loc=(1, 7), name=_ast.Name(loc=(1, 7), value="MyType")
            ),
        ),
    )
Exemple #4
0
def test_parse_type_it_parses_nested_types():
    assert_node_equal(
        parse_type("[MyType!]"),
        _ast.ListType(
            loc=(0, 9),
            type=_ast.NonNullType(
                loc=(1, 8),
                type=_ast.NamedType(
                    loc=(1, 7), name=_ast.Name(loc=(1, 7), value="MyType")
                ),
            ),
        ),
    )
Exemple #5
0
def test_it_parses_inline_fragment_without_type():
    assert_node_equal(
        parse(
            """
    fragment validFragment on Pet {
        ... {
            name
        }
    }
    """
        ),
        _ast.Document(
            loc=(0, 88),
            definitions=[
                _ast.FragmentDefinition(
                    loc=(5, 83),
                    name=_ast.Name(loc=(14, 27), value="validFragment"),
                    type_condition=_ast.NamedType(
                        loc=(31, 34), name=_ast.Name(loc=(31, 34), value="Pet")
                    ),
                    variable_definitions=None,
                    selection_set=_ast.SelectionSet(
                        loc=(35, 83),
                        selections=[
                            _ast.InlineFragment(
                                loc=(45, 77),
                                selection_set=_ast.SelectionSet(
                                    loc=(49, 77),
                                    selections=[
                                        _ast.Field(
                                            loc=(63, 67),
                                            name=_ast.Name(
                                                loc=(63, 67), value="name"
                                            ),
                                        )
                                    ],
                                ),
                            )
                        ],
                    ),
                )
            ],
        ),
    )
Exemple #6
0
def _type(loc, value):
    return _ast.NamedType(loc=loc, name=_ast.Name(loc=loc, value=value))
Exemple #7
0
def test_parse_type_it_parses_custom_types():
    assert_node_equal(
        parse_type("MyType"),
        _ast.NamedType(loc=(0, 6), name=_ast.Name(loc=(0, 6), value="MyType")),
    )
Exemple #8
0
def test_parse_type_it_parses_well_known_types():
    assert_node_equal(
        parse_type("String"),
        _ast.NamedType(loc=(0, 6), name=_ast.Name(loc=(0, 6), value="String")),
    )