コード例 #1
0
def test_it_parses_type_with_description_string():
    assert_node_equal(
        parse(
            """
"Description"
type Hello {
  world: String
}""",
            allow_type_system=True,
        ),
        _ast.Document(
            loc=(0, 45),
            definitions=[
                _ast.ObjectTypeDefinition(
                    loc=(1, 45),
                    name=_name((20, 25), "Hello"),
                    interfaces=[],
                    directives=[],
                    description=_ast.StringValue(loc=(1, 14),
                                                 value="Description"),
                    fields=[
                        _field(
                            (30, 43),
                            _name((30, 35), "world"),
                            _type((37, 43), "String"),
                        )
                    ],
                )
            ],
        ),
    )
コード例 #2
0
def test_it_parses_simple_type():
    body = """
type Hello {
  world: String
}"""
    assert_node_equal(
        parse(body, allow_type_system=True),
        _ast.Document(
            loc=(0, 31),
            definitions=[
                _ast.ObjectTypeDefinition(
                    loc=(1, 31),
                    name=_name((6, 11), "Hello"),
                    interfaces=[],
                    directives=[],
                    fields=[
                        _field(
                            (16, 29),
                            _name((16, 21), "world"),
                            _type((23, 29), "String"),
                        )
                    ],
                )
            ],
        ),
    )
コード例 #3
0
def test_it_parses_simple_field_with_arg_with_default_value():
    body = """
type Hello {
  world(flag: Boolean = true): String
}"""
    assert_node_equal(
        parse(body, allow_type_system=True),
        _doc(
            (0, 53),
            [
                _ast.ObjectTypeDefinition(
                    loc=(1, 53),
                    name=_name((6, 11), "Hello"),
                    interfaces=[],
                    directives=[],
                    fields=[
                        _field(
                            (16, 51),
                            _name((16, 21), "world"),
                            _type((45, 51), "String"),
                            [
                                _input(
                                    (22, 42),
                                    _name((22, 26), "flag"),
                                    _type((28, 35), "Boolean"),
                                    _ast.BooleanValue(loc=(38, 42),
                                                      value=True),
                                )
                            ],
                        )
                    ],
                )
            ],
        ),
    )
コード例 #4
0
def test_it_parses_simple_type_inheriting_multiple_interfaces_with_leading_ampersand(
):  # noqa: E501
    body = "type Hello implements & Wo & rld { field: String }"
    assert_node_equal(
        parse(body, allow_type_system=True),
        _ast.Document(
            loc=(0, 50),
            definitions=[
                _ast.ObjectTypeDefinition(
                    loc=(0, 50),
                    name=_name((5, 10), "Hello"),
                    interfaces=[_type((24, 26), "Wo"),
                                _type((29, 32), "rld")],
                    directives=[],
                    fields=[
                        _field(
                            (35, 48),
                            _name((35, 40), "field"),
                            _type((42, 48), "String"),
                        )
                    ],
                )
            ],
        ),
    )
コード例 #5
0
def test_it_parses_type_with_description_multi_line_string():
    body = '''
"""
Description
"""
# Even with comments between them
type Hello {
  world: String
}'''

    assert_node_equal(
        parse(body, allow_type_system=True),
        _ast.Document(
            loc=(0, 85),
            definitions=[
                _ast.ObjectTypeDefinition(
                    loc=(1, 85),
                    name=_name((60, 65), "Hello"),
                    interfaces=[],
                    directives=[],
                    description=_ast.StringValue(loc=(1, 20),
                                                 value="Description",
                                                 block=True),
                    fields=[
                        _field(
                            (70, 83),
                            _name((70, 75), "world"),
                            _type((77, 83), "String"),
                        )
                    ],
                )
            ],
        ),
    )
コード例 #6
0
def test_it_parses_simple_field_with_two_args():
    body = """
type Hello {
  world(argOne: Boolean, argTwo: Int): String
}"""
    assert_node_equal(
        parse(body, allow_type_system=True),
        _doc(
            (0, 61),
            [
                _ast.ObjectTypeDefinition(
                    loc=(1, 61),
                    name=_name((6, 11), "Hello"),
                    interfaces=[],
                    directives=[],
                    fields=[
                        _field(
                            (16, 59),
                            _name((16, 21), "world"),
                            _type((53, 59), "String"),
                            [
                                _input(
                                    (22, 37),
                                    _name((22, 28), "argOne"),
                                    _type((30, 37), "Boolean"),
                                ),
                                _input(
                                    (39, 50),
                                    _name((39, 45), "argTwo"),
                                    _type((47, 50), "Int"),
                                ),
                            ],
                        )
                    ],
                )
            ],
        ),
    )
コード例 #7
0
def test_it_parses_simple_type_inheriting_interface():
    body = "type Hello implements World { field: String }"
    assert_node_equal(
        parse(body, allow_type_system=True),
        _ast.Document(
            loc=(0, 45),
            definitions=[
                _ast.ObjectTypeDefinition(
                    loc=(0, 45),
                    name=_name((5, 10), "Hello"),
                    interfaces=[_type((22, 27), "World")],
                    directives=[],
                    fields=[
                        _field(
                            (30, 43),
                            _name((30, 35), "field"),
                            _type((37, 43), "String"),
                        )
                    ],
                )
            ],
        ),
    )
コード例 #8
0
def test_it_parses_simple_field_with_list_arg():
    body = """
type Hello {
  world(things: [String]): String
}"""
    assert_node_equal(
        parse(body, allow_type_system=True),
        _doc(
            (0, 49),
            [
                _ast.ObjectTypeDefinition(
                    loc=(1, 49),
                    name=_name((6, 11), "Hello"),
                    interfaces=[],
                    directives=[],
                    fields=[
                        _field(
                            (16, 47),
                            _name((16, 21), "world"),
                            _type((41, 47), "String"),
                            [
                                _input(
                                    (22, 38),
                                    _name((22, 28), "things"),
                                    _ast.ListType(
                                        loc=(30, 38),
                                        type=_type((31, 37), "String"),
                                    ),
                                )
                            ],
                        )
                    ],
                )
            ],
        ),
    )