Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
],
children=[
ParsedObject(
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(
name='CreateHeroPayload',
fields=[
ParsedField(name='hero', type='Hero', nullable=True),
def test_parser_query_inline_fragment(swapi_schema):
query = """
query GetFilm {
returnOfTheJedi: film(id: "1") {
... 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(
name='Film',
fields=[
ParsedField(name='title', type='str', nullable=False),
}
}
}
}
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=[
ParsedObject(
name='FilmConnection',
fields=[
query MyIssues {
viewer {
issues(first: 5) {
edges {
node {
author { login }
authorAssociation
}
}
}
}
}
"""
parsed = github_parser.parse(query)
expected = asdict(ParsedQuery(
query=query,
enums=[
ParsedEnum(name='CommentAuthorAssociation', values={'MEMBER': 'MEMBER', 'OWNER': 'OWNER', 'COLLABORATOR': 'COLLABORATOR', 'CONTRIBUTOR': 'CONTRIBUTOR', 'FIRST_TIME_CONTRIBUTOR': 'FIRST_TIME_CONTRIBUTOR', 'FIRST_TIMER': 'FIRST_TIMER', 'NONE': 'NONE'})
],
objects=[
ParsedOperation(
name='MyIssues',
type='query',
children=[
ParsedObject(
name='MyIssuesData',
fields=[
ParsedField(name='viewer', type='User', nullable=False)
],
children=[
ParsedObject(
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(
name='Film',
parents=['FilmFields'],
fields=[
}
}
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(
name='Person',
parents=['CharacterFields'],
fields=[]
def test_parser_query(swapi_schema):
query = """
query GetFilm {
returnOfTheJedi: film(id: "1") {
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',
fields=[
ParsedField(name='title', type='str', nullable=False),
def __init__(self, schema: GraphQLSchema, type_info: TypeInfo, query: str):
self.schema = schema
self.type_info = type_info
self.query = query
self.parsed = ParsedQuery(query=self.query)
self.dfs_path: List[ParsedObject] = []