@@ -99,6 +99,10 @@ def _dynamic_field():
9999 return strawberry .field (_dynamic_field )
100100
101101
102+ class NodeNotFoundError (Exception ):
103+ pass
104+
105+
102106class FieldsTree :
103107 def __init__ (self , name : str ):
104108 self .name = name
@@ -108,28 +112,34 @@ def __init__(self, name: str):
108112 "mutation" : [],
109113 }
110114
111- def insert (self , path : list [str ]):
115+ def insert (self , path : list [str ]) -> "FieldsTree" :
112116 # Create child if not exist
113117 name = path .pop (0 )
114- if not (child := self .get_child (name )):
118+ if self .is_child (name ):
119+ child = self .get_child (name )
120+ else :
115121 child = FieldsTree (name )
116122 self .children .append (child )
117- else :
118- child = self .get_child (name )
119123
120124 # Recurse if needed
121125 if path :
122126 return child .insert (path ) # type: ignore
123127 else :
124128 return child
125129
126- def get_child (self , name : str ):
130+ def is_child (self , name : str ) -> bool :
131+ for child in self .children :
132+ if child .name == name :
133+ return True
134+ return False
135+
136+ def get_child (self , name : str ) -> "FieldsTree" :
127137 for child in self .children :
128138 if child .name == name :
129139 return child
130- return None
140+ raise NodeNotFoundError
131141
132- def create_type (self , strawberry_type : str ):
142+ def create_type (self , strawberry_type : str ) -> type :
133143 for child in self .children :
134144 child_field = _wrap_as_field (
135145 child .name ,
0 commit comments