extractRequiredFieldsData is used to extract the data of fields which are required to resolve a custom field from a given parentNode. It returns a map containing the extracted data along with the dgraph.type values for parentNode. The keys in the returned map correspond to the name of a required fie
(parentNode fastJsonNode, rfDefs map[string]gqlSchema.FieldDefinition)
| 531 | // The keys in the returned map correspond to the name of a required field. |
| 532 | // Values in the map correspond to the extracted data for a required field. |
| 533 | func (genc *graphQLEncoder) extractRequiredFieldsData(parentNode fastJsonNode, |
| 534 | rfDefs map[string]gqlSchema.FieldDefinition) (map[string]interface{}, []string) { |
| 535 | child := genc.children(parentNode) |
| 536 | // first, just skip all the custom nodes |
| 537 | for ; child != nil && genc.getCustom(child); child = child.next { |
| 538 | // do nothing |
| 539 | } |
| 540 | // then, extract data for dgraph.type |
| 541 | child, dgraphTypes := genc.extractDgraphTypes(child) |
| 542 | |
| 543 | // now, iterate over rest of the children of the parentNode and find out the data for |
| 544 | // requiredFields. We can stop iterating as soon as we have the data for all the requiredFields. |
| 545 | rfData := make(map[string]interface{}) |
| 546 | for fj := child; fj != nil && len(rfData) < len(rfDefs); fj = fj.next { |
| 547 | // check if this node has the data for a requiredField. If yes, we need to |
| 548 | // extract that in the rfData map to be used later in substitution. |
| 549 | if rfDef := rfDefs[genc.attrForID(genc.getAttr(fj))]; rfDef != nil { |
| 550 | // if the requiredField is of list type, then need to extract all the data for the list. |
| 551 | // using enc.getList() instead of `rfDef.Type().ListType() != nil` as for custom fields |
| 552 | // both have the same behaviour and enc.getList() is fast. |
| 553 | if genc.getList(fj) { |
| 554 | var vals []interface{} |
| 555 | for ; fj.next != nil && genc.getAttr(fj.next) == genc.getAttr(fj); fj = fj.next { |
| 556 | if val, err := genc.getScalarVal(fj); err == nil { |
| 557 | vals = append(vals, json.RawMessage(val)) |
| 558 | } |
| 559 | } |
| 560 | // append the last list value |
| 561 | if val, err := genc.getScalarVal(fj); err == nil { |
| 562 | vals = append(vals, json.RawMessage(val)) |
| 563 | } |
| 564 | rfData[rfDef.Name()] = vals |
| 565 | } else { |
| 566 | // this requiredField is of non-list type, need to extract the only |
| 567 | // data point for this. |
| 568 | if val, err := genc.getScalarVal(fj); err == nil { |
| 569 | rfData[rfDef.Name()] = json.RawMessage(val) |
| 570 | } |
| 571 | } |
| 572 | } |
| 573 | } |
| 574 | return rfData, dgraphTypes |
| 575 | } |
| 576 | |
| 577 | // writeCustomField is used to write the value when the currentSelection is a custom field. |
| 578 | // If the current field had @custom(http: {...}), then we need to find the fastJson node which |
no test coverage detected