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)
| 1210 | // completeGeoObject builds a json GraphQL result object for the underlying geo type. |
| 1211 | // Currently, it supports Point, Polygon and MultiPolygon. |
| 1212 | func 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 }. |
no test coverage detected