Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def mock_codec_config(swapi_schema, swapi_parser, mocker):
renderer = DataclassesRenderer(swapi_schema, Config(schema='schemaurl', endpoint='schemaurl', documents=''), internal_ns=True)
mocker.patch.object(transform, 'get_schema', return_value=swapi_schema)
mocker.patch.object(transform, 'get_parser', return_value=swapi_parser)
mocker.patch.object(transform, 'get_renderer', return_value=renderer)
def swapi_dataclass_renderer(swapi_schema):
return DataclassesRenderer(swapi_schema, Config(schema='schemaurl', endpoint='schemaurl', documents=''))
}
)
schema = GraphQLSchema(query_type, types=[length_unit_enum, starship_type])
query = """
query GetStarship {
ship(id: "Enterprise") {
id
name
length(unit: METER)
}
}
"""
query_parser = QueryParser(schema)
query_renderer = DataclassesRenderer(schema, Config(schema='schemaurl', endpoint='schemaurl', documents=''))
parsed = query_parser.parse(query)
rendered = query_renderer.render(parsed)
m = module_compiler(rendered)
response = m.GetStarship.from_json("""
{
"data": {
"ship": {
"id": "Enterprise",
"name": "Enterprise",
"length": 100
}
}
}
""")
'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"
},
def github_dataclass_renderer(swapi_schema):
return DataclassesRenderer(swapi_schema, Config(schema='schemaurl', endpoint='schemaurl', documents=''))
def init(schema, endpoint, root, config_filename):
if isfile(config_filename):
click.confirm(f'{config_filename} already exists. Are you sure you want to continue?', abort=True)
if endpoint == 'same as schema':
endpoint = schema
config = Config(
schema=schema,
endpoint=endpoint,
documents=join_paths(root, '**/*.graphql')
)
config.save(config_filename)
click.echo(f"Config file generated at {click.style(config_filename, fg='bright_white')}\n\n")