Esempio n. 1
0
def test_parse_creates_ast():
    source = Source("""{
  node(id: 4) {
    id,
    name
  }
}
""")
    result = parse(source)

    assert result == \
           ast.Document(
               loc={'start': 0, 'end': 41, 'source': source},
               definitions=
               [ast.OperationDefinition(
                   loc={'start': 0, 'end': 40, 'source': source},
                   operation='query',
                   name=None,
                   variable_definitions=None,
                   directives=[],
                   selection_set=ast.SelectionSet(
                       loc={'start': 0, 'end': 40, 'source': source},
                       selections=
                       [ast.Field(
                           loc={'start': 4, 'end': 38, 'source': source},
                           alias=None,
                           name=ast.Name(
                               loc={'start': 4, 'end': 8, 'source': source},
                               value='node'),
                           arguments=[ast.Argument(
                               name=ast.Name(loc={'start': 9, 'end': 11, 'source': source},
                                             value='id'),
                               value=ast.IntValue(
                                   loc={'start': 13, 'end': 14, 'source': source},
                                   value='4'),
                               loc={'start': 9, 'end': 14, 'source': source})],
                           directives=[],
                           selection_set=ast.SelectionSet(
                               loc={'start': 16, 'end': 38, 'source': source},
                               selections=
                               [ast.Field(
                                   loc={'start': 22, 'end': 24, 'source': source},
                                   alias=None,
                                   name=ast.Name(
                                       loc={'start': 22, 'end': 24, 'source': source},
                                       value='id'),
                                   arguments=[],
                                   directives=[],
                                   selection_set=None),
                                ast.Field(
                                    loc={'start': 30, 'end': 34, 'source': source},
                                    alias=None,
                                    name=ast.Name(
                                        loc={'start': 30, 'end': 34, 'source': source},
                                        value='name'),
                                    arguments=[],
                                    directives=[],
                                    selection_set=None)]))]))])
Esempio n. 2
0
def test_parse_creates_ast():
    source = Source("""{
  node(id: 4) {
    id,
    name
  }
}
""")
    result = parse(source)

    assert result == \
           ast.Document(
               loc=Loc(start=0, end=41, source=source),
               definitions=
               [ast.OperationDefinition(
                   loc=Loc(start=0, end=40, source=source),
                   operation='query',
                   name=None,
                   variable_definitions=None,
                   directives=[],
                   selection_set=ast.SelectionSet(
                       loc=Loc(start=0, end=40, source=source),
                       selections=
                       [ast.Field(
                           loc=Loc(start=4, end=38, source=source),
                           alias=None,
                           name=ast.Name(
                               loc=Loc(start=4, end=8, source=source),
                               value='node'),
                           arguments=[ast.Argument(
                               name=ast.Name(loc=Loc(start=9, end=11, source=source),
                                             value='id'),
                               value=ast.IntValue(
                                   loc=Loc(start=13, end=14, source=source),
                                   value='4'),
                               loc=Loc(start=9, end=14, source=source))],
                           directives=[],
                           selection_set=ast.SelectionSet(
                               loc=Loc(start=16, end=38, source=source),
                               selections=
                               [ast.Field(
                                   loc=Loc(start=22, end=24, source=source),
                                   alias=None,
                                   name=ast.Name(
                                       loc=Loc(start=22, end=24, source=source),
                                       value='id'),
                                   arguments=[],
                                   directives=[],
                                   selection_set=None),
                                   ast.Field(
                                       loc=Loc(start=30, end=34, source=source),
                                       alias=None,
                                       name=ast.Name(
                                           loc=Loc(start=30, end=34, source=source),
                                           value='name'),
                                       arguments=[],
                                       directives=[],
                                       selection_set=None)]))]))])
Esempio n. 3
0
def test_lex_reports_useful_information_for_dashes_in_names():
    q = u'a-b'
    lexer = Lexer(Source(q))
    first_token = lexer.next_token()
    assert first_token == Token(TokenKind.NAME, 0, 1, 'a')
    with raises(LanguageError) as excinfo:
        lexer.next_token()

    assert u'Syntax Error GraphQL (1:3) Invalid number, expected digit but got: "b".' in excinfo.value.message
Esempio n. 4
0
def lex_one(s):
    return Lexer(Source(s)).next_token()
def validation_errors(query):
    source = Source(query, 'StarWars.graphql')
    ast = parse(source)
    return validate(StarWarsSchema, ast)
Esempio n. 6
0
def test_parse_provides_useful_error_when_using_source():
    with raises(LanguageError) as excinfo:
        parse(Source('query', 'MyQuery.graphql'))
    assert 'Syntax Error MyQuery.graphql (1:6) Expected Name, found EOF' in str(
        excinfo.value)