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

Function completeGeoObject

query/outputnode_graphql.go:1212–1232  ·  view source on GitHub ↗

completeGeoObject builds a json GraphQL result object for the underlying geo type. Currently, it supports Point, Polygon and MultiPolygon.

(path []interface{}, field gqlSchema.Field, val map[string]interface{},
	buf *bytes.Buffer)

Source from the content-addressed store, hash-verified

1210// completeGeoObject builds a json GraphQL result object for the underlying geo type.
1211// Currently, it supports Point, Polygon and MultiPolygon.
1212func completeGeoObject(path []interface{}, field gqlSchema.Field, val map[string]interface{},
1213 buf *bytes.Buffer) *x.GqlError {
1214 coordinate, _ := val[gqlSchema.Coordinates].([]interface{})
1215 if coordinate == nil {
1216 return field.GqlErrorf(path, "missing coordinates in geojson value: %v", val)
1217 }
1218
1219 typ, _ := val["type"].(string)
1220 switch typ {
1221 case gqlSchema.Point:
1222 completePoint(field, coordinate, buf)
1223 case gqlSchema.Polygon:
1224 completePolygon(field, coordinate, buf)
1225 case gqlSchema.MultiPolygon:
1226 completeMultiPolygon(field, coordinate, buf)
1227 default:
1228 return field.GqlErrorf(path, "unsupported geo type: %s", typ)
1229 }
1230
1231 return nil
1232}
1233
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 }.

Callers 1

encodeMethod · 0.85

Calls 4

completePointFunction · 0.85
completePolygonFunction · 0.85
completeMultiPolygonFunction · 0.85
GqlErrorfMethod · 0.65

Tested by

no test coverage detected