Coverage for graphqler / compiler / parsers / mutation_list_parser.py: 95%
19 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-20 10:09 -0400
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-20 10:09 -0400
1"""Simple singleton class to parse mutation listings from the introspection query"""
3from .parser import Parser
6class MutationListParser(Parser):
7 def __init__(self):
8 pass
10 def parse(self, introspection_data: dict) -> dict:
11 """Parses the introspection data for only objects
13 Args:
14 data (dict): Introspection JSON as a dictionary
16 Returns:
17 dict: List of objects with their types
18 """
19 # Grab just the objects from the dict
20 schema_types = introspection_data.get("data", {}).get("__schema", {}).get("types", [])
21 mutation_object = [t for t in schema_types if t.get("kind") == "OBJECT" and (t.get("name") == "Mutation" or t.get("name") == "Mutations")]
23 # If no mutations, just early return
24 if len(mutation_object) == 0:
25 return {}
26 mutations = mutation_object[0]["fields"]
28 # Convert it to the YAML structure we want
29 mutation_info_dict = {}
30 for mutation in mutations:
31 mutation_name = mutation["name"]
32 mutation_args = self.extract_arg_info(mutation["args"])
33 is_deprecated = mutation["isDeprecated"]
34 description = mutation["description"]
36 return_type = {"kind": mutation["type"]["kind"], "name": mutation["type"]["name"], "ofType": self.extract_oftype(mutation["type"]), "type": mutation["type"]["name"]}
38 mutation_info_dict[mutation_name] = {"name": mutation_name, "inputs": mutation_args, "output": return_type, "isDepracated": is_deprecated, "description": description}
40 return mutation_info_dict