MCPcopy Index your code
hub / github.com/dgraph-io/dgraph / resolveNestedFields

Method resolveNestedFields

query/outputnode_graphql.go:1016–1048  ·  view source on GitHub ↗

resolveNestedFields resolves fields which themselves don't have the @custom directive but their children might. queryUser { id classes { name @custom... } } In the example above, resolveNestedFields would be called on classes field and parentNodeHeads would be the list of head pointers

(childField gqlSchema.Field,
	parentNodeHeads []fastJsonNode, wg *sync.WaitGroup)

Source from the content-addressed store, hash-verified

1014// In the example above, resolveNestedFields would be called on classes field and parentNodeHeads
1015// would be the list of head pointers for all the user fastJson nodes.
1016func (genc *graphQLEncoder) resolveNestedFields(childField gqlSchema.Field,
1017 parentNodeHeads []fastJsonNode, wg *sync.WaitGroup) {
1018 defer wg.Done() // signal when this goroutine finishes execution
1019
1020 var childNodeHeads []fastJsonNode
1021 var parentNodeHeadAttr uint16
1022 if len(parentNodeHeads) > 0 {
1023 parentNodeHeadAttr = genc.getAttr(parentNodeHeads[0])
1024 }
1025 childFieldAttr := genc.idForAttr(childField.DgraphAlias())
1026 // iterate over all the parentNodeHeads and build the list of childNodeHeads for this childField
1027 for _, parentNodeHead := range parentNodeHeads {
1028 // iterate over all the siblings of this parentNodeHead which have the same attr as this
1029 for parentNode := parentNodeHead; parentNode != nil && genc.getAttr(
1030 parentNode) == parentNodeHeadAttr; parentNode = parentNode.next {
1031 // find the first child node which has data for childField
1032 fj := genc.children(parentNode)
1033 for ; fj != nil && genc.getAttr(fj) != childFieldAttr; fj = fj.next {
1034 // do nothing, just keep skipping unnecessary data
1035 }
1036 if fj != nil {
1037 // we found the first node that has data for childField,
1038 // add that node to the list of childNodeHeads
1039 childNodeHeads = append(childNodeHeads, fj)
1040 }
1041 }
1042 }
1043 // if we found some data for the child field, then only we need to
1044 // resolve the custom fields in the selection set of childField
1045 if len(childNodeHeads) > 0 {
1046 genc.resolveCustomFields(childField.SelectionSet(), childNodeHeads)
1047 }
1048}
1049
1050// completeRootAggregateQuery builds GraphQL JSON for aggregate queries at root.
1051// Root aggregate queries return a single object of type `TypeAggregateResult` which contains the

Callers 1

resolveCustomFieldsMethod · 0.95

Calls 7

resolveCustomFieldsMethod · 0.95
getAttrMethod · 0.80
idForAttrMethod · 0.80
childrenMethod · 0.80
DgraphAliasMethod · 0.65
SelectionSetMethod · 0.65
DoneMethod · 0.45

Tested by

no test coverage detected