graphql-engine/community/sample-apps/quasar-framework-vue-graphql
Catalin Pit 3c15fa9f93 community: update Quasar sample app
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4262
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
GitOrigin-RevId: d4633d9e789d95b0b796266485ea0c62b9e55f69
2022-04-13 16:13:36 +00:00
..
public community: update Quasar sample app 2022-04-13 16:13:36 +00:00
src community: update Quasar sample app 2022-04-13 16:13:36 +00:00
.editorconfig add quasar framework sample app (#1825) 2019-03-20 12:42:50 +05:30
.eslintignore community: update Quasar sample app 2022-04-13 16:13:36 +00:00
.eslintrc.js community: update Quasar sample app 2022-04-13 16:13:36 +00:00
.gitignore community: update Quasar sample app 2022-04-13 16:13:36 +00:00
.postcssrc.js community: update Quasar sample app 2022-04-13 16:13:36 +00:00
apollo.config.js community: update Quasar sample app 2022-04-13 16:13:36 +00:00
babel.config.js community: update Quasar sample app 2022-04-13 16:13:36 +00:00
jsconfig.json community: update Quasar sample app 2022-04-13 16:13:36 +00:00
package.json community: update Quasar sample app 2022-04-13 16:13:36 +00:00
quasar.config.js community: update Quasar sample app 2022-04-13 16:13:36 +00:00
quasar.extensions.json community: update Quasar sample app 2022-04-13 16:13:36 +00:00
README.md community: update Quasar sample app 2022-04-13 16:13:36 +00:00
yarn.lock community: update Quasar sample app 2022-04-13 16:13:36 +00:00

quasar-framework-vue-graphql

A boilerplate to get started with Quasar Framework, Hasura GraphQL Engine as a CMS and Postgres as a database using the quasar-cli and vue-apollo module.

Edit quasar-framework-vue-graphql

Tutorial

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

    Deploy to Hasura Cloud

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

  • Create the author table:

    Open Hasura console: visit https://quasar-graphql.hasura.app on 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 the 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/quasar-framework-vue-graphql
    
  • Install node modules:

    yarn install
    
  • Open src/apollo/index.js and configure Hasura's GraphQL Endpoint as follows:

[...]

    link: createHttpLink({
        uri:
          process.env.GRAPHQL_URI ||
          // Change to your graphql endpoint.
          "<your-Hasura-app-endpoint>",
      }),

[...]

Find the above piece of code and replace <your-Hasura-app-endpoint> with the URL of your Hasura Cloud Project.

  • We have defined the GraphQL query for fetching author list in src/layouts/MainLayout.vue.

    • GraphQL query
      const { result, loading, error } = useQuery(gql`
        query {
          author {
            id
            name
          }
        }
      `);
    
    • In pages/Articles.vue, we have defined a GraphQL query for articles:

       <script>
      import { watch } from "vue";
      import { useQuery, useResult } from "@vue/apollo-composable";
      import { useRoute } from "vue-router";
      import gql from "graphql-tag";
      
      export default {
        name: "PageName",
      
        setup() {
          const route = useRoute();
      
          const { result, loading, error, refetch } = useQuery(
            gql`
              query articleQuery($authorId: Int!) {
                article(where: { author_id: { _eq: $authorId } }) {
                  id
                  title
                  content
                }
              }
            `,
            {
              authorId: route.params.authorId,
            }
          );
      
          const articles = useResult(result, null, (data) => data.article);
      
          watch(
            () => route.params.authorId,
            async (newId) => {
              refetch({ authorId: newId });
            }
          );
      
          return {
            articles,
          };
        },
      };
      </script>
      
  • Run the app:

    quasar dev
    
  • Test the app Visit http://localhost:8080 to view the app

For a detailed explanation on how things work, check out the Quasar Framework documentation.