dcd3ccb75b
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 |
||
---|---|---|
.. | ||
src | ||
static | ||
.gitignore | ||
gridsome.config.js | ||
gridsome.server.js | ||
package.json | ||
README.md | ||
yarn.lock |
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.
Tutorial Steps
-
Deploy the GraphQL Engine on Hasura Cloud and setup PostgreSQL via Heroku:
-
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: -
Insert sample data into
author
table:Verify if the row is inserted successfully
-
Similarly, create an
article
table with the following columns:id
,title
,content
,author_id
(foreign key toauthor
table'sid
) andcreated_at
-
Now create a relationship from the
article
table to theauthor
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 filegridsome.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>
-
Run the app:
yarn start
-
Test the app Visit http://localhost:8080 to view the app
Contributing
Checkout the contributing guide for more details.