graphql-engine/community/sample-apps/gridsome-postgres-graphql
hasura-bot dcd3ccb75b docs: update gridsome-postgres-graphql sample app
GITHUB_PR_NUMBER: 8361
GITHUB_PR_URL: https://github.com/hasura/graphql-engine/pull/8361

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4110
Co-authored-by: Catalin Pit <25515812+catalinpit@users.noreply.github.com>
GitOrigin-RevId: d13d274dfb529fcd92d93cf4ecc2bfb949fd2cc3
2022-04-05 14:53:27 +00:00
..
src docs: update gridsome-postgres-graphql sample app 2022-04-05 14:53:27 +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 docs: update gridsome-postgres-graphql sample app 2022-04-05 14:53:27 +00:00
gridsome.server.js docs: update gridsome-postgres-graphql sample app 2022-04-05 14:53:27 +00:00
package.json docs: update gridsome-postgres-graphql sample app 2022-04-05 14:53:27 +00:00
README.md docs: update gridsome-postgres-graphql sample app 2022-04-05 14:53:27 +00:00
yarn.lock docs: update gridsome-postgres-graphql sample app 2022-04-05 14:53:27 +00:00

gridsome-postgres-graphql

Boilerplate to get started with Gridsome, Hasura GraphQL Engine and PostgreSQL. It uses the Hasura GraphQL Engine as a CMS, PostgreSQL as a database and the source-graphql plugin.

Edit gridsome-postgres-graphql

Gridsome Postgres GraphQL

Tutorial Steps

  • Deploy the 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 the author table:

    Open the Hasura console: visit https://gridsome-graphql.hasura.app in a browser Navigate to the 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 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 the article table to the author table by going to the "Relationships" tab.

  • Install the Gridsome CLI:

npm install --global @gridsome/cli

  • Create a Gridsome project:

gridsome create my-gridsome-site

  • Go to your project directory:

cd my-gridsome-site

  • Install the dependencies:

    yarn install
    

    or

    npm install
    
  • Configure Gridsome to use the source-graphql plugin and then configure the GraphQL connection. Open the file gridsome.config.js and add the following code:

{
  plugins: [
    {
      use: '@gridsome/source-graphql',
      options: {
        url: '<your-app-url>/v1/graphql',
        fieldName: 'hasura',
        headers: {
          // Authorization: `Bearer ${process.env.AUTH_TOKEN}`,
        },
      },
    }
  ]
}
  • Create the Articles.vue file in the "pages" folder. After that, write the following code:
<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.