Meet Hasura and Mapbox
We store user Point coord on our Postgres (gis enabled PostGis) and query custom aggregate poi stored inside our Mapbox service as a Tileset.
We first need to create a Mapbox datasets. In a second time the Mapbox Tilequery API allows you to retrieve data about specific features from a vector tileset, based on a given latitude and longitude.
How to create a simple pipeline to create a Mapbox Tileset from push on Github: mapbox-tileset-action
docker-compose up
Go to SQL tab to add some very basic user id and coordinates into a new user_location
table.
Change users coordinates according to your mapbox datasets, we will query data informations in a 3000 meters radius in resolver.js.
-- User location data
CREATE TABLE user_location (
user_id INTEGER PRIMARY KEY,
location GEOGRAPHY(Point)
);
GraphQL Mutation
mutation insertUserLocation(
$user_location_objects: [user_location_insert_input!]!
) {
insert_user_location(objects: $user_location_objects) {
returning {
location
user_id
}
}
}
Variable would be the following:
{
"user_location_objects": [
{
"user_id": 1,
"location": {
"type": "Point",
"coordinates": [2.5365543365478516, 48.77236950468487]
}
},
{
"user_id": 2,
"location": {
"type": "Point",
"coordinates": [2.5059127807617183, 48.7550429007606]
}
}
]
}
-
Click the following button to edit on glitch
-
Rename
.env-sample
into.env
and add the following environment variables.
MAPBOX_API_KEY='YOUR-MAPBOX-TOKEN'
TILESET_ID='YOUR-TILE-ID'
- Open the app on glitch or local Apollo server to test qickly
Query
query($location: geography!) {
places(location: $location) {
name
address
lat
lng
distance
rating
}
}
Test some coordinates in the variable to query mapbox datasets
{
"location": {
"type": "Point",
"coordinates": [2.5365543365478516, 48.77236950468487]
}
}
In Remote Shema just add a new remot shema and enter your glitch app url in
GraphQL server URL
Now in DATA > Relationships > Remote Relationships
click on add remote relationships
and select your dataset and tables to work with
query {
user_location {
user_id
shops {
name
address
lat
lng
rating
distance
}
}
}