GithubHelp home page GithubHelp logo

Comments (6)

Akryum avatar Akryum commented on April 27, 2024

I forgot to change that in the doc! It is now this.$apollo.provider.defaultClient or this.$apollo.provider.clients.<key>.

from apollo.

oddmouse avatar oddmouse commented on April 27, 2024

Thanks @Akryum!

from apollo.

stlbucket avatar stlbucket commented on April 27, 2024

I've got

    "apollo-client": "^1.0.2",
...
    "vue-apollo": "^2.1.0-beta.2",

and am still getting this.$apollo is undefined...

i know my provider is there, because my query is working. my component looks like this:

<template>
  <div>
    <input type="text" v-model="name" placeholder="company name">
    <button v-on:click="saveCustomer({name: name})">Save</button>
    <p>{{ allCustomers }}</p>
  </div>
</template>

<script>
  import gql from 'graphql-tag'

  const createCustomerMutation = gql`mutation CreateCustomer($name: String!) {
  createCustomer(name: $name) {
    id,
    name
  }
}`

  const allCustomersQuery = gql`query {
    allCustomers {
      id,
      name
     }
  }`

  export default {
    data () {
      return {
        name: '',
        allCustomers: []
      }
    },
    methods: {
      saveCustomer: (companyInfo) => {
        console.log('this', this)
        console.log('this.$apollo', this.$apollo)

        this.$apollo.provider.defaultClient.mutate({
          mutation: createCustomerMutation,
          variables: companyInfo
        })
          .then(data => {
            console.log(data)
          })
          .catch(error => {
            console.log('ERROR', error)
          })
      }
    },
    apollo: {
      allCustomers: allCustomersQuery
    }
  }
</script>

from apollo.

oddmouse avatar oddmouse commented on April 27, 2024

The setup changed a bit with the new beta. Did you pass it into your root component?
https://github.com/Akryum/vue-apollo#create-a-provider

from apollo.

stlbucket avatar stlbucket commented on April 27, 2024

gah...

can't use arrow functions:

...

...
    methods: {
     ** saveCustomer (companyInfo) { **
        console.log('this', this)
        console.log('this.$apollo', this.$apollo)

        this.$apollo.provider.defaultClient.mutate({
          mutation: createCustomerMutation,
          variables: companyInfo
        })
          .then(data => {
...

all is good now

from apollo.

Akryum avatar Akryum commented on April 27, 2024

@stlbucket Using arrow functions for declaring methods is a very bad idea, since you lose the this context of the component (it's what arrow functions are for), and instead get window: this.$apollo is then equivalent to window.$apollo which fails.
That said, it's recommended to use arrow functions inside methods to keep the component this context. 😉

from apollo.

Related Issues (20)

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.