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

feat(use-query): Enable to refetch on channel change #2869

Conversation

gdarchen
Copy link
Contributor

@gdarchen gdarchen commented May 28, 2024

Description

In the DataService, there exists a method to refetch whenever the channel changes.

However, it was not yet possible to use this refetchOnChannelChange method in React custom Admin UI pages when using the useQuery and useLazyQuery hooks.

In this PR, I added an option on those hooks, so that we can refetch the queries whenever the channel changes.

To test it:

  1. Compile the dev-server with the custom-admin-ui extension
  2. In the ReactUi.tsx file, add the following:
     const GET_CHANNELS = gql`
     	query channels {
     	  channels {
     	    items {
     	      id
     	      code
     	      token
     	    }
     	  }
     	}
     `
     
     const channelsResponse = useQuery<any>(GET_CHANNELS, undefined, { refetchOnChannelChange: true })
  3. Check the network: whenever the channel changes, the query is run again with the new channel token passed in the headers

Breaking changes

No breaking change, just an option added.

Screenshots

vendure.mp4

Checklist

📌 Always:

  • I have set a clear title
  • My PR is small and contains a single feature
  • I have checked my own PR

👍 Most of the time:

  • I have added or updated test cases
  • I have updated the README if needed

Copy link

netlify bot commented May 28, 2024

Deploy Preview for effervescent-donut-4977b2 failed.

Name Link
🔨 Latest commit b9ae3f3
🔍 Latest deploy log https://app.netlify.com/sites/effervescent-donut-4977b2/deploys/6655a91176e36d0008e4172c

@michaelbromley
Copy link
Member

Hi @gdarchen! Thanks, this is a nice addition. Could you make the PR against the minor branch though since it's a new feature?

@gdarchen gdarchen changed the base branch from master to minor May 31, 2024 14:53
@gdarchen
Copy link
Contributor Author

Hi @gdarchen! Thanks, this is a nice addition. Could you make the PR against the minor branch though since it's a new feature?

Hi @michaelbromley!
Thanks for the review, I changed the base branch ✅

@gdarchen
Copy link
Contributor Author

Hi @martijnvdbrug,
I don't get why you pushed b54c210 on this PR? 🤔

@michaelbromley
Copy link
Member

I think the commit from Martijn probably got added automatically when you changed branch. What you could try is to locally rebase the commit to minor and then force push? Not sure. If all else fails just close this PR and open a new one linking to this :)

@gdarchen gdarchen force-pushed the feat/emit-event-on-local-storage-change branch from b9ae3f3 to e4dcff7 Compare June 3, 2024 07:28
@gdarchen gdarchen force-pushed the feat/emit-event-on-local-storage-change branch from e4dcff7 to 0ce9796 Compare June 3, 2024 07:29
@gdarchen
Copy link
Contributor Author

gdarchen commented Jun 3, 2024

Hi @michaelbromley
I just reset my branch on upstream/minor and cherry-picked my commit, it seems fine now 👍

@michaelbromley michaelbromley merged commit 3d516ea into vendure-ecommerce:minor Jun 3, 2024
10 checks passed
@michaelbromley
Copy link
Member

Thank you!

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

Successfully merging this pull request may close these issues.

2 participants