Vue + Apollo: TypeError: this.getClient(...).watchQuery is not a function

vue js
vue js tutorial
vue 3
vue cinema prices
vue cinema near me
vue app
vue kingston
vue definition

I am trying to setup a very simple query using Vue + Apollo (Postgraphile GraphQL server in the backend).

In my component I have (in the script tag):

import { CURRENT_USER_QUERY } from '../constants/graphql';

export default {
  name: 'User',
  data() {
    return {
      currentUser: undefined,
    };
  },
  apollo: {
    currentUser: CURRENT_USER_QUERY,
  },
};

In ../contants/graphql I have:

import gql from 'graphql-tag';

export const CURRENT_USER_QUERY = gql`
  query CurrentUserQuery {
    currentUser {
      id
      username
    }
  }
`;

In my Graphiql endpoint, the query above works without any problems.

However, when I run it in Vue, I get the following message on console:

[Vue warn]: Error in created hook: "TypeError: 
this.getClient(...).watchQuery is not a function"

Searched everywhere and could not find anyone with a similar error...

Any clues? Where should I start looking at? Thanks!!

watchQuery is returning an observable instead of a promise. See Apollo docs for ApolloClient.watchQuery or (assuming you're using vue-apollo) the actual code.

This means you'll want to subscribe to the watchQuery (as you'd for an observable), instead of doing a then (as you'd do for a promise) – like so:

apolloClient.watchQuery({
  query: yourQuery,
  variables: yourVariables
}).subscribe({
  next: (body) => {
    console.log('success', body)
    commit(MY_ACTION, body)
  },
  error: (error, done) => {
    console.error(error)
  }
})

Vue.js, Base Example. Here's an example of a Vue component: // Define a new component called button-counter Vue.component('button-counter', { data: function� See the latest films and live events in 2D, 3D, IMAX and IMAX 3D at Vue cinemas. Browse movie times at a cinema near you and book your tickets online today.

You must add the ApolloPrivder and ApolloClient on the WrappedApp like :

import React from 'react';
import { render } from 'react-dom';
import ApolloClient from 'apollo-boost';
import { ApolloProvider } from '@apollo/react-components';

import App from './App';

const client = new ApolloClient({
    uri: 'http://localhost:2370/graphql'
});

const WrappedApp = (
    <ApolloProvider client={client}>
        <App />
    </ApolloProvider>
);

render(WrappedApp, document.getElementById('root'));

I know this is for React but apply the same thing to the VUE.

Components Basics — Vue.js, Vue. 486402 likes � 4357 talking about this � 3370050 were here. Home of Big Screen Entertainment Contact our Customer Service team on 0345 308 4620 Pearson VUE offers innovative computer based testing solutions through secure, electronic test delivery. Pearson VUE provides licensure and certification exams for Microsoft, Cisco, CompTIA, Oracle, HP, GMAC, NCLEX, FINRA, ASCP, DANB and many more.

i am not sure why this is happening in vue. but i got same error in react. 1. Apollo queries should be wrapped in ApooloProvider to connect react(i think it should be similiar in vue also) with apollo.

A)

const client = async () => {// remove the async as it will cause trouble
    const client = new ApolloClient({
        link,
        cache,
        defaultOptions,
    });
    return client;
};

const apolloClient = client();
<ApolloProvider client={apolloClient}>
            <BrowserRouter>
                <App />
            </BrowserRouter>
</ApolloProvider>

you might be getting this error because of an issue in the apolloClient. for me it was throwing the error because my apolloClient was a fn that returns a promise(mentioned in A). so even before the promise is resolved, the useQuery hook is trying to be executed, but the ApolloProvider doesn't have the client resolved yet(which have the essential fns like WatchQuery() to handle useQuery hook, so it returns an error). i removed the async from the client then my error is fixed, since the apollo client is readily available for the provider.

Vue Cinemas, A sign in the window of a Vue cinema in Altrincham, Greater Manchester. Vue has announced it's ready to reopen some of its cinemas on 7� Schedule your computer-based certification exam with Pearson VUE and explore other helpful resources for test-takers.

Vue - 7,030 Photos - Movie Theater -, Browser devtools extension for debugging Vue.js applications. - vuejs/vue- devtools. Find out what's on at Vue and film times at the Vue cinema near you. Book tickets for the latest films online with 2D, 3D, IMAX and IMAX 3D options.

Vue announces phased reopening date for cinemas, Visual Understanding Environment. Flexible concept mapping tools for managing and integrating digital resources in support of teaching, learning and research.

vuejs/vue-devtools: ⚙ Browser devtools extension for , Pearson VUE delivers the CTT+ TK0-201 Essentials exam. The CompTIA CTT+ certification performance based TK0-202 Classroom trainer and the TK0-203 Virtual Classroom trainer exams are delivered exclusively through Ingenuiti.

Comments
  • facing the same issue, did you solve?
  • wow I do not really remember, but looking at it now after more months of experience, I'd start by fixing the code above... it should be apollo: { currentUser: {query: CURRENT_USER_QUERY }}