I’m very impressed with the GraphQL API in Dgraph (extremely impressed with the @auth
directive!).
I have, however, hit a bit of a roadblock in the POC phase for how this might work for the app that we’re building, in that I can’t seem to figure out how to implement geolocation fields, not really in any way a fault of Dgraph’s implementation as this isn’t handled in the official GraphQL spec (that I can find).
The issue for me is that our application is in the transport industry and as such, as you can imagine, it’s heavily reliant on the geolocation data.
My thoughts are that, just like the scalar DateTime
appears to be a custom scalar type for Dgraph, with its operations interpreted and rewritten to run in the GraphQL± way, we could look to create Point
and Polygon
types (with geo
index) which are in turn rewritten to be the appropriate geo:geojson
string for the database.
We’d also need to implement the appropriate query (near
, within
, contains
, intersects
) and mutation syntaxes for each of these ‘types’.
I can picture that the structure of a Point would be something like:
type Point {
Latitude: Float!
Longitude: Float!
}
and Polygon being something like:
#Creating PointList as I'm not able to find whether or not GQL allows for nested lists:
type PointList {
Points: [Point!]
}
type Polygon {
Coordinates: [PointList!]
}
#Probably implement MultiPolygon also as the Dgraph docs specify it as available
type MultiPolygon {
Coordinates: [Polygon!]
}
Unless I’m mistaken, the above should match the GraphQL± specification for Geolocation in the docs and therefore should be ‘translatable’ to GraphQL± queries and mutations:
https://dgraph.io/docs/query-language/#geolocation
I’d be interested to hear opinions on the above or if I’m heading up the wrong path with this?