npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vuex-apollo

v2.1.1

Published

Vuex Setup with Apollo Integration

Downloads

86

Readme

Vuex Apollo (Bringing the best of both worlds together)

First stable release is out

npm npm

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

This is an Example of actions using the INIT self called action and destructing the apollo and gql properties

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

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

License

MIT