def test_parses_simple_field_with_list_arg():
    body = '''
type Hello {
  world(things: [String]): String
}'''
    loc = create_loc_fn(body)
    doc = parse(body)
    expected = ast.Document(definitions=[
        ast.ObjectTypeDefinition(
            name=ast.Name(value='Hello', loc=loc(6, 11)),
            interfaces=[],
            fields=[
                ast.FieldDefinition(
                    name=ast.Name(value='world', loc=loc(16, 21)),
                    arguments=[
                        ast.InputValueDefinition(
                            name=ast.Name(value='things', loc=loc(22, 28)),
                            type=ast.ListType(type=ast.NamedType(
                                name=ast.Name(value='String', loc=loc(31, 37)),
                                loc=loc(31, 37)),
                                              loc=loc(30, 38)),
                            default_value=None,
                            loc=loc(22, 38))
                    ],
                    type=ast.NamedType(name=ast.Name(value='String',
                                                     loc=loc(41, 47)),
                                       loc=loc(41, 47)),
                    loc=loc(16, 47))
            ],
            loc=loc(1, 49))
    ],
                            loc=loc(1, 49))
    assert doc == expected
def test_parses_simple_field_with_arg_with_default_value():
    body = '''
type Hello {
  world(flag: Boolean = true): String
}'''
    loc = create_loc_fn(body)
    doc = parse(body)
    expected = ast.Document(definitions=[
        ast.ObjectTypeDefinition(
            name=ast.Name(value='Hello', loc=loc(6, 11)),
            interfaces=[],
            fields=[
                ast.FieldDefinition(
                    name=ast.Name(value='world', loc=loc(16, 21)),
                    arguments=[
                        ast.InputValueDefinition(
                            name=ast.Name(value='flag', loc=loc(22, 26)),
                            type=ast.NamedType(name=ast.Name(value='Boolean',
                                                             loc=loc(28, 35)),
                                               loc=loc(28, 35)),
                            default_value=ast.BooleanValue(value=True,
                                                           loc=loc(38, 42)),
                            loc=loc(22, 42))
                    ],
                    type=ast.NamedType(name=ast.Name(value='String',
                                                     loc=loc(45, 51)),
                                       loc=loc(45, 51)),
                    loc=loc(16, 51))
            ],
            loc=loc(1, 53))
    ],
                            loc=loc(1, 53))

    assert doc == expected
def test_parses_simple_field_with_two_args():
    body = '''
type Hello {
  world(argOne: Boolean, argTwo: Int): String
}'''
    loc = create_loc_fn(body)
    doc = parse(body)
    expected = ast.Document(definitions=[
        ast.ObjectTypeDefinition(
            name=ast.Name(value='Hello', loc=loc(6, 11)),
            interfaces=[],
            fields=[
                ast.FieldDefinition(
                    name=ast.Name(value='world', loc=loc(16, 21)),
                    arguments=[
                        ast.InputValueDefinition(
                            name=ast.Name(value='argOne', loc=loc(22, 28)),
                            type=ast.NamedType(name=ast.Name(value='Boolean',
                                                             loc=loc(30, 37)),
                                               loc=loc(30, 37)),
                            default_value=None,
                            loc=loc(22, 37)),
                        ast.InputValueDefinition(
                            name=ast.Name(value='argTwo', loc=loc(39, 45)),
                            type=ast.NamedType(name=ast.Name(value='Int',
                                                             loc=loc(47, 50)),
                                               loc=loc(47, 50)),
                            default_value=None,
                            loc=loc(39, 50))
                    ],
                    type=ast.NamedType(name=ast.Name(value='String',
                                                     loc=loc(53, 59)),
                                       loc=loc(53, 59)),
                    loc=loc(16, 59))
            ],
            loc=loc(1, 61))
    ],
                            loc=loc(1, 61))
    assert doc == expected
def test_parses_simple_input_object():
    body = '''
input Hello {
  world: String
}'''
    loc = create_loc_fn(body)
    doc = parse(body)
    expected = ast.Document(definitions=[
        ast.InputObjectTypeDefinition(
            name=ast.Name(value='Hello', loc=loc(7, 12)),
            fields=[
                ast.InputValueDefinition(name=ast.Name(value='world',
                                                       loc=loc(17, 22)),
                                         type=ast.NamedType(name=ast.Name(
                                             value='String', loc=loc(24, 30)),
                                                            loc=loc(24, 30)),
                                         default_value=None,
                                         loc=loc(17, 30))
            ],
            loc=loc(1, 32))
    ],
                            loc=loc(1, 32))
    assert doc == expected