graphql-engine/community/sample-apps/gridsome-postgres-graphql
Rikin Kachhia 3696d92743 add github workflow to compress new images in PRs
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
GitOrigin-RevId: cfef3585b120d82cafe5343cfceddbcd05969a15
2021-03-10 20:55:02 +00:00
..
src add github workflow to compress new images in PRs 2021-03-10 20:55:02 +00:00
static community: add gridsome sample app (#2363) 2019-06-10 18:57:38 +05:30
.gitignore community: add gridsome sample app (#2363) 2019-06-10 18:57:38 +05:30
gridsome.config.js community: add gridsome sample app (#2363) 2019-06-10 18:57:38 +05:30
gridsome.server.js community: add gridsome sample app (#2363) 2019-06-10 18:57:38 +05:30
package.json community: add gridsome sample app (#2363) 2019-06-10 18:57:38 +05:30
README.md community: update sample apps to use hasura cloud and v3 migrations/metadata 2021-03-02 08:32:37 +00:00
yarn.lock community: add gridsome sample app (#2363) 2019-06-10 18:57:38 +05:30

gridsome-postgres-graphql

Boilerplate to get started with Gridsome, Hasura GraphQL engine as CMS and postgres as database using the awesome plugin source-graphql.

Edit gridsome-postgres-graphql

Gridsome Postgres GraphQL

Tutorial

  • Deploy GraphQL Engine on Hasura Cloud and setup PostgreSQL via Heroku:

    Deploy to Hasura Cloud

  • Get the Hasura app URL (say gridsome-graphql.hasura.app)

  • Create author table:

    Open Hasura console: visit https://gridsome-graphql.hasura.app on a browser
    Navigate to Data section in the top nav bar and create a table as follows:

    Create author table

  • Insert sample data into author table:

    Insert data into author table

    Verify if the row is inserted successfully

    Insert data into author table

  • Similarly, create an article table with the following data model: table: article columns: id, title, content, author_id (foreign key to author table's id) and created_at

    Create foreign key for author_id column to author's id

  • Now create a relationship from article table to author table by going to the Relationships tab.

  • Install Gridsome CLI tool if you don't have

npm install --global @gridsome/cli

  • Create a Gridsome project

gridsome create my-gridsome-site

  • Go to your project directory

cd my-gridsome-site

  • Install node modules:

    yarn install
    

    or npm

    npm install
    
  • Configure Gridsome to use source-graphql plugin and a connection GraphQL url to stitch the schema. Open the file gridsome.config.js and modify the plugin section to configure the GraphQL Endpoint.

{
  plugins: [
    {
      use: '@gridsome/source-graphql',
      options: {
        url: 'https://gridsome-graphql.hasura.app/v1/graphql',
        fieldName: 'hasura',
        headers: {
          // Authorization: `Bearer ${process.env.AUTH_TOKEN}`,
        },
      },
    }
  ]
}
  • Make a GraphQL query from your component
<template>
  <Layout>
    <h1>Articles</h1>
    <div v-if="$page.hasura.article.length">
        <div class="articles" v-for="article in $page.hasura.article" :key="article.id">
          <p>{{ article.title }} by {{ article.author.name }}</p>
        </div>
    </div>
    <div v-else>
        <p>No articles found</p>
    </div>
  </Layout>
</template>

<page-query>
query {
  hasura {
    article {
      id
      title
      author {
        name
      }
    }
  }
}
</page-query>

Contributing

Checkout the contributing guide for more details.