Skip to content

refactor: replace fetchShippingZones with supportedShippingDestinations#2370

Merged
matthewvolk merged 2 commits into
canaryfrom
supported-shipping-destinations
Jun 4, 2025
Merged

refactor: replace fetchShippingZones with supportedShippingDestinations#2370
matthewvolk merged 2 commits into
canaryfrom
supported-shipping-destinations

Conversation

@matthewvolk

@matthewvolk matthewvolk commented Jun 4, 2025

Copy link
Copy Markdown
Contributor

What/Why?

  • Added a new query to fetch supported shipping destinations directly from the GraphQL API.
  • Updated the cart page to utilize the new shipping countries retrieval method.
  • Removed the unused getShippingZones function and related code to simplify the client structure and remove dependence on BIGCOMMERCE_ACCESS_TOKEN environment variable

Testing

Tested locally after changes:

supported-shipping-zones-after.mov

Migration

  1. The return type of getShippingCountries has the same shape as the Country BigCommerce GraphQL type, so you should be able to copy the graphql query from core/app/[locale]/(default)/cart/page-data.ts into your project and replace the existing getShippingCountries method in there.
  2. Remove the argument data.geography from the getShippingCountries invocation in core/app/[locale]/(default)/cart/page.tsx
  3. Finally, you should be able to delete the file core/client/management/get-shipping-zones.ts assuming it is no longer referenced anywhere in core/
  4. If you are using the version of the client published to NPM, simply ensure you are using at least @bigcommerce/catalyst-client@0.16.0 or higher.
  5. If you are using the client in your pnpm workspace, simply remove the xAuthToken references in packages/client/src/client.ts as well as the fetchShippingZones method.
  6. Remove the reference to xAuthToken in core/client/index.ts

@changeset-bot

changeset-bot Bot commented Jun 4, 2025

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 73d5e08

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@bigcommerce/catalyst-core Minor
@bigcommerce/catalyst-client Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Jun 4, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
catalyst-canary ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 4, 2025 8:28pm
3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
catalyst ⬜️ Ignored (Inspect) Jun 4, 2025 8:28pm
catalyst-au ⬜️ Ignored (Inspect) Visit Preview Jun 4, 2025 8:28pm
catalyst-uk ⬜️ Ignored (Inspect) Visit Preview Jun 4, 2025 8:28pm

@matthewvolk
matthewvolk force-pushed the supported-shipping-destinations branch from 8d8c1dc to 5fa4b90 Compare June 4, 2025 20:18
@matthewvolk matthewvolk changed the title refactor(core): replace REST fetchShippingZones with GQL supportedShippingDestinations query refactor: replace fetchShippingZones with supportedShippingDestinations Jun 4, 2025
@matthewvolk
matthewvolk force-pushed the supported-shipping-destinations branch from 5fa4b90 to 73d5e08 Compare June 4, 2025 20:27
@matthewvolk
matthewvolk marked this pull request as ready for review June 4, 2025 20:34
@matthewvolk
matthewvolk requested a review from a team June 4, 2025 20:34
});
};

return data.site.settings?.shipping?.supportedShippingDestinations.countries ?? [];

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the right fallback (empty array)?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

export const getShippingCountries = cache(async () => {
const { data } = await client.fetch({
document: SupportedShippingDestinationsQuery,
fetchOptions: { next: { revalidate } },

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the right caching strategy? I wasn't sure if CAT influences the returned list of countries 🤔

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This look good to me IF customers don't have special shipping countries available to them (which I don't think so).

export const getShippingCountries = cache(async () => {
const { data } = await client.fetch({
document: SupportedShippingDestinationsQuery,
fetchOptions: { next: { revalidate } },

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This look good to me IF customers don't have special shipping countries available to them (which I don't think so).

});
};

return data.site.settings?.shipping?.supportedShippingDestinations.countries ?? [];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@matthewvolk
matthewvolk added this pull request to the merge queue Jun 4, 2025
Merged via the queue into canary with commit 20b8788 Jun 4, 2025
9 checks passed
@matthewvolk
matthewvolk deleted the supported-shipping-destinations branch June 4, 2025 21:46
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