def run_test(instrumented_schema: ast.Module, query: str, params: list, field_args_dict : dict): """[summary] Args: instrumented_schema (ast.Module): The AST form of the instrumented schema.py file query (string): GraphQL query string for target function params (list): List of arguments to be passed to the query Returns: list(tuple): List of tuples representing the executed path/trace. Format is (expr, test_val, lineno, branch_dist) """ schema = executable_schema(instrumented_schema) swsetup() hpsetup() client = Client(schema) context = {"trace_execution": []} variables = {} for i, param_name in enumerate(field_args_dict): variables[param_name] = params[i] blockPrint() client.execute(query, context=context, variables=variables) enablePrint() exec_path = context["trace_execution"] return exec_path
def test_fetch_id_query_mutate_query(): swsetup() hpsetup() client = Client(schema) query = """ query FetchSomeIDQuery($someId: String!) { char(id: $someId) { name } } """ params = {"someId": "1007"} mutate = """ mutation myFirstMutation { createHuman( id: 1007, name: "Anthony", sctype: [SW], appearsIn: [NEWHOPE]) { human { name } } } """ print(client.execute(query, variables=params)) print(client.execute(mutate)) print(client.execute(query, variables=params))
def test_fetch_luke_query(): swsetup() hpsetup() client = Client(schema) query = """ query FetchLukeQuery { human(id: "1000") { name } } """ client.execute(query)
def test_hero_name_query(): swsetup() hpsetup() client = Client(schema) query = """ query HeroNameQuery { hero(scType:HP) { name, id sctype } } """ print(client.execute(query))
def test_fetch_id_query_persistence(): swsetup() hpsetup() client = Client(schema) query = """ query FetchSomeIDQuery($someId: String!) { human(id: $someId) { name } } """ params = {"someId": "3000"} con = {"trace": []} result = schema.execute(query, context=con)
def test_hero_name_and_friends_query(): swsetup() hpsetup() client = Client(schema) query = """ query HeroNameAndFriendsQuery { hero { id name friends { name } } } """ client.execute(query)
def test_nested_query(): swsetup() hpsetup() client = Client(schema) query = """ query NestedQuery { hero { name friends { name appearsIn friends { name } } } } """ client.execute(query)