mutation insertLandmark($objects: [landmark_insert_input!]!) {
insert_landmark(objects: $objects) {
returning{
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
query landmarks($district_polygon: geometry){ | |
landmarks(where: {location: {_st_within: $district_polygon}}){ | |
id | |
name | |
location | |
} | |
} |
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
{ | |
"data": { | |
"search_landmarks_near_user": [ | |
{ | |
"user_id": 3, | |
"location": { | |
"type": "Point", | |
"crs": { | |
"type": "name", | |
"properties": { |
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
query { | |
search_landmarks_near_user( | |
args: {userid: 3, distance_kms: 20} | |
){ | |
user_id | |
location | |
nearby_landmarks | |
} | |
} |
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
query { | |
search_landmarks_near_user( | |
args: {userid: 3, distance_kms: 20} | |
){ | |
user_id | |
location | |
nearby_landmarks | |
} | |
} |
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
-- SETOF table | |
CREATE TABLE user_landmarks ( | |
user_id INTEGER, | |
location GEOGRAPHY(Point), | |
nearby_landmarks JSON | |
); | |
-- function returns a list of landmarks near a user based on the | |
-- input arguments distance_kms and userid | |
CREATE FUNCTION search_landmarks_near_user(userid integer, distance_kms integer) |
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 PostGIS extensions if they don't exist | |
CREATE EXTENSION IF NOT EXISTS postgis; | |
CREATE EXTENSION IF NOT EXISTS postgis_topology; | |
-- User location data | |
CREATE TABLE user_location ( | |
user_id INTEGER PRIMARY KEY, | |
location GEOGRAPHY(Point) | |
); |
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 FUNCTION search_articles(search text) | |
RETURNS SETOF article AS $$ | |
SELECT * | |
FROM article | |
WHERE | |
title ilike ('%' || search || '%') | |
OR content ilike ('%' || search || '%') | |
$$ LANGUAGE sql STABLE; |
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
-- “search_articles” is a custom SQL function that takes a text input to search an ”article” table | |
query { | |
search_articles( | |
args: {search: "hasura"} | |
){ | |
id | |
title | |
content | |
} |
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
EXPLAIN SELECT * FROM foo; | |
QUERY PLAN | |
--------------------------------------------------------- | |
Seq Scan on foo (cost=0.00..155.00 rows=10000 width=4) | |
(1 row) |