Skip to content
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

Best way to re-execute query #14

Closed
stephanedemotte opened this issue Jan 30, 2020 · 3 comments
Closed

Best way to re-execute query #14

stephanedemotte opened this issue Jan 30, 2020 · 3 comments

Comments

@stephanedemotte
Copy link

Hello, thanks for your great job :)

Small question, i want to re-excute a query when a variable change,

   const lang = _.capitalize(root.lang)

    const { data } = useQuery({
      query: `
      {
        pageBy(pageId: 30) {
          title
          slug
          acf_pages {
            metaDescription: meta${lang}Description
            metaTitle: meta${lang}Title,
            template: adminComponent
          }
        }
      }
      `,
    })

In this case lang change, what the best way to re-excute query ? watch lang and manually fetch the data ?

Thanks

@danrocha
Copy link

danrocha commented Feb 4, 2020

@stephanedemotte
Copy link
Author

I'm not using the "official" graphql variable.
It's juste string concatenation.
Sometime i want to call { query: '{ titi }' } and sometimes { query: '{ toto }' }

I've read your doc, but without success :)

Thanks !

@logaretm
Copy link
Owner

logaretm commented Feb 4, 2020

You could introduce the lang as a query variable, but I don't think that's viable. To me language change involves more than just fetching the data, your entire UI would probably change as well.

You could create a reactive query:

const query = computed(() => {
  if (something) {
    return `{ titi }`
  }

return `{ toto }`
});

const { data } = useQuery({
  query
});

and whenever the query will change the useQuery will automatically execute the query. Note that all the features are available in 1.x alpha releases which is only for Vue 3.x.

@logaretm logaretm closed this as completed Feb 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants