Skip to content

Commit

Permalink
♻️ renamed all customer reference to the API to customer-account
Browse files Browse the repository at this point in the history
  • Loading branch information
michenly committed Jan 3, 2024
1 parent 0484459 commit b20a2a9
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 50 deletions.
7 changes: 7 additions & 0 deletions .changeset/chilly-moons-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@shopify/hydrogen-codegen': patch
'@shopify/hydrogen-react': patch
'@shopify/hydrogen': patch
---

♻️ renamed all customer reference to the API to customer-account
8 changes: 4 additions & 4 deletions packages/hydrogen-codegen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ export default {
documents: [
'./*.{ts,tsx,js,jsx}',
'./app/**/*.{ts,tsx,js,jsx}',
'!./app/graphql/customer/*.{ts,tsx,js,jsx}',
'!./app/graphql/customer-account/*.{ts,tsx,js,jsx}',
'!./app/graphql/my-cms/*.{ts,tsx,js,jsx}',
],
},
'customerapi.generated.d.ts': {
'customeraccountapi.generated.d.ts': {
preset,
schema: getSchema('customer'),
documents: ['./app/graphql/customer/*.{ts,tsx,js,jsx}'],
schema: getSchema('customer-account'),
documents: ['./app/graphql/customer-account/*.{ts,tsx,js,jsx}'],
},
'mycms.generated.d.ts': {
preset,
Expand Down
8 changes: 5 additions & 3 deletions packages/hydrogen-codegen/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
* @param api
* @returns
*/
export const getSchema = (api = 'storefront' as 'storefront' | 'customer') => {
if (api !== 'storefront' && api !== 'customer') {
export const getSchema = (
api = 'storefront' as 'storefront' | 'customer-account',
) => {
if (api !== 'storefront' && api !== 'customer-account') {
throw new Error(
`The provided API type "${api}" is unknown. Please use "storefront" or "customer".`,
`The provided API type "${api}" is unknown. Please use "storefront" or "customer-account".`,
);
}

Expand Down
12 changes: 6 additions & 6 deletions packages/hydrogen-react/codegen.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {CodegenConfig} from '@graphql-codegen/cli';
import {
storefrontApiCustomScalars,
customerApiCustomScalars,
customerAccountApiCustomScalars,
} from './src/codegen.helpers';

const SF_API_VERSION = '2023-10';
Expand All @@ -18,7 +18,7 @@ const storefrontAPISchema: CodegenConfig['schema'] = {
};

// API Key used is specific for Hydrogen App
const customerAPISchema: CodegenConfig['schema'] = {
const customerAccountAPISchema: CodegenConfig['schema'] = {
[`https://app.myshopify.com/services/graphql/introspection/customer?api_client_api_key=159a99b8a7289a72f68603f2f4de40ac&api_version=${CA_API_VERSION}`]:
{method: 'GET'},
};
Expand Down Expand Up @@ -67,7 +67,7 @@ const config: CodegenConfig = {
],
},
'src/customer-account-api-types.d.ts': {
schema: customerAPISchema,
schema: customerAccountAPISchema,
plugins: [
{
add: {
Expand All @@ -87,13 +87,13 @@ const config: CodegenConfig = {
defaultScalarType: 'unknown',
useImplementingTypes: true,
enumsAsTypes: true,
scalars: customerApiCustomScalars,
scalars: customerAccountApiCustomScalars,
},
},
],
},
'./customer.schema.json': {
schema: customerAPISchema,
'./customer-account.schema.json': {
schema: customerAccountAPISchema,
plugins: [
{
introspection: {
Expand Down

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions packages/hydrogen-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"files": [
"dist",
"storefront.schema.json",
"customer.schema.json"
"customer-account.schema.json"
],
"type": "commonjs",
"exports": {
Expand Down Expand Up @@ -51,7 +51,8 @@
},
"./storefront-api-types": "./dist/types/storefront-api-types.d.ts",
"./storefront.schema.json": "./storefront.schema.json",
"./customer.schema.json": "./customer.schema.json",
"./customer-account.schema.json": "./customer-account.schema.json",
"./customer-account-api-types": "./dist/types/customer-account-api-types.d.ts",
"./package.json": "./package.json",
"./*": {
"node": {
Expand Down
2 changes: 1 addition & 1 deletion packages/hydrogen-react/src/codegen.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const storefrontApiCustomScalars = {
* Reference for the GraphQL types: https://shopify.dev/docs/api/customer/current/scalars/HTML
* Note: JSON is generated as 'unknown' by default.
*/
export const customerApiCustomScalars = {
export const customerAccountApiCustomScalars = {
DateTime: 'string',
Decimal: 'string',
HTML: 'string',
Expand Down
2 changes: 1 addition & 1 deletion packages/hydrogen-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export {CartLineQuantity} from './CartLineQuantity.js';
export {CartLineQuantityAdjustButton} from './CartLineQuantityAdjustButton.js';
export {CartProvider, useCart} from './CartProvider.js';
export {
customerApiCustomScalars,
customerAccountApiCustomScalars,
storefrontApiCustomScalars,
} from './codegen.helpers.js';
export {getShopifyCookies} from './cookies-utils.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/hydrogen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"./storefront-api-types": "./dist/storefront-api-types.d.ts",
"./storefront.schema.json": "./dist/storefront.schema.json",
"./customer-account-api-types": "./dist/customer-account-api-types.d.ts",
"./customer.schema.json": "./dist/customer.schema.json",
"./customer-account.schema.json": "./dist/customer-account.schema.json",
"./package.json": "./package.json"
},
"typesVersions": {
Expand Down
2 changes: 1 addition & 1 deletion packages/hydrogen/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export {
sendShopifyAnalytics,
ShopifySalesChannel,
storefrontApiCustomScalars,
customerApiCustomScalars,
customerAccountApiCustomScalars,
useLoadScript,
useMoney,
useShopifyCookies,
Expand Down
2 changes: 1 addition & 1 deletion packages/hydrogen/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default [
'\n',
);

const caSchemaFile = 'customer.schema.json';
const caSchemaFile = 'customer-account.schema.json';
const caTypeFile = 'customer-account-api-types.d.ts';

await fs.copyFile(
Expand Down

0 comments on commit b20a2a9

Please sign in to comment.