Skip to content

Commit

Permalink
add signupOnly variable to the query
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-amaral committed Apr 29, 2024
1 parent 85ddbce commit 1811513
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/early-ants-look.md
@@ -0,0 +1,5 @@
---
'@shopify/address': patch
---

Add `signupOnly` parameter to fetch supported countries for shop creation
10 changes: 8 additions & 2 deletions packages/address/src/AddressFormatter.ts
Expand Up @@ -32,13 +32,19 @@ export default class AddressFormatter {
return loadCountry(this.locale, countryCode, {includeHiddenZones});
}

async getCountries({includeHiddenZones = false} = {}): Promise<Country[]> {
async getCountries({
includeHiddenZones = false,
signupOnly = false,
} = {}): Promise<Country[]> {
const cacheKey = this.cacheKey(this.locale, includeHiddenZones);
const cachedCountries = ORDERED_COUNTRIES_CACHE.get(cacheKey);

if (cachedCountries) return cachedCountries;

const countries = await loadCountries(this.locale, {includeHiddenZones});
const countries = await loadCountries(this.locale, {
includeHiddenZones,
signupOnly,
});
ORDERED_COUNTRIES_CACHE.set(cacheKey, countries);

return countries;
Expand Down
4 changes: 2 additions & 2 deletions packages/address/src/graphqlQuery.ts
@@ -1,6 +1,6 @@
const query = `
query countries($locale: SupportedLocale!) {
countries(locale: $locale) {
query countries($locale: SupportedLocale!, $signupOnly: Boolean) {
countries(locale: $locale, signupOnly: $signupOnly) {
name
code
continent
Expand Down
8 changes: 6 additions & 2 deletions packages/address/src/loader.ts
Expand Up @@ -14,9 +14,12 @@ import query from './graphqlQuery';

export const loadCountries: (
locale: string,
options?: {includeHiddenZones?: boolean},
options?: {includeHiddenZones?: boolean; signupOnly?: boolean},
) => Promise<Country[]> = memoizeAsync(
async (locale: string, {includeHiddenZones = false} = {}) => {
async (
locale: string,
{includeHiddenZones = false, signupOnly = false} = {},
) => {
const response = await fetch(GRAPHQL_ENDPOINT, {
method: 'POST',
headers: HEADERS,
Expand All @@ -26,6 +29,7 @@ export const loadCountries: (
variables: {
locale: locale.replace(/-/, '_').toUpperCase(),
includeHiddenZones,
signupOnly,
},
}),
});
Expand Down

0 comments on commit 1811513

Please sign in to comment.