Coverage for graphqler / compiler / parsers / input_object_list_parser.py: 100%

18 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-03-20 10:09 -0400

1""" 

2Parser for input objects 

3Input objects can depend on other input objects https://spec.graphql.org/June2018/#sec-Input-Object 

4""" 

5 

6from .parser import Parser 

7 

8 

9class InputObjectListParser(Parser): 

10 def __init__(self): 

11 pass 

12 

13 def __extract_field_info(self, input_fields): 

14 resulting_input_fields = {} 

15 for field in input_fields: 

16 field_name = field["name"] 

17 resulting_input_fields[field_name] = { 

18 "kind": field["type"]["kind"], 

19 "type": field["type"]["name"] if "name" in field["type"] else None, 

20 "ofType": self.extract_oftype(field["type"]), 

21 "name": field["type"]["name"] if "name" in field["type"] else None, 

22 } 

23 

24 return resulting_input_fields 

25 

26 def parse(self, introspection_data: dict) -> dict: 

27 """Parses the introspection data for only objects 

28 

29 Args: 

30 data (dict): Introspection JSON as a dictionary 

31 

32 Returns: 

33 dict: List of objects with their types 

34 """ 

35 # Grab just the objects from the dict 

36 schema_types = introspection_data.get("data", {}).get("__schema", {}).get("types", []) 

37 object_types = [t for t in schema_types if t.get("kind") == "INPUT_OBJECT"] 

38 

39 # Convert it to the YAML structure we want 

40 input_object_info_dict = {} 

41 for obj in object_types: 

42 object_name = obj["name"] 

43 input_object_info_dict[object_name] = { 

44 "kind": obj["kind"], 

45 "name": object_name, 

46 "inputFields": self.__extract_field_info(obj["inputFields"]), 

47 } 

48 

49 return input_object_info_dict