-
-
Notifications
You must be signed in to change notification settings - Fork 522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Vue 3.0 composition API #1011
Comments
This is really a major problem. We had to move many projects to react during the last month, because we were not able to go with vue 3. We did many poc and in general vue3 was doing already great. Just the missing graphql and some typescript problems killed the approach. |
vue-apollo v4 has been available since early December 2019, with |
True, but this doesn't support Vue 3, just Vue 2 with the composition api plugin. |
From my understanding it can be used with vue 3. Have you tested, @justinwaite? I do use it with composition api because storybook is the last thing holding me back from upgrading to vue 3. So I've not tested myself, but I believe it is compatible in the latest version. Its latest version was released with using a package which allows vue apollo 4 to be used with either vue 2 or vue 3. |
@MechJosh0 there may be multiple things at play here, but I am unable to get it working with Vue 3 + Vite. See my comment here: #1029 (comment) |
It does work with Composition API but the thing is that it only does up to composition-api@0.5.0 (see issue here). I had v4.0.0-alpha.8 and composition-api@0.5.0 working fine. However, it gives this error after upgrading to v4.0.0-alpha.10 |
From what I can tell at least |
However, I've found a couple of issues with it: #1041 #1040 With those two changes I got it working. Until they are merged or refactored by Guillaume, you can try this patch: // scripts/vue-apollo-patch.js
const fs = require('fs')
const path = require('path')
const loadTrackingPath = path.resolve(
__dirname,
'../node_modules/@vue/apollo-composable/dist/util/loadingTracking.js'
)
fs.writeFileSync(
loadTrackingPath,
fs.readFileSync(loadTrackingPath, 'utf8').replace(/\.\$root/m, '.root')
)
const useQueryPath = path.resolve(
__dirname,
'../node_modules/@vue/apollo-composable/dist/useQuery.js'
)
fs.writeFileSync(
useQueryPath,
fs
.readFileSync(useQueryPath, 'utf8')
.replace(/(^.*onServerPrefetch)/m, '$1=()=>{}; $1')
.replace(/(.* require\("vue"\);)/m, '')
.replace(/^.*(nextTick)/m, 'vue_demi_1.$1')
) In package.json: "scripts": {
"postinstall": "node scripts/vue-apollo-patch.js"
} Just make sure the paths in the script point to the right files (in case node_modules is not in the parent directory). Hope that helps! |
Thanks @frandiox |
The quoted reply fails because the onServerPrefetch property can't be resigned on a freezed object. The below snippet solves the issue: const fs = require('fs')
const path = require('path')
const loadTrackingPath = path.resolve(
__dirname,
'../node_modules/@vue/apollo-composable/dist/util/loadingTracking.js'
)
fs.rmdirSync(path.resolve(__dirname, '../node_modules/.vite_opt_cache'), {
recursive: true
})
fs.writeFileSync(
loadTrackingPath,
fs.readFileSync(loadTrackingPath, 'utf8').replace(/\.\$root/m, '.root')
)
const useQueryPath = path.resolve(
__dirname,
'../node_modules/@vue/apollo-composable/dist/useQuery.js'
)
fs.writeFileSync(
useQueryPath,
fs
.readFileSync(useQueryPath, 'utf8')
.replace(/(^.*onServerPrefetch)(\.\?\.)?/m, '$1?.')
.replace(/(.* require\("vue"\);)/m, '')
.replace(/^.*(nextTick)/m, 'vue_demi_1.$1')
) |
For me this issue got resolved by putting Vue.use(VueCompositionAPI) into an external file (the same one where I'm setting up Apollo) and then importing it in the main.{ts,js} |
Full support for Vue 3 is pending the inclusion of |
@Akryum Could you please release |
Vue 3 support for @vue/apollo-composable is now included in automatic tests on v4 branch. (More tests to come) |
Updated patch for const fs = require("fs")
const path = require("path")
fs.rmdirSync(path.resolve(__dirname, "../node_modules/.vite_opt_cache"), {
recursive: true,
})
const useQueryPath = path.resolve(
__dirname,
"../node_modules/@vue/apollo-composable/dist/useQuery.js"
)
fs.writeFileSync(
useQueryPath,
fs.readFileSync(useQueryPath, "utf8").replace(/^onServerPrefetch, /mu, "")
) |
Updated patch to fully remove vite: 1.0.0-rc4
|
This is what ended up working for me const fs = require("fs");
const path = require("path");
const loadTrackingPath = path.resolve(
__dirname,
"../node_modules/@vue/apollo-composable/dist/util/loadingTracking.js"
);
fs.rmdirSync(path.resolve(__dirname, "../node_modules/.vite_opt_cache"), {
recursive: true
});
fs.writeFileSync(
loadTrackingPath,
fs.readFileSync(loadTrackingPath, "utf8").replace(/\.\$root/m, ".root")
);
const useQueryPath = path.resolve(
__dirname,
"../node_modules/@vue/apollo-composable/dist/useQuery.js"
);
fs.writeFileSync(
useQueryPath,
fs
.readFileSync(useQueryPath, "utf8")
.replace(/\:\sonServerPrefetch\(/, ": (() => {})(")
.replace(/(.* require\("vue"\);)/m, "")
); |
it's not working for me with my version and still get this error can anyone tell me what should i do with this error
|
@seyhadot not sure, you could create a new issue. Here's a small working app you can use to try to reproduce with: https://github.com/GraphQLGuide/guide-vue/tree/repro-1116 |
I had the same thing happen to me.
|
@NagamineYusuke sorry, would you mind explaining your fix please? It isn't clear what you did to get alpha12 working. |
This little script patches it, to make it work with vite. const fs = require("fs")
const path = require("path")
fs.rmdirSync(path.resolve(__dirname, "../node_modules/.vite_opt_cache"), {
recursive: true,
})
const useQueryPath = path.resolve(
__dirname,
"../node_modules/@vue/apollo-composable/dist/useQuery.js"
)
fs.writeFileSync(
useQueryPath,
fs.readFileSync(useQueryPath, "utf8").replace(/^onServerPrefetch, /mu, "")
) |
When the fix will come? |
This one is safer. const fs = require("fs");
const path = require("path");
fs.rmdirSync(path.resolve(__dirname, "../node_modules/.vite_opt_cache"), {
recursive: true,
})
const useQueryPath = path.resolve(
__dirname,
"../node_modules/@vue/apollo-composable/dist/useQuery.js"
);
fs.writeFileSync(
useQueryPath,
fs
.readFileSync(useQueryPath, "utf8")
.replace(/\/\/ @ts-expect-error.*[\r\n]+(onServerPrefetch),/m, "// $1,\n")
.replace(/export function/m, "\n\rimport * as VueDemi from 'vue-demi';\nconst onServerPrefetch = VueDemi.onServerPrefetch;\n\rexport function")
); |
I have this error.
How can I solve this problem? |
I solved this with adding the following code to
Hope this helps. |
This should be unnecessary with alpha.14 |
I am using vue 3.0 and "@vue/apollo-composable": "^4.0.0-alpha.12" |
According to the Vue roadmap, the API for v3.0 is now frozen.
The text was updated successfully, but these errors were encountered: