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)
| 1155 | // } |
| 1156 | // } |
| 1157 | func (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. |
no test coverage detected