Open hi2u opened 5 years ago
I'm getting some thumbs ups on my initial post above, so seems I'm not alone with these issues.
For anyone else coming here with similar issues, can you please post some details so we can help narrow this down?
@murillio4 @hhsl @edward-simpson @alukos
e.g:
<ApolloQuery>
tags working for you?this.$apollo
like I've shown above, which properties contain the expected stuff? And which are undefined?npm list vue vue-apollo
I'm currently on:
I was struggeling with the same problem for some time, but found the solution here: https://github.com/vuejs/vue-class-component#adding-custom-hooks
For example just put the following into a hooks.ts, followed by importing this new file in your main.ts:
import Component from 'vue-class-component'
// Register the router hooks with their names
Component.registerHooks([
'apollo'
])
Afterwards I was finally able to use the apollo getter in my components.
When this is really helping you as well, i think updating the documentation of vue-apollo with a typescript section, that hints to the custom hooks section of vue-class-component, might help.
I want to say that I had the same problem, with the following setup :
nuxt-ts / vue 2.6.6 / "@nuxtjs/apollo": "^4.0.0-rc4" -> Vue-Apollo 3.0.0-beta.28
the solution of @hhsl worked, I've created a plugin with
import {Component} from "~/node_modules/nuxt-property-decorator";
export default () => {
Component.registerHooks([
'apollo'
])
}
then imported in : nuxt.config.ts
definitely we need a better typerscript documentation, I'm pretty new to vue but also I'm not js/ts expert and an "easy to run" configuration/ guide is really far away.. I find myself always lost not knowing if each problem that show up is a bug , a misconfiguration ( also because the ts interfaces of apollo-module which then load vue-apollo ) or an incompatiblity between all those layers and maybe even with the additional interface layer of typescript which isn't documented, I've had to setup a frankenstein of code found around in guides/ tutorial/other sources, to have nuxt + apollo working with typescript,
my 2cents are that typescript native in all those libraries would also help managing so many moving parts..
errata corrige: the plugin works only for ".vue" components added in "components" dir but doesn't work in ".vue" pages I have in "pages" directory, for those I have had to add
Component.registerHooks([
'apollo'
])
in each page..
same mistake
I was struggeling with the same problem for some time, but found the solution here: https://github.com/vuejs/vue-class-component#adding-custom-hooks
For example just put the following into a hooks.ts, followed by importing this new file in your main.ts:
import Component from 'vue-class-component' // Register the router hooks with their names Component.registerHooks([ 'apollo' ])
Afterwards I was finally able to use the apollo getter in my components.
When this is really helping you as well, i think updating the documentation of vue-apollo with a typescript section, that hints to the custom hooks section of vue-class-component, might help.
Help me so much!!! I had the same problem and struggled for a whole day long and gave up back to JS, today I've found this, really helps a lot, thanks
I'm not sure if I just don't understand the documentation, of if this is a bug (I've seen a few similar bug reports). But I've tried creating multiple new projects with various versions of vue/vue-apollo (both with and without nuxt 1 and 2) since earlier last year, and I can never (or rarely) seem to get the basic simple queries from docs to work, i.e.
If I use
<ApolloQuery>
tags - it works fine.Note that I'm using TypeScript. As far I can tell from some example projects,
get apollo() {... }
is the right way to define the queries. However this methodget apollo()
is never executed automatically... from what I understand of the docs, these queries are executed as soon as you load the page?My code:
Seeing it works fine and sends the query when I uncomment the
<ApolloQuery>
tags - I'm making the assumption that my global config is correct, but maybe there's some missing piece that I need to add there in order for vue-apollo to read the queries fromget apollo() {...}
and have them available inthis.$apollo.queries
?Here's my main.ts
Here's my vue-apollo.js
For the new project I created that I'm trying to get it working on right now, I've done the most "mainstream/recommended" regular way of creating that project that I can find right now...
vue add apollo
- this gives me version 3.0.0-beta.28 of vue-aplloIf I look at
Object.keys(this.$apollo)
in the template, I can see that it does exist, and the expected object keys exist:[ "_apolloSubscriptions", "_watchers", "vm", "queries", "subscriptions", "client", "loadingKey", "error" ]
The biggest clues are that:
typeof this.$apollo.client
is undefinedtypeof this.$apollo.queries
is an object (but it's empty)I guess
client
being empty is the biggest sign? But why do the<ApolloQuery>
tags work in that case?What am I missing? Is there something else I need to do to "init"
this.$apollo.config
andthis.$apollo.queries
and have the query executed?