Git Product home page Git Product logo

app-extension-apollo's Introduction

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
      })
  }

app-extension-apollo's People

Contributors

codenamezjames avatar dependabot[bot] avatar ejez avatar nothingismagick avatar rstoenescu avatar smolinari avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.