Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def validation_errors(client, query):
query = gql(query)
try:
client.validate(query)
return False
except Exception:
return True
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
def local_schema():
return Client(schema=StarWarsSchema)
def ds():
client = Client(schema=StarWarsSchema)
ds = DSLSchema(client)
return ds
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))
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),
]
)
]
)
]
)
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),
]
)
]
)
]
))
}
}
}
"""
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),
]
)
],
)
]
)
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)
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),
]
)
],
),
]
),