@@ -107,13 +107,42 @@ func (p *Parser) parseDefinition() Definition {
107107 return nil
108108}
109109
110+ // skipTypeAnnotation assumes the current token is COLON and skips a type annotation.
111+ // It handles simple and list types.
110112func (p * Parser ) skipTypeAnnotation () {
111113 if p .curToken .Type != COLON {
112114 return
113115 }
114116 p .nextToken () // Skip the colon
115- // Skip tokens until we hit a comma, a closing brace, or EOF.
116- for p .curToken .Type != COMMA && p .curToken .Type != RBRACE && p .curToken .Type != EOF {
117+
118+ // Check for list type: if the annotation starts with '['.
119+ if p .curToken .Type == LBRACKET {
120+ // Consume '['
121+ p .nextToken ()
122+ // Consume the inner type (which we assume is a simple type)
123+ if p .curToken .Type == IDENT {
124+ p .nextToken ()
125+ // Optionally skip a trailing BANG for the inner type.
126+ if p .curToken .Type == BANG {
127+ p .nextToken ()
128+ }
129+ }
130+ // Expect a closing bracket.
131+ if p .curToken .Type == RBRACKET {
132+ p .nextToken ()
133+ }
134+ // Optionally, skip a trailing BANG for the list type.
135+ if p .curToken .Type == BANG {
136+ p .nextToken ()
137+ }
138+ return
139+ }
140+
141+ // Otherwise, assume a simple type: one IDENT, optionally followed by a BANG.
142+ if p .curToken .Type == IDENT {
143+ p .nextToken ()
144+ }
145+ if p .curToken .Type == BANG {
117146 p .nextToken ()
118147 }
119148}
@@ -126,7 +155,7 @@ func (p *Parser) skipTypeDefinition() Definition {
126155 return nil // Expected a type name.
127156 }
128157 typeName := p .curToken .Literal
129- p .nextToken () // Move past type name.
158+ p .nextToken () // Move past the type name.
130159
131160 // Expect an opening brace.
132161 if p .curToken .Type != LBRACE {
@@ -137,7 +166,6 @@ func (p *Parser) skipTypeDefinition() Definition {
137166 var fields []* Field
138167 iterations := 0
139168 maxIterations := 10000 // safeguard
140-
141169 for p .curToken .Type != RBRACE && p .curToken .Type != EOF {
142170 iterations ++
143171 if iterations > maxIterations {
@@ -147,7 +175,7 @@ func (p *Parser) skipTypeDefinition() Definition {
147175 if field != nil {
148176 fields = append (fields , field )
149177 } else {
150- // If no field is returned, advance token to ensure progress.
178+ // Advance token to ensure progress.
151179 p .nextToken ()
152180 }
153181 if p .curToken .Type == COMMA {
@@ -212,7 +240,7 @@ func (p *Parser) parseOperationDefinition() *OperationDefinition {
212240}
213241
214242func (p * Parser ) parseTypeField () * Field {
215- // Ensure the current token is an IDENT for the field name.
243+ // Expect an IDENT for the field name.
216244 if p .curToken .Type != IDENT {
217245 return nil
218246 }
@@ -221,7 +249,7 @@ func (p *Parser) parseTypeField() *Field {
221249 }
222250 p .nextToken () // Consume the field name
223251
224- // If there is an argument list, skip it.
252+ // If there's an argument list, skip it.
225253 if p .curToken .Type == LPAREN {
226254 p .skipParenBlock ()
227255 }
0 commit comments