# gatsby-postgres-graphql Boilerplate to get started with Gatsby, Hasura GraphQL engine as CMS and postgres as database using the awesome plugin [gatsby-source-graphql](https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-source-graphql). [![Edit gatsby-postgres-graphql](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/github/hasura/graphql-engine/tree/master/community/sample-apps/gatsby-postgres-graphql?fontsize=14) ![Gatsby Postgres GraphQL](./assets/gatsby-postgres-graphql.png) # Tutorial - Deploy GraphQL Engine on Hasura Cloud and setup PostgreSQL via Heroku: [![Deploy to Hasura Cloud](https://graphql-engine-cdn.hasura.io/img/deploy_to_hasura.png)](https://cloud.hasura.io/signup) - Get the Hasura app URL (say `gatsby-graphql.hasura.app`) - Clone this repo: ```bash git clone https://github.com/hasura/graphql-engine cd graphql-engine/community/sample-apps/gatsby-postgres-graphql ``` - Create `author` table: Open Hasura console: visit https://gatsby-graphql.hasura.app on a browser Navigate to `Data` section in the top nav bar and create a table as follows: ![Create author table](./assets/add_table.jpg) - Insert sample data into `author` table: ![Insert data into author table](./assets/insert_data.jpg) Verify if the row is inserted successfully ![Insert data into author table](./assets/browse_rows.jpg) - Install npm modules: ```bash npm install ``` - Configure gatsby to use `gatsby-source-graphql` plugin and a connection GraphQL url to stitch the schema. ```js { plugins: [ { resolve: "gatsby-source-graphql", // <- Configure plugin options: { typeName: "HASURA", fieldName: "hasura", // <- fieldName under which schema will be stitched url: process.env.GATSBY_HASURA_GRAPHQL_URL, refetchInterval: 10 // Refresh every 10 seconds for new data } } ]; } ``` - Run the app: ```bash GATSBY_HASURA_GRAPHQL_URL=https://gatsby-graphql.hasura.app/v1/graphql npm run develop ``` - Test the app Visit [http://localhost:8000](http://localhost:8000) to view the app ![Demo app](./assets/test_app.jpg) # Make a GraphQL query from your component using hooks 1. Create a component named `AuthorList.js`: ```js import React from "react"; import { useQuery } from "@apollo/react-hooks"; import { gql } from "apollo-boost"; const GET_AUTHORS = gql` query { author { id name } } `; const AuthorList = () => { const { loading, error, data } = useQuery(GET_AUTHORS); if (loading) return "loading..."; if (error) return `error: ${error.message}`; return (