fragmentType finds the first fragment, in query order, on a possible type.
(sel ast.SelectionSet, find func(string) *ast.Definition)
| 281 | |
| 282 | // fragmentType finds the first fragment, in query order, on a possible type. |
| 283 | func (s *gqlScaffolder) fragmentType(sel ast.SelectionSet, find func(string) *ast.Definition) *ast.Definition { |
| 284 | for _, item := range sel { |
| 285 | var cond string |
| 286 | var inner ast.SelectionSet |
| 287 | switch x := item.(type) { |
| 288 | case *ast.InlineFragment: |
| 289 | if s.skipped(x.Directives) { |
| 290 | continue |
| 291 | } |
| 292 | cond, inner = x.TypeCondition, x.SelectionSet |
| 293 | case *ast.FragmentSpread: |
| 294 | if x.Definition == nil || s.skipped(x.Directives) { |
| 295 | continue |
| 296 | } |
| 297 | cond, inner = x.Definition.TypeCondition, x.Definition.SelectionSet |
| 298 | default: |
| 299 | continue |
| 300 | } |
| 301 | if t := find(cond); t != nil { |
| 302 | return t |
| 303 | } |
| 304 | if t := s.fragmentType(inner, find); t != nil { |
| 305 | return t |
| 306 | } |
| 307 | } |
| 308 | return nil |
| 309 | } |
| 310 | |
| 311 | // collect groups the fields a selection asks for on an object of type |
| 312 | // concrete by response key, in query order. Fields that share a key are |