Replies: 12 comments 1 reply
-
@Akryum can you give me some point in what direction to go? |
Beta Was this translation helpful? Give feedback.
-
@rnenjoy: I guess if you want for all three queries to be run you either have to use smart queries and wait for all of them to resolve (i.e. resolveAll). Or you use the "skip()" function to wait for other queries to be finished first. EDIT: I actually mean "Promise.all", see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all |
Beta Was this translation helpful? Give feedback.
-
@jdus ok ill investigate! |
Beta Was this translation helpful? Give feedback.
-
Hey @rnenjoy, were you able to investigate any further? Currently I need two smart queries to run before the third and I'm using the skip() approach by keeping a global count. The skip() logic in the third query is checking if Is there a cleaner way to do this when using smart queries or would I have to go down the |
Beta Was this translation helpful? Give feedback.
-
@j0h that sounds clever! My problem was more that components renders without data being fetched. Switched to batch link, and then use v-if on some dependency data on a component. |
Beta Was this translation helpful? Give feedback.
-
Hello @j0h, |
Beta Was this translation helpful? Give feedback.
-
Hey @jdus, I came across this comment made by @Akryum (#407 (comment)):
I would be limited to doing the queries manually ( |
Beta Was this translation helpful? Give feedback.
-
Hi @j0h, |
Beta Was this translation helpful? Give feedback.
-
@jdus The issue I'm currently trying to solve with the skip() is that my third query has an I still need the third query to run regardless of the results from the first two queries (which could be null or have results). The conditional logic in the update function accounts for when there are null results. So I should still be able to do this without doing manual queries, maybe the skip() approach could be cleaner, instead of checking on a simple |
Beta Was this translation helpful? Give feedback.
-
Well, variables are reactive, so you could use the results of the first two queries as variables for the third query. If one of the first two results changes, the third query will be executed. Could be wasteful, but eventually you get what you want I suppose? |
Beta Was this translation helpful? Give feedback.
-
True, though this would potentially mean the third query could run multiple times if there is a delay between the first two queries. I will re-consider all the options discussed and see what works out better. Thanks for all the help @jdus. |
Beta Was this translation helpful? Give feedback.
-
We could use the For example: <template>
<div>I'm a Vue component</div>
</template>
<script>
import gql from "graphql-tag";
export default {
data: () => ({ firstAsset: null, secondAsset: null }),
apollo: {
firstAsset: {
query: gql`query { firstAsset }`,
result() {
this.init();
}
},
secondAsset: {
query: gql`query { secondAsset }`,
result() {
this.init();
}
}
},
methods: {
init() {
if (!this.firstAsset || !this.secondAsset) return;
console.log("All gql queries loaded!");
}
}
};
</script> Of course, there is others ways to use the
The |
Beta Was this translation helpful? Give feedback.
-
One of my biggest issue with vue apollo and graphql is how to delay certain actions until the initial data is loaded. What is the correct way to handle this? Usually i hide components with v-if until data exists, but there is also need for waiting for initial data inside the vue object.
For example I could do certain actions in the result() function inside the apollo object, but what if my function needs data from 2 or more queries?
Is there any simple way to trigger a method after all the initial graphql queries are loaded?
Beta Was this translation helpful? Give feedback.
All reactions