(fmap fragmentMap)
| 264 | } |
| 265 | |
| 266 | func (gq *GraphQuery) expandFragments(fmap fragmentMap) error { |
| 267 | // We have to make a copy of children to preserve order and replace |
| 268 | // fragment references with fragment content. The copy is newChildren. |
| 269 | var newChildren []*GraphQuery |
| 270 | // Expand non-fragments. Do not append to gq.Children. |
| 271 | for _, child := range gq.Children { |
| 272 | if child.isFragment() { |
| 273 | fname := child.fragment // Name of fragment being referenced. |
| 274 | fchild := fmap[fname] |
| 275 | if fchild == nil { |
| 276 | return errors.Errorf("Missing fragment: %s", fname) |
| 277 | } |
| 278 | if err := fchild.expand(fmap); err != nil { |
| 279 | return err |
| 280 | } |
| 281 | newChildren = append(newChildren, fchild.Gq.Children...) |
| 282 | } else { |
| 283 | if err := child.expandFragments(fmap); err != nil { |
| 284 | return err |
| 285 | } |
| 286 | newChildren = append(newChildren, child) |
| 287 | } |
| 288 | } |
| 289 | gq.Children = newChildren |
| 290 | return nil |
| 291 | } |
| 292 | |
| 293 | func convertToVarMap(variables map[string]string) (vm varMap) { |
| 294 | vm = make(map[string]varInfo) |
no test coverage detected