Using GraphQL to join data across Google Places API and Postgres to build location based apps

Enabling PostGIS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE EXTENSION postgis; | |
CREATE EXTENSION postgis_topology; |
-- User location data
CREATE TABLE user_location (
user_id INTEGER PRIMARY KEY,
location GEOGRAPHY(Point)
);
Insert Sample Data
mutation insertUserLocation($user_location_objects: [user_location_insert_input!]!) {
insert_user_location(objects: $user_location_objects) {
returning{
location
user_id
}
}
}
{
"user_location_objects": [
{
"user_id": 1,
"location": {
"type": "Point",
"coordinates": [12.9406589, 77.6185572]
}
},
{
"user_id": 2,
"location": {
"type": "Point",
"coordinates": [12.939553, 77.6183303]
}
}
]
}
Deploy Custom Resolver

GOOGLE_MAPS_API_KEY=xxx
PORT=3000
- Get the Google Maps API Key by visting the Google Maps Platform page.
- Set the API key as
GOOGLE_MAPS_API_KEY
environment variable. - This custom resolver is used to accept a location argument of type "geography" of PostGIS and returns restaurants around a radius with name, rating and address details.
- Refer to API documentation for integration with other information like Photos, Reviews etc.


query {
user_location {
user_id
restaurants {
name
lat
long
address
rating
}
}
}
Related reading