-
Notifications
You must be signed in to change notification settings - Fork 197
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
useAsyncQuery can't refresh #496
Comments
Looks like the issue might be related to the token. After many tries I gave a go to nuxt-graphql-client instead. While testing I made the api public and everything immediately worked. This time, however, I found a Not sure if apollo has a similar thing, I expect it does, though I will probably stick to |
In Addition, The result from useAsyncQuery is unable to update automatically with Apollo Cache. I had to write a custom useAsyncQuery. It is still working for me. type Options<TResult, TVariables> = OptionsParameter<TResult, TVariables> & {
key?: string
}
export const useAsyncQuery = async <TResult = any, TVariables extends OperationVariables = OperationVariables> (document: DocumentParameter<TResult, TVariables>, variables?: VariablesParameter<TVariables>, options?: Options<TResult, TVariables>) => {
const { client } = useApolloClient()
const fn = () => client.query<TResult, TVariables>({
query: document as DocumentNode,
variables: variables as TVariables
}).then((res) => res.data)
const key = options?.key || hash({ query: print(document as DocumentNode), variables })
await useAsyncData(key, fn)
return useQuery(document, variables as TVariables)
} Basically, I call useAsyncData to write the result to Apollo Cache and return useQuery instead. |
Also experiencing this issue, I'm kinda blown away this isn't tripping everyone up. Is is just no on is using this package? What are we missing. |
Same here, this is really annoying, in nuxt2 I was refreshing my queries via EventBus after closing a modal, worked perfectly fine. With this version (5.0.0-alpha.10 and before) I can call the refresh function but no refresh is happening. |
We ended up doing a bunch of extra work to ensure we're only calling |
UPDATE: @ssyberg : I just found out that reactive queries in options api are working like in nuxt2, you just have to place the apollo object after the setup routine, this is awesome !!! :) With that you can easily do a export default defineNuxtComponent({
name: "MyTest",
async setup(props) {
.....
},
apollo: {
setting: {
query: gql`
query ($name: String!) {
setting(where: { name: $name }) {
show
}
}
`,
variables() {
return {
name: "showNameOfSomeone",
};
},
update: (data) => data.setting,
error() {
if (process.client) {
this.$nextTick(() => {
this.$buefy.toast.open({
message: this.$t("loading_error"),
type: "is-danger",
});
});
}
},
},
currentSchemas: {
query: gql`
.......
},
data() {
return {
...... |
@ssyberg Same issue here |
Understanding the Issue with "Refresh"Discovery ProcessWhile looking into the code and experimenting, I discovered something: Conclusion:
|
@timyourivh thanks for approach, it works! But cache is very important for optimization. Is it possible to fix? |
Same issue |
Hello there,
I tried hard to use the useAsyncQuery composable and i also gave a look to the nuxt-apollo module's core... This is the only way I found to refresh a search graphql request based off the query params. |
Environment
I came across different issues opened about what it looks to be the same problem.
I have not been able to refresh the data of useAsyncQuery in any way.
Describe the bug
useAsyncQuery only seems to work on page refresh / landing.
Expected behaviour
refresh() or watch makes no different (not sure they are even needed on route change).
Reproduction
No response
Additional context
Nuxt 3 documentation does not mention useAsyncQuery: is this actually usable in Nuxt 3?
Logs
No response
The text was updated successfully, but these errors were encountered: