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

Function completePolygon

query/outputnode_graphql.go:1267–1327  ·  view source on GitHub ↗

completePolygon converts the Dgraph result to GraphQL Polygon type. Dgraph output: coordinate: [[[22.22,11.11],[16.16,15.15],[21.21,20.2]],[[22.28,11.18],[16.18,15.18],[21.28,20.28]]] Graphql output: { coordinates: [ { points: [{ latitude: 11.11, longitude: 22.22}, { latitude: 15.15, longitude: 16.1

(field gqlSchema.Field, polygon []interface{}, buf *bytes.Buffer)

Source from the content-addressed store, hash-verified

1265// { latitude: 11.18, longitude: 22.28}, { latitude: 15.18, longitude: 16.18} ,
1266// { latitude: 20.28, longitude: 21.28}]} ] }
1267func completePolygon(field gqlSchema.Field, polygon []interface{}, buf *bytes.Buffer) {
1268 comma1 := ""
1269
1270 x.Check2(buf.WriteRune('{'))
1271 for _, f1 := range field.SelectionSet() {
1272 if f1.Skip() || !f1.Include() {
1273 continue
1274 }
1275
1276 x.Check2(buf.WriteString(comma1))
1277 f1.CompleteAlias(buf)
1278
1279 switch f1.Name() {
1280 case gqlSchema.Coordinates:
1281 x.Check2(buf.WriteRune('['))
1282 comma2 := ""
1283
1284 for _, ring := range polygon {
1285 x.Check2(buf.WriteString(comma2))
1286 x.Check2(buf.WriteRune('{'))
1287 comma3 := ""
1288
1289 for _, f2 := range f1.SelectionSet() {
1290 if f2.Skip() || !f2.Include() {
1291 continue
1292 }
1293
1294 x.Check2(buf.WriteString(comma3))
1295 f2.CompleteAlias(buf)
1296
1297 switch f2.Name() {
1298 case gqlSchema.Points:
1299 x.Check2(buf.WriteRune('['))
1300 comma4 := ""
1301
1302 r, _ := ring.([]interface{})
1303 for _, point := range r {
1304 x.Check2(buf.WriteString(comma4))
1305
1306 p, _ := point.([]interface{})
1307 completePoint(f2, p, buf)
1308
1309 comma4 = ","
1310 }
1311 x.Check2(buf.WriteRune(']'))
1312 case gqlSchema.Typename:
1313 x.Check2(buf.WriteString(`"PointList"`))
1314 }
1315 comma3 = ","
1316 }
1317 x.Check2(buf.WriteRune('}'))
1318 comma2 = ","
1319 }
1320 x.Check2(buf.WriteRune(']'))
1321 case gqlSchema.Typename:
1322 x.Check2(buf.WriteString(`"Polygon"`))
1323 }
1324 comma1 = ","

Callers 2

completeGeoObjectFunction · 0.85
completeMultiPolygonFunction · 0.85

Calls 7

Check2Function · 0.92
completePointFunction · 0.85
SelectionSetMethod · 0.65
SkipMethod · 0.65
IncludeMethod · 0.65
CompleteAliasMethod · 0.65
NameMethod · 0.65

Tested by

no test coverage detected