Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upSupport 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 [email protected] (see issue here). I had v4.0.0-alpha.8 and [email protected] 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
|
According to the Vue roadmap, the API for v3.0 is now frozen.