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
Server Side Queries #14
Comments
apollo-client needs import fetch from 'fetch'
global.fetch = fetch See #13 |
More could be done to improve compatibility with the server, if you have any idea please don't hesitate to share them. |
I already am using I have something sort of kind of working now using the following code, but it's limited to queries that don't have any dynamic variables (since we don't have a
Then we inline This works for queries that only depend on the route and store and other top level app information. If there is any way to perform asynchronous operations inside a lifecycle hook or otherwise defer component renderering from a plugin you could potentially check If I'm overthinking this and you have a working ssr example please let me know. |
Ran into the same problem. Isn't the easiest solution to not load any data from graphql on the server and make sure inside the library that both server and client render the same html? If the |
Unfortunately, that's an unacceptable solution for our app. If that's the best we can do I'll probably have to recommend we use react instead. For now I'm using my solution above where I manually run what queries I can without access to the live instances, we'll see how far that gets me :/ |
Okay, yeah makes sense. I'm not sure how much of this logic should be part of this library, because server side vuejs still requires quite a lot of boilerplate code and it doesn't seem like there's an "official way" to do things (see hackernews vue clone). Maybe it makes sense to kickstart a discussion on apollo-client? Unless there's already a solution on apollo level that I don't know about. |
I'm exploring solutions for vue-apollo that would make server-side querying easy. If you have suggestions, please feel free to share! |
wouldn't it be cool to have something like: export default {
...
preFetch(store) {
return this.$apollo.initialize();
}
...
}; Which would return a promise that resolves after a Btw ignore the wording, should be called something more descriptive (instead of |
I'm basically doing that manually atm, and it mostly works, as long as my queries only care about route parameters :/ |
Maybe I could fake |
@TheMallen can you show us the code where you use |
What do you think of this? export function prefetch(router) {
return Promise.all(router.getMatchedComponents().map(component => component.$apollo.promise.allQueries))
} With |
Another proposition (for instance-less use-case): export default {
apollo: {
someData: {
query: ...,
variables () {
...
},
prefetchVariables: context => {
...
},
}
}
}
// vue-apollo API
export function prefetchQueries (componentDefinition, context) {
return Promise.all(...)
}
export function prefetchAll (router, context) {
return Promise.all(router.getMatchedComponents().map(component => prefetchQueries(component, context)))
} |
Looks cool. Would apollo take over the serialization process or how would that work? As in how would we be able to instantiate the vue apollo instance with data on the client? |
It may not do that in the first iteration, but that would be nice to have indeed. 😄 |
I think having that function would already greatly simplify the server side pre fetching. Any way of helping you with this? |
We can start playing with SSR! v2.1.0-beta.1 |
Here are some brainstorming about how it may look like (I didn't test it yet, but if someone has time, he can 😄). |
I think we will need to walk the possible tree of components like what react-apollo does. |
I'll definitely check out the SSR this weekend. |
Mostly final SSR API has landed in |
@Akryum great news. Was looking for the beta.8 release, did you publish it already? The improvements seem to make a working example now for |
@Akryum just found the npm release, I've been confused because this repo does not show a release note for beta.8. |
The Struggle
Hello, I'm trying to get an isomorphic
vue
vue-router
vue-apollo
application running and I've run into some issue.vue-apollo
does not run on the server by default. To try to get around this I first tried to manually run queries before rendering the application on the server by pullinf fromrouter.getMatchedComponents
. This lead me to my next issue.vue-router
'srouter.getMatchedComponents
yields only the component definitions, not instances. This means we cannot run the queries in the context of the running state of the application. This lead me to try to run the queries from within component lifecycle hooks.Unfortunately component lifecycle hooks cannot be asynchronous. As a result the queries are run after the application has already been rendered and sent down the wire.
I'm more or less out of ideas now, and I'll probably just fall back to using apollo client directly with vuex, which is pretty terrible.
TLDR
It seems like this plugin has no way to operate in conjunction with server side rendering. I'd love to be wrong however. Do you have any ideas how it could be done?
The text was updated successfully, but these errors were encountered: