graphql-engine/community/sample-apps/nuxtjs-postgres-graphql
hasura-bot 01e5be146f community: update nuxtjs-postgres-graphql sample app
GITHUB_PR_NUMBER: 8359
GITHUB_PR_URL: https://github.com/hasura/graphql-engine/pull/8359

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4103
Co-authored-by: Catalin Pit <25515812+catalinpit@users.noreply.github.com>
GitOrigin-RevId: b811692e1e61eb0aae0b87d7935863d725af161a
2022-04-05 13:25:32 +00:00
..
apollo community: update nuxtjs-postgres-graphql sample app 2022-04-05 13:25:32 +00:00
assets add nuxtjs-postgres-graphql (#1439) 2019-01-23 16:49:32 +05:30
components add nuxtjs-postgres-graphql (#1439) 2019-01-23 16:49:32 +05:30
layouts add nuxtjs-postgres-graphql (#1439) 2019-01-23 16:49:32 +05:30
middleware add nuxtjs-postgres-graphql (#1439) 2019-01-23 16:49:32 +05:30
pages add nuxtjs-postgres-graphql (#1439) 2019-01-23 16:49:32 +05:30
plugins community: update nuxtjs-postgres-graphql sample app 2022-04-05 13:25:32 +00:00
static add nuxtjs-postgres-graphql (#1439) 2019-01-23 16:49:32 +05:30
store add nuxtjs-postgres-graphql (#1439) 2019-01-23 16:49:32 +05:30
.gitignore add nuxtjs-postgres-graphql (#1439) 2019-01-23 16:49:32 +05:30
nuxt.config.js community: update nuxtjs-postgres-graphql sample app 2022-04-05 13:25:32 +00:00
package-lock.json community: update nuxtjs-postgres-graphql sample app 2022-04-05 13:25:32 +00:00
package.json community: update nuxtjs-postgres-graphql sample app 2022-04-05 13:25:32 +00:00
README.md readme: use cloud signup endpoint for "Deploy to Hasura" CTA 2021-08-19 07:03:05 +00:00

nuxtjs-postgres-graphql

Boilerplate to get started with Nuxt.js, Hasura GraphQL engine as CMS and postgres as database using the create-nuxt-app and @nuxtjs/apollo module.

Edit nuxtjs-postgres-graphql

Tutorial

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

    Deploy to Hasura Cloud

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

  • Create author table:

    Open Hasura console: visit https://nuxtjs-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)

  • Clone this repo:

    git clone https://github.com/hasura/graphql-engine
    cd graphql-engine/community/sample-apps/nuxtjs-postgres-graphql
    
  • Install npm modules:

    npm install
    
  • Open apollo/clientConfig.js and configure Hasura's GraphQL Endpoint as follows:

    
      import { InMemoryCache } from "apollo-cache-inmemory";
      export default function(context){
        return {
              httpLinkOptions: {
                  uri: 'https://nextjs-graphql.hasura.app/v1/graphql',
                  credentials: 'same-origin'
              },
              cache: new InMemoryCache(),
              wsEndpoint: 'ws://nextjs-graphql.hasura.app/v1/graphql',
        }
      }
    
  • We have defined the graphql query in apollo/queries/fetchAuthor.gql.

    • GraphQL query
    
    query {
      author {
        id
        name
      }
    }
    
    
    • In pages/index.vue, we import author query.
    
    <script>
    import author from '~/apollo/queries/fetchAuthor'
    
    export default {
      apollo: {
        author: {
          prefetch: true,
          query: author
        }
      },
      head: {
        title: 'Authors of Blog'
      }
    }
    </script>
    
    
  • Run the app:

    npm run dev
    
  • Test the app Visit http://localhost:3000 to view the app

For detailed explanation on how things work, checkout Nuxt.js docs.