@quasar/quasar-app-extension-apollo
A Quasar app extension to add GraphQL support via Apollo Client and the vue-apollo plugin.
Last updated 5 months ago by smolinari .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @quasar/quasar-app-extension-apollo 
SYNC missed versions from official npm registry.

app-extension-apollo

official icon

Statements Branches Functions Lines
Statements Branches Functions Lines

This is the official Quasar App-Extension for adding GraphQL to your Quasar project.

Introductions

This app extension adds GraphQL support to your Quasar projects.

It uses Apollo Client and the Vue Apollo plugin.

Server side rendering (SSR) mode is also supported by this extension.

Installation

quasar ext add @quasar/apollo

Quasar CLI will retrieve the extension from NPM (@quasar/quasar-app-extension-apollo)

Note: Some code will be added to the html template file of your app (src/index.template.html)

Prompts

You will be prompted to enter the URI of your GraphQL endpoint. You can skip this and instead provide the URI using an environment variable when running Quasar:

GRAPHQL_URI=https://prod.example.com/graphql quasar build
GRAPHQL_URI=https://dev.example.com/graphql quasar dev

If you don't have a GraphQL endpoint yet, you can create one to experiment with at FakeQL or other similar services.

Uninstall

quasar ext remove @quasar/apollo

Note: The added code to the html template file (src/index.template.html) will be removed.

Warning Added directory src/apollo will be removed, if you need, make a backup before uninstalling the extension.

Configuration

Apollo client can be configured through src/apollo/apollo-client-config.js.

Advanced configuration

Apollo client

The extension provides two hooks, one gets called before the apollo client instantiation and the other afterwards. The hooks are apolloClientBeforeCreate and apolloClientAfterCreate, and can be modified as needed in src/apollo/apollo-client-hooks.js.

Apollo provider

The extension provides two hooks, one gets called before the apollo provider instantiation and the other afterwards. The hooks are apolloProviderBeforeCreate and apolloProviderAfterCreate, and can be modified as needed in src/apollo/apollo-provider-hooks.js.

Usage

Check the guide in Vue Apollo docs

Example usage:

src/pages/Index.vue

<template>
  <q-page>
    <!-- when the query response is not received yet, data from it is undefined,
    so before referring to it we need to use v-if -->
    <div v-if="post">GraphQL query result:<br />{{ post.title }}</div>
    <div v-else>
      loading...
    </div>
  </q-page>
</template>

<script>
  import gql from 'graphql-tag'

  export default {
    name: 'PageIndex',

    // https://apollo.vuejs.org/guide/apollo/#usage-in-vue-components
    apollo: {
      post: {
        query: gql`
          query {
            post(id: 5) {
              title
            }
          }
        `
      }
    }
  }
</script>

IMPORTANT: Needed to get vue-apollo's components to work (with Vue)

In order for the vue-apollo components to work, you must turn on a special transform so vue-loader doesn't fail on those new tags. Add the below code to the build property in your quasar.conf.js file.

  chainWebpack (chain, { isServer, isClient }) {
    chain.module.rule('vue')
      .use('vue-loader')
      .loader('vue-loader')
      .tap(options => {
        options.transpileOptions = {
          transforms: {
            dangerousTaggedTemplateString: true
          }
        }
        return options
      })
  }

Current Tags

  • 1.0.0-beta.6                                ...           latest (3 months ago)

7 Versions

  • 1.0.0-beta.6                                ...           3 months ago
  • 1.0.0-beta.5                                ...           3 months ago
  • 1.0.0-beta.4                                ...           3 months ago
  • 1.0.0-beta.3                                ...           3 months ago
  • 1.0.0-beta.2                                ...           5 months ago
  • 1.0.0-beta.2.0                                ...           5 months ago
  • 1.0.0-beta.1                                ...           7 months ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (9)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |