Skip to content

Instantly share code, notes, and snippets.

@dsandip
Last active July 27, 2018 10:02
Show Gist options
  • Save dsandip/46e0193e8aea65042a25fdcf76ec3b4c to your computer and use it in GitHub Desktop.
Save dsandip/46e0193e8aea65042a25fdcf76ec3b4c to your computer and use it in GitHub Desktop.
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

  1. Get a Postgres instance and the Hasura GraphQL engine running on Heroku's free tier in less than a minute: https://docs.hasura.io/0.15/graphql/manual/getting-started/heroku-simple.html

  2. Create table and add test data

    • Create a table named medication with the following schema:

    Table schema

    • Add some test data:

      name diagnosis_code price inventory
      Ibuprofen T39.311A 2.00 12
      Lyrica oral S00-T88 148.00 15
      Butrans transdermal S00-T88 10.00 121
      Ketorolac TROMETHAMINE T21.431C 211.50 1
      diclofenac potassium oral T20-R73 12.50 9
      Advil PM oral T20-R73 160.00 123
  3. Use the GraphiQL window (click on GRAPHIQL link) to run the the following GraphQL query:

    query {
      medication (
        where:{
          _and: [
                { diagnosis_code: {_in: ["S00-T88","T20-R73"]}},
                { price: {_lt: 150}},
                { inventory: {_gt: 10}}
            ]
        }
      ) {
        id
        name
        diagnosis_code
        price
        inventory
      }
    }
  4. Run the following query (or just change the query keyword to subscription in the above query and run it again) and modify the data in the medication table in another tab for real-time updates in your response:

    subscription {
      medication (
        where:{
          _and: [
                { diagnosis_code: {_in: ["S00-T88","T20-R73"]}},
                { price: {_lt: 150}},
                { inventory: {_gt: 10}}
            ]
        }
      ) {
        id
        name
        diagnosis_code
        price
        inventory
      }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment