How to use gql - 10 common examples

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 / tests / starwars / test_validation.py View on Github external
def validation_errors(client, query):
    query = gql(query)
    try:
        client.validate(query)
        return False
    except Exception:
        return True
github graphql-python / gql / tests / starwars / test_query.py View on Github external
def test_check_type_of_r2(client):
    query = gql('''
        query CheckTypeOfR2 {
          hero {
            __typename
            name
          }
        }
    ''')
    expected = {
        'hero': {
            '__typename': 'Droid',
            'name': 'R2-D2',
        }
    }
    result = client.execute(query)
    assert result == expected
github graphql-python / gql / tests / starwars / test_validation.py View on Github external
def local_schema():
    return Client(schema=StarWarsSchema)
github graphql-python / gql / tests / starwars / test_dsl.py View on Github external
def ds():
    client = Client(schema=StarWarsSchema)
    ds = DSLSchema(client)
    return ds
github graphql-python / gql-next / tests / test_query_parser.py View on Github external
fields=[
                            ParsedField(name='returnOfTheJedi', type='Film', nullable=True)
                        ],
                        children=[
                            ParsedObject(
                                name='Film',
                                parents=['FilmFields'],
                                fields=[
                                    ParsedField(name='id', type='str', nullable=False),
                                ]
                            )
                        ],
                    ),
                ]
            ),
            ParsedObject(
                name='FilmFields',
                fields=[
                    ParsedField(name='title', type='str', nullable=False),
                    ParsedField(name='director', type='str', nullable=False),
                ],
            )
        ]
    ))

    parsed_dict = asdict(parsed)

    assert bool(parsed)
    assert parsed_dict == expected, str(DeepDiff(parsed_dict, expected))
github graphql-python / gql-next / tests / test_query_parser.py View on Github external
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(
                                name='Film',
                                fields=[
                                    ParsedField(name='title', type='str', nullable=False),
                                    ParsedField(name='director', type='str', nullable=False),
                                ]
                            )
                        ]
                    )
                ]
            )
github graphql-python / gql-next / tests / test_query_parser.py View on Github external
ParsedObject(
                        name='GetPersonData',
                        fields=[
                            ParsedField(name='luke', type='Person', nullable=True)
                        ],
                        children=[
                            ParsedObject(
                                name='Person',
                                parents=['CharacterFields'],
                                fields=[]
                            )
                        ],
                    ),
                ]
            ),
            ParsedObject(
                name='CharacterFields',
                fields=[
                    ParsedField(name='name', type='str', nullable=False),
                    ParsedField(name='home', type='Planet', nullable=False),
                ],
                children=[
                    ParsedObject(
                        name='Planet',
                        fields=[
                            ParsedField(name='name', type='str', nullable=False),
                        ]
                    )
                ]
            )
        ]
    ))
github graphql-python / gql-next / tests / test_query_parser.py View on Github external
}
          }
        }
    """

    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(
                                name='Film',
                                fields=[
                                    ParsedField(name='title', type='str', nullable=False),
                                    ParsedField(name='director', type='str', nullable=False),
                                ]
                            )
                        ],
                    )
                ]
            )
github graphql-python / gql-next / tests / test_query_parser.py View on Github external
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(
                                name='CreateHeroPayload',
                                fields=[
                                    ParsedField(name='hero', type='Hero', nullable=True),
                                    ParsedField(name='ok', type='bool', nullable=True)
                                ],
                                children=[
                                    ParsedObject(
                                        name='Hero',
                                        fields=[
                                            ParsedField(name='name', type='str', nullable=False)
github graphql-python / gql-next / tests / test_query_parser.py View on Github external
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(
                                name='Film',
                                parents=['FilmFields'],
                                fields=[
                                    ParsedField(name='id', type='str', nullable=False),
                                ]
                            )
                        ],
                    ),
                ]
            ),