MCPcopy
hub / github.com/dgraph-io/dgraph / completePoint

Function completePoint

query/outputnode_graphql.go:1236–1259  ·  view source on GitHub ↗

completePoint takes in coordinates from dgraph response like [12.32, 123.32], and builds a JSON GraphQL result object for Point like { "longitude" : 12.32 , "latitude" : 123.32 }.

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

Source from the content-addressed store, hash-verified

1234// completePoint takes in coordinates from dgraph response like [12.32, 123.32], and builds
1235// a JSON GraphQL result object for Point like { "longitude" : 12.32 , "latitude" : 123.32 }.
1236func completePoint(field gqlSchema.Field, coordinate []interface{}, buf *bytes.Buffer) {
1237 comma := ""
1238
1239 x.Check2(buf.WriteRune('{'))
1240 for _, f := range field.SelectionSet() {
1241 if f.Skip() || !f.Include() {
1242 continue
1243 }
1244
1245 x.Check2(buf.WriteString(comma))
1246 f.CompleteAlias(buf)
1247
1248 switch f.Name() {
1249 case gqlSchema.Longitude:
1250 x.Check2(buf.WriteString(fmt.Sprintf("%v", coordinate[0])))
1251 case gqlSchema.Latitude:
1252 x.Check2(buf.WriteString(fmt.Sprintf("%v", coordinate[1])))
1253 case gqlSchema.Typename:
1254 x.Check2(buf.WriteString(`"Point"`))
1255 }
1256 comma = ","
1257 }
1258 x.Check2(buf.WriteRune('}'))
1259}
1260
1261// completePolygon converts the Dgraph result to GraphQL Polygon type.
1262// 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]]]

Callers 2

completeGeoObjectFunction · 0.85
completePolygonFunction · 0.85

Calls 6

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

Tested by

no test coverage detected