| 113 | |
| 114 | |
| 115 | def run_graphql_test(query, expected_output, graph, sort_output=False): |
| 116 | tmp_work_dir = tempfile.mkdtemp() |
| 117 | with GraphServer(tmp_work_dir).start() as server: |
| 118 | client = server.get_client() |
| 119 | client.send_graph(path="g", graph=graph) |
| 120 | response = client.query(query) |
| 121 | |
| 122 | # Convert response to a dictionary if needed and compare |
| 123 | response_dict = json.loads(response) if isinstance(response, str) else response |
| 124 | if sort_output: |
| 125 | response_dict = sort_by_gql_name_or_id(response_dict) |
| 126 | expected_output = sort_by_gql_name_or_id(expected_output) |
| 127 | assert ( |
| 128 | response_dict == expected_output |
| 129 | ), f"left={sort_dict_recursive(response_dict)}\nright={sort_dict_recursive(expected_output)}" |
| 130 | |
| 131 | |
| 132 | def run_group_graphql_test(queries_and_expected_outputs, graph, sort_output=False): |