How to use the gql.query_parser.QueryParser function in gql

To help you get started, we’ve selected a few gql examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github graphql-python / gql-next / tests / test_query_parser.py View on Github external
def test_parser_query_with_variables(swapi_schema):
    query = """
        query GetFilm($theFilmID: ID!) {
          returnOfTheJedi: film(id: $theFilmID) {
            title
            director
          }
        }
    """

    parser = QueryParser(swapi_schema)
    parsed = parser.parse(query)

    expected = asdict(ParsedQuery(
        query=query,
        objects=[
            ParsedOperation(
                name='GetFilm',
                type='query',
                variables=[
                    ParsedVariableDefinition(name='theFilmID', type='str', nullable=False)
                ],
                children=[
                    ParsedObject(
                        name='GetFilmData',
                        fields=[
                            ParsedField(name='returnOfTheJedi', type='Film', nullable=True)
github graphql-python / gql-next / tests / test_query_parser.py View on Github external
edges {
              node {
                ...HeroFields
              }
            }
          }
        }

        fragment HeroFields on Hero {
            id
            name
        }

    """

    parser = QueryParser(swapi_schema)
    parsed = parser.parse(query)

    expected = asdict(ParsedQuery(
        query=query,
        objects=[
            ParsedOperation(
                name='GetAllFilms',
                type='query',
                children=[
                    ParsedObject(
                        name='GetAllFilmsData',
                        fields=[
                            ParsedField(name='allFilms', type='FilmConnection', nullable=True),
                            ParsedField(name='allHeroes', type='HeroConnection', nullable=True)
                        ],
                        children=[
github graphql-python / gql-next / tests / test_query_parser.py View on Github external
def test_parser_query_fragment(swapi_schema):
    query = """
        query GetFilm {
          returnOfTheJedi: film(id: "1") {
            id
            ...FilmFields
          }
        }

        fragment FilmFields on Film {
            title
            director
        }
    """

    parser = QueryParser(swapi_schema)
    parsed = parser.parse(query)

    expected = asdict(ParsedQuery(
        query=query,
        objects=[
            ParsedOperation(
                name='GetFilm',
                type='query',
                children=[
                    ParsedObject(
                        name='GetFilmData',
                        fields=[
                            ParsedField(name='returnOfTheJedi', type='Film', nullable=True)
                        ],
                        children=[
                            ParsedObject(
github graphql-python / gql-next / tests / test_query_parser.py View on Github external
def test_parser_mutation(swapi_schema):
    query = """
        mutation CreateHero {
          createHero {
            hero {
              name
            }
            ok
          }
        }
    """

    parser = QueryParser(swapi_schema)
    parsed = parser.parse(query)

    expected = asdict(ParsedQuery(
        query=query,
        objects=[
            ParsedOperation(
                name='CreateHero',
                type='mutation',
                children=[
                    ParsedObject(
                        name='CreateHeroData',
                        fields=[
                            ParsedField(name='createHero', type='CreateHeroPayload', nullable=True)
                        ],
                        children=[
                            ParsedObject(
github graphql-python / gql-next / tests / test_query_parser.py View on Github external
def test_parser_fails_invalid_query(swapi_schema):
    query = """
        query ShouldFail {
          allFilms {
            totalCount
            edges {
              node {
                title
                nonExistingField
              }
            }
          }
        }
    """

    parser = QueryParser(swapi_schema)

    with pytest.raises(InvalidQueryError) as excinfo:
        parser.parse(query)

    print(str(excinfo))
github graphql-python / gql-next / tests / test_query_parser.py View on Github external
query GetPerson {
              luke: character(id: "luke") {
                ...CharacterFields
              }
            }

            fragment CharacterFields on Person {
                name

                home: homeworld {
                    name
                }
            }
        """

    parser = QueryParser(swapi_schema)
    parsed = parser.parse(query)

    expected = asdict(ParsedQuery(
        query=query,
        objects=[
            ParsedOperation(
                name='GetPerson',
                type='query',
                children=[
                    ParsedObject(
                        name='GetPersonData',
                        fields=[
                            ParsedField(name='luke', type='Person', nullable=True)
                        ],
                        children=[
                            ParsedObject(
github graphql-python / gql-next / tests / test_renderer_dataclasses.py View on Github external
fields={
                'people': GraphQLField(
                    GraphQLList(GraphQLNonNull(PersonType)),
                    resolve=lambda obj, info: {'name':'eran'}
                )
            }))

    query = """
            query GetPeople {
              people {
                name
              }
            }
        """

    parser = QueryParser(schema)
    dataclass_renderer = DataclassesRenderer(schema, Config(schema='schemaurl', endpoint='schemaurl', documents=''))

    parsed = parser.parse(query)
    rendered = dataclass_renderer.render(parsed)

    m = module_compiler(rendered)

    now = datetime.now()

    call_mock = mocker.patch.object(m.Client, 'call')
    call_mock.return_value = """
       {
           "data": {
               "people": [
                  {
                    "name": "eran"
github graphql-python / gql-next / gql / codec / transform.py View on Github external
def get_parser() -> QueryParser:
    if 'PARSER' not in globals():
        schema = get_schema()
        globals()['PARSER'] = QueryParser(schema)

    return globals()['PARSER']
github graphql-python / gql-next / gql / cli.py View on Github external
def __init__(self, config: Config, schema: GraphQLSchema):
            self.parser = QueryParser(schema)
            self.renderer = DataclassesRenderer(schema, config)