MCPcopy Create free account
hub / github.com/dgraph-io/dgraph / completeAggregateChildren

Method completeAggregateChildren

query/outputnode_graphql.go:1157–1208  ·  view source on GitHub ↗

completeAggregateChildren build GraphQL JSON for aggregate fields at child levels. Dgraph result: { "Country.statesAggregate": [ { "State.name": "Calgary", "dgraph.uid": "0x2712" } ], "StateAggregateResult.count_Country.statesAggregate": 1, "StateAggregateResult

(fj fastJsonNode,
	field gqlSchema.Field, fieldPath []interface{}, respIsNull bool)

Source from the content-addressed store, hash-verified

1155// }
1156// }
1157func (genc *graphQLEncoder) completeAggregateChildren(fj fastJsonNode,
1158 field gqlSchema.Field, fieldPath []interface{}, respIsNull bool) fastJsonNode {
1159 if !respIsNull {
1160 // first we need to skip all the nodes returned with the attr of field as they are not
1161 // needed in GraphQL.
1162 attrId := genc.getAttr(fj)
1163 for fj = fj.next; attrId == genc.getAttr(fj); fj = fj.next {
1164 // do nothing
1165 }
1166 // there would always be some other fastJson node after the nodes for field are skipped
1167 // corresponding to a selection inside field that. So, no need to check above if fj != nil.
1168 }
1169
1170 // now fj points to a node containing data for a child of field
1171 comma := ""
1172 suffix := "_" + field.DgraphAlias()
1173 var val []byte
1174 var err error
1175 x.Check2(genc.buf.WriteString("{"))
1176 for _, f := range field.SelectionSet() {
1177 if f.Skip() || !f.Include() {
1178 if f.Name() != gqlSchema.Typename && fj != nil && f.DgraphAlias()+suffix == genc.
1179 attrForID(genc.getAttr(fj)) {
1180 fj = fj.next // if data was there, need to skip that as well for this field
1181 }
1182 continue
1183 }
1184
1185 x.Check2(genc.buf.WriteString(comma))
1186 f.CompleteAlias(genc.buf)
1187
1188 if f.Name() == gqlSchema.Typename {
1189 val = getTypename(f, nil)
1190 } else if fj != nil && f.DgraphAlias()+suffix == genc.attrForID(genc.getAttr(fj)) {
1191 val, err = genc.getScalarVal(fj)
1192 if err != nil {
1193 genc.errs = append(genc.errs, f.GqlErrorf(append(fieldPath,
1194 f.ResponseName()), "%s", err.Error()))
1195 // all aggregate properties are nullable, so no special checks are required
1196 val = gqlSchema.JsonNull
1197 }
1198 fj = fj.next
1199 } else {
1200 val = gqlSchema.JsonNull
1201 }
1202 x.Check2(genc.buf.Write(val))
1203 comma = ","
1204 }
1205 x.Check2(genc.buf.WriteString("}"))
1206
1207 return fj
1208}
1209
1210// completeGeoObject builds a json GraphQL result object for the underlying geo type.
1211// Currently, it supports Point, Polygon and MultiPolygon.

Callers 1

encodeMethod · 0.95

Calls 15

Check2Function · 0.92
getTypenameFunction · 0.85
getAttrMethod · 0.80
attrForIDMethod · 0.80
getScalarValMethod · 0.80
DgraphAliasMethod · 0.65
SelectionSetMethod · 0.65
SkipMethod · 0.65
IncludeMethod · 0.65
NameMethod · 0.65
CompleteAliasMethod · 0.65
GqlErrorfMethod · 0.65

Tested by

no test coverage detected