Skip to content

Instantly share code, notes, and snippets.

SELECT
album.id as album_id,
album.title as album_title,
track.id as track_id,
track.title as track_title
FROM
album
LEFT OUTER JOIN
track
ON
[
{
"title" : "Album1",
"tracks": [
{"id" : 1, "title": "track1"},
{"id" : 2, "title": "track2"}
]
},
{
"title" : "Album2",
SELECT json_agg(r.*) FROM (
SELECT
album.title as title,
json_agg(track.*) as tracks
FROM
album
LEFT OUTER JOIN
track
ON
(album.id = track.album_id)
{
album (where: {year: {_eq: 2018}}) {
title
tracks {
id
title
}
}
}
PREPARE prep_1 AS SELECT json_agg(r.*) FROM (
SELECT
album.title as title,
json_agg(track.*) as tracks
FROM
album
LEFT OUTER JOIN
track
ON
(album.id = track.album_id)
@dsandip
dsandip / schema.graphql
Last active June 8, 2018 13:55
schema for a blog app's database
const typeDefs = `
type Query {
author(firstName: String, lastName: String): Author
allAuthors: [Author]
allArticles: [Article]
}
type Author {
id: Int
@dsandip
dsandip / authors_articles.graphql
Last active June 8, 2018 13:57
query for all authors and their articles
query {
allAuthors(){
firstName
lastName
articles{
title
views
}
}
}
@dsandip
dsandip / articles_authors.graphql
Created June 8, 2018 14:01
A list of all articles and their authors
query {
allArticles(){
title
views
author{
firstName
lastName
}
}
}
@dsandip
dsandip / cURL_example.md
Last active July 27, 2018 10:02
Example cURL to query GraphQL endpoint

cURL example to test the query

curl --header "Content-Type: application/json" \
  --request POST \
  --data '{"query":"query { medication ( where:{ _and: [ { diagnosis_code: {_in: [\"S00-T88\",\"T20-R73\"]}}, { price: {_lt: 150}}, { inventory: {_gt: 10}} ] } ) { id name diagnosis_code price inventory } }","variables":null}' \
  https://hasura-graphql-test.herokuapp.com/v1alpha1/graphql

Try this out yourself

Hasura Technologies Pvt. Ltd. Contributor License Agreement

This Contributor License Agreement (“Agreement”) is entered into between Hasura Technologies Pvt. Ltd., (“Hasura,” “we” or “us”.) and You. Accordingly, You hereby agree to the following terms for your present and future contributions submitted to Hasura:

  1. Definitions:

    (a) "You" (or "your") shall mean the copyright owner (whether an individual or organization) or a party authorized by the copyright owner that is making this Agreement with Hasura. For Entities, the Entity making a Contribution and all other Entities that control, are controlled by, or are under common control with that Entity are considered to be a single Contributor. For the purposes of this definition, “control” means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity

(b) "Contri