-
-
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
apollo-composable "enabled/disable" query, not working #1422
Comments
Was running into this issue in a branch where I am upgrading from the following...
to...
Noticed something odd along with the query firing when it was disabled; the variables were blank on the outgoing query. After reading through the code one more time I realized my query's variable definitions were not properly set. Fixing the variable definitions in the query, to match the variables passed into Guess what I'm saying here is, the latest version of apollo, graphql, vue, and this package work fine. I'm curious if additional logic should be added in to check for a mismatch with variables and definitions. I would not have come to this thread if the query didn't fire while it was disabled. @tcastelly - Was your issue solved? |
Bellow my code, the query is still trigger with undefined value. Maybe because the same variable is also used in the const selectedPeriod = ref<string>();
const { result: seriesResult, loading: isSeriesPending } = useQuery<Series>(
REPORT,
() => ({
period: selectedPeriod.value,
}),
() => ({
fetchPolicy: 'no-cache',
enabled: !!selectedPeriod.value,
}),
);
const unwatch = watch(
() => periodOptions.value.length, // `periodOptions` come from an other graph query
() => {
if (periodOptions.value.length && !selectedPeriod.value) {
selectedPeriod.value = periodOptions.value[0].id;
unwatch();
}
},
); The most wired behavior, if I never update the const unwatch = watch(
() => periodOptions.value.length,
() => {
if (periodOptions.value.length && !selectedPeriod.value) {
// selectedPeriod.value = periodOptions.value[0].id;
unwatch();
}
},
); the query is never trigger ... So I tried with a setTimeout like this: const unwatch = watch(
() => periodOptions.value.length,
() => {
if (periodOptions.value.length && !selectedPeriod.value) {
setTimeout(() => {
selectedPeriod.value = periodOptions.value[0].id;
}, 0);
unwatch();
}
},
); And it works. I can't explain how it can works like this, I'm lost. |
Hello! I'm not able to reproduce the issue on my end, could anyone try again with the latest versions of the libraries (vue, apollo, vue-apollo, etc.). 🙏 |
Hello @Akryum I created a repo to reproduce the issue: There is a workaround branch. |
I was on Related #1243 (comment) |
Hello, I hit the same problem,
# Detect the platform
# /!\ If you're in MacOs, install gsed
case $(uname | tr '[:upper:]' '[:lower:]') in
darwin*)
alias sed=gsed
;;
esac
# https://github.com/vuejs/apollo/issues/1422
FILE="node_modules/@vue/apollo-composable/dist/index.esm.js"
sed -i '542 c nextTick(() => start());' $FILE
sed -i '796 c nextTick(() => start());' $FILE
|
@tcastelly, I also had this problem and figured it out. Note that Building on your example, this is wrong:
This is what it should be:
|
Hi, You are right about how to use the const { result } = useQuery<Series>(
REPORT,
() => ({
period: selectedPeriod.value,
}),
() => ({
fetchPolicy: 'no-cache',
enabled: !!selectedPeriod.value,
}),
); But in the initial issue, it was not possible to use this |
@tcastelly, thank you. To clarify, either of these work:
or
but this does NOT work:
|
Let me clarify
About |
We agree 🙂. Thank you. |
Describe the bug
I would want to launch a query using the "enabled" property in the
useQuery
By default the result of
!!periodSelected.value
isfalse
. But the query is launched.If I try to use a static
false
It works.
Versions
vue: 3.2.41
vue-apollo: 3.1.0
@apollo/client: 3.7.1
Additional context
I've tried with computed options:
Not working.
The text was updated successfully, but these errors were encountered: