# vuex-apollo

> Vuex Setup with Apollo Integration

Latest version **2.1.1** (published 2018-07-07) · ISC license · 0 weekly downloads

## Install

```sh
npm install vuex-apollo
pnpm add vuex-apollo
yarn add vuex-apollo
bun add vuex-apollo
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; large bundle.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.1 |
| Published | 2018-07-07 |
| First published | 2018-07-06 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 15.8 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 32 |
| Author | Alan J. Fitzpatrick |
| Maintainers | staratarms |
| Keywords | vue, vuex, apollo, graphql, vuex-apollo, vuex-plugin, vuex apollo, vuexApollo, vue-apollo, vueApollo |

## Links

- npm: https://www.npmjs.com/package/vuex-apollo
- Repository: https://github.com/alajfit/vuex-apollo
- Homepage: https://github.com/alajfit/vuex-apollo#readme
- Issues: https://github.com/alajfit/vuex-apollo/issues
- npm.io page: https://npm.io/package/vuex-apollo

## Dependencies (4)

- [vuex](https://npm.io/package/vuex.md) ^3.0.1
- [graphql](https://npm.io/package/graphql.md) ^0.13.2
- [graphql-tag](https://npm.io/package/graphql-tag.md) ^2.9.2
- [apollo-boost](https://npm.io/package/apollo-boost.md) ^0.1.10

## Alternatives

- [apollo-link-http-common](https://npm.io/package/apollo-link-http-common.md) — 879.0K weekly downloads
- [react-relay](https://npm.io/package/react-relay.md) — 336.8K weekly downloads
- [relay-test-utils](https://npm.io/package/relay-test-utils.md) — 181.6K weekly downloads
- [@vendure/core](https://npm.io/package/@vendure/core.md) — 14.8K weekly downloads
- [@pnpm/deps.graph-sequencer](https://npm.io/package/@pnpm/deps.graph-sequencer.md) — 13.4K weekly downloads

## Recent versions

- 2.1.1 (latest) — 2018-07-07
- 2.1.0 — 2018-07-07
- 2.0.2 — 2018-07-07
- 2.0.1 — 2018-07-07
- 2.0.0 — 2018-07-07
- 1.2.0 — 2018-07-07
- 1.0.0 — 2018-07-06

## README

# Vuex Apollo (Bringing the best of both worlds together)
> First stable release is out

[![npm](https://img.shields.io/npm/v/vuex-apollo.svg) ![npm](https://img.shields.io/npm/dm/vuex-apollo.svg)](https://www.npmjs.com/package/vuex-apollo)

<p align="center">
  <img width="200" height="200" src="./docs/assets/vuex-apollo.png" />
</p>
<p align="center">
  <a href="https://travis-ci.org/alajfit/vuex-apollo">
    <img src="https://travis-ci.org/alajfit/vuex-apollo.svg?branch=master" alt="Build Status" />
  </a>
</p>

## Install

```
npm install vuex-apollo --save
```

## Import
- vuexApollo can be imported as a normal vue plugin
- You can pass the plugin 2 options
  - The *uri* of the graphql server
  - An Array of objects with the *module name* _(name)_ and the *raw module* _(module)_

```js
import Vue from 'vue'
import vuexApollo from 'vuex-apollo'
import user from './modules/user'
import App from './App.vue'

Vue.use(vuexApollo, {
    uri: 'https://fakerql.com/graphql',
    modules: [{
      name: 'user',
      store: user
    }]
})

new Vue({
  el: '#app',
  render: h => h(App)
})

```

## Usage
- Along with the export for vuexApollo you can also get some of the Vuex map functions from this package
- So you can do the following within your application when bootstrapped with vuexApollo

```html
<template>
    <div id="app">
        <h1>Testing Vuex Apollo</h1>
        <div class="user">
            <img
                class="user-avatar" 
                :src="avatar" />
            <h3>Name: {{ name }}</h3>
            <h3>Email: {{ email }}</h3>
        </div>
        <p>
            <button @click="newUser">Get New User</button>
        </p>
    </div>
</template>

<script>
    import { mapActions, mapGetters, mapState } from 'vuex-apollo'

    export default {
        name: 'app',
        computed: {
            ...mapState('user', {
                avatar: 'avatar',
                email: 'email'
            }),
            ...mapGetters({
                name: 'user/fullName'
            })
        },
        methods: {
            ...mapActions({
                newUser: 'user/GET_USER_INFO'
            })
        }
    }
</script>
```

## Building a Module
- Modules are built in a standard fashion to how you would nomally scaffold a module
- The Action is now passed two new properties in the context
  - apollo (This is an instance of Apollo Client)
  - gql (This )
- You can also init a module from actions by declaring an INIT action

[You Can See An Example Module Here](https://github.com/alajfit/vuex-apollo/tree/master/tests/demo/app/modules/user)

> This is an Example of actions using the INIT self called action and destructing the apollo and gql properties
```js
import * as types from './types'

export const actions = {
    INIT ({ commit }) {
        console.log(`I'm called on init`)
    },
    [types.GET_USER_INFO] ({ commit, apollo, gql }) {
        apollo.query({
            query: gql`
            query UserInfo {
                User(id:21) {
                    id
                    firstName
                    lastName
                    email
                    avatar 
                }
            }
            `
        }).then(response => {
            commit(types.GET_USER_INFO, response.data.User)
        })
    }
}
```

## Features
- Vuex
- Apollo (GraphQL)
- Seamless Integration

## ToDo
- Add Error Logging through an error link
- Look at making the bundle smaller
- Add Unit Testing
- Add E2E Testing
- Integrate Vuex with apollo-link-state
- When major Vuex changes affect this plugin adapt the plugin - [Vue Roadmap](https://github.com/vuejs/roadmap#vuex-4x)

## Feedback
- Please raise any issues you find
- This is still a work in progress and I'll update as and when I have free time

<p>
  <a href="https://www.patreon.com/staratarms" target="_blank">
    <h3>If I've helped you out in any way why not: :blush:</h3>
    <img src="./docs/assets/patreon.png" alt="Become a Patreon">
  </a>
</p>


---

## License

[MIT](http://opensource.org/licenses/MIT)

---
_Source: https://npm.io/package/vuex-apollo · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
