Comments (6)
In my current project we're using both Vuex (with the Vuex-Pathify plugin, which has been a huge game-changer) and ApolloClient and I had a similar question.
In case anyone comes across this and needs to know how to access the ApolloClient from an external file (e.g. another .js
file), here's what I did after asking around in the Quasar Discord.
(Here's the direct link to the answer I got in Discord).
In your apollo-client-hooks.js
file (in src/plugins/quasar-app-extension-apollo
), you can export the apolloClient
object from the apolloClientAfterCreate
function.
Here's what mine looks like:
// src/plugins/quasar-app-extension-apollo/apollo-client-hooks.js
let apollo = {}
export function apolloClientBeforeCreate () {}
export function apolloClientAfterCreate ({ apolloClient }) {
apollo = apolloClient
}
export { apollo }
Now the client is accessible from wherever it needs to be called.
For example, I make GraphQL mutations in some of the actions in my Vuex store.
// store/some-store-module.js
import { apollo } from '@/quasar-app-extension-apollo/apollo-client-hooks'
const actions = {
onCreate ({ dispatch }, { myMutation, myVariables }) {
apollo.mutate({
mutation: myMutation,
variables: myVariables
})
}
}
Hopefully this helps anyone else who needs it!
from app-extension-apollo.
On which stage would you replace Vuex by ApolloClient? By design it's possible to replace store inside the store/index.js
, place there initialization of the apollo client. This kind of change is very limited to the SSR mode, as inside the store
you are not able to access to the ssrContext
, which is serious limitation for me. That's the only one point I found how you could replace vuex store by apollo client. It's not possible to change it on the next steps, for example inside the boot files.
Lets discuss of the possible solutions to the 1 way.
I've implemented second solution without any modifications in the latest quasar with boot file. If you have any problems with this implementation - just let me know. It also works with SSR mode as well. So I have two stores at the same time, but I don't use vuex as I found it's better to have one storage solution in the app, it's much easier to apollo cache, though it's still premature (not as easier as working with vuex in some cases).
from app-extension-apollo.
Closing as old.
Scott
from app-extension-apollo.
@smolinari hopefully that will be fixed as well in the newer versions.
from app-extension-apollo.
Try it out and see. The way it works now and IMHO, you should use Apollo for global state management. You'll also need to take the paradigm of the Flux pattern with Vuex and change it a bit to components that need only the data they need and changing only the data they need to change, making data a forth clear concern within components. So, nothing more about wanting some call to get data via the router. That shouldn't be necessary any more. But, let's see. We can always change and improve as we move forward. 😃
Scott
from app-extension-apollo.
Has anyone else able to use multiple clients with this client hooks?
https://apollo.vuejs.org/guide/multiple-clients.html
I managed to set up the apollo-provider-hook to return multiple clients and that works great.
However, I'm not able to set up multiple clients with the apollo-client-hooks.
from app-extension-apollo.
Related Issues (20)
- apolloClientBeforeCreate equivalent in v2? HOT 6
- Infinite loading on SSR HOT 5
- Quasar 2 + Apollo: Error: Apollo client with id default not found. Use provideApolloClient() if you are outside of a component setup HOT 9
- quasar build -m pwa not using GRAPHQL_URI HOT 3
- Extension v2 doesn't install due to @quasar/app dependency missing in quasar vite setup HOT 1
- this.$apollo returns `undefined` HOT 1
- installation breaks using vite HOT 4
- Error: Apollo client with id default not found. Use provideApolloClient() if you are outside of a component setup, in the q-dialog (modal) HOT 3
- Minor request HOT 1
- First call affter Page reload anytime gives me an undefined HOT 8
- HELP USING LIB HOT 7
- graphql-tag dependency issues HOT 2
- Apollo Client not compatible with Quasar II ? HOT 2
- Invalid Version: undefined Exception when installing HOT 2
- Error in Quasar ssr with @vue/apollo-composable HOT 6
- lient id
- @vue/apollo-composable HOT 2
- Quasar v2 ssr mode and apollo extension HOT 3
- [Quasar] boot error: SyntaxError: missing name after . operator HOT 2
- Add support for SSR
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from app-extension-apollo.