@shopify/hydrogen-codegen 0.2.2 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Hydrogen Codegen
2
2
 
3
- A codegen plugin and preset for generating TypeScript types from GraphQL queries in a `d.ts` file. It does not require any function wrapper and adds no runtime overhead (0 bytes to the bundle).
3
+ A codegen plugin and preset for generating TypeScript types from GraphQL queries in a `d.ts` file. It wraps the [`@shopify/graphql-codegen` package](https://github.com/Shopify/graphql-codegen) and adds utilities for Hydrogen. It does not require any function wrapper and adds no runtime overhead (0 bytes to the bundle).
4
4
 
5
5
  ```ts
6
6
  const {shop} = await client.query(`#graphql
@@ -16,7 +16,7 @@ The GraphQL client must use TypeScript interfaces that are extended in the gener
16
16
 
17
17
  ## Usage
18
18
 
19
- When using Hydrogen CLI, this package is already included and configured for you to generate types for the Shopify Storefront API. However, if you want to use it standalone with the GraphQL CLI or just want to add other APIs to Hydrogen, you can use the following example configuration:
19
+ When using Hydrogen CLI, this package is already configured for you to generate types for the Shopify Storefront API. However, if you want to use it standalone with the GraphQL CLI or just want to add other APIs to Hydrogen, you can use the following example configuration:
20
20
 
21
21
  ```ts
22
22
  // <root>/codegen.ts
@@ -51,3 +51,5 @@ export default {
51
51
  },
52
52
  } as CodegenConfig;
53
53
  ```
54
+
55
+ For more examples and information, refer to [@shopify/graphql-codegen](https://github.com/Shopify/graphql-codegen).
@@ -14,10 +14,6 @@ Object.defineProperty(exports, 'getSchema', {
14
14
  enumerable: true,
15
15
  get: function () { return schema_js.getSchema; }
16
16
  });
17
- Object.defineProperty(exports, 'schema', {
18
- enumerable: true,
19
- get: function () { return schema_js.schema; }
20
- });
21
17
  Object.defineProperty(exports, 'pluckConfig', {
22
18
  enumerable: true,
23
19
  get: function () { return graphqlCodegen.pluckConfig; }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,SAAQ,cAAgC;AACxC,SAAQ,QAAQ,iBAAgB;AAChC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAOK","sourcesContent":["export {preset, type PresetConfig} from './preset.js';\nexport {schema, getSchema} from './schema.js';\nexport {\n plugin,\n pluckConfig,\n processSources,\n type GenericVariables,\n type EmptyVariables,\n type ClientReturn,\n type IsOptionalVariables,\n type ClientVariables,\n type ClientVariablesInRestParams,\n} from '@shopify/graphql-codegen';\n"]}
1
+ {"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,SAAQ,cAAgC;AACxC,SAAQ,iBAAgB;AACxB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAOK","sourcesContent":["export {preset, type PresetConfig} from './preset.js';\nexport {getSchema} from './schema.js';\nexport {\n plugin,\n pluckConfig,\n processSources,\n type GenericVariables,\n type EmptyVariables,\n type ClientReturn,\n type IsOptionalVariables,\n type ClientVariables,\n type ClientVariablesInRestParams,\n} from '@shopify/graphql-codegen';\n"]}
@@ -1,22 +1,24 @@
1
1
  'use strict';
2
2
 
3
3
  //! import {createRequire} from 'module'; const require = createRequire(import.meta.url);
4
- const getSchema = (api = "storefront") => {
4
+ function getSchema(api, options) {
5
5
  if (api !== "storefront" && api !== "customer-account") {
6
6
  throw new Error(
7
7
  `The provided API type "${api}" is unknown. Please use "storefront" or "customer-account".`
8
8
  );
9
9
  }
10
- return require.resolve(`@shopify/hydrogen-react/${api}.schema.json`);
11
- };
12
- let staticSFAPISchema = "";
13
- try {
14
- staticSFAPISchema = getSchema("storefront");
15
- } catch (error) {
10
+ try {
11
+ return require.resolve(`@shopify/hydrogen/${api}.schema.json`);
12
+ } catch {
13
+ if (options?.throwIfMissing !== false) {
14
+ throw new Error(
15
+ `Could not find a schema for "${api}".
16
+ Please make sure a recent version of \`@shopify/hydrogen\` is installed.`
17
+ );
18
+ }
19
+ }
16
20
  }
17
- const schema = staticSFAPISchema;
18
21
 
19
22
  exports.getSchema = getSchema;
20
- exports.schema = schema;
21
23
  //# sourceMappingURL=out.js.map
22
24
  //# sourceMappingURL=schema.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/schema.ts"],"names":[],"mappings":"AACA;AAQO,MAAM,YAAY,CACvB,MAAM,iBACH;AACH,MAAI,QAAQ,gBAAgB,QAAQ,oBAAoB;AACtD,UAAM,IAAI;AAAA,MACR,0BAA0B,GAAG;AAAA,IAC/B;AAAA,EACF;AAEA,SAAO,QAAQ,QAAQ,2BAA2B,GAAG,cAAc;AACrE;AAEA,IAAI,oBAAoB;AAExB,IAAI;AACF,sBAAoB,UAAU,YAAY;AAC5C,SAAS,OAAO;AAIhB;AAKO,MAAM,SAAS","sourcesContent":["// This comment is used during ESM build:\n//! import {createRequire} from 'module'; const require = createRequire(import.meta.url);\n\n/**\n * Resolves a schema path for the provided API type. Only the API types currently\n * bundled in Hydrogen are allowed: \"storefront\" and \"customer\".\n * @param api\n * @returns\n */\nexport const getSchema = (\n api = 'storefront' as 'storefront' | 'customer-account',\n) => {\n if (api !== 'storefront' && api !== 'customer-account') {\n throw new Error(\n `The provided API type \"${api}\" is unknown. Please use \"storefront\" or \"customer-account\".`,\n );\n }\n\n return require.resolve(`@shopify/hydrogen-react/${api}.schema.json`);\n};\n\nlet staticSFAPISchema = '';\n\ntry {\n staticSFAPISchema = getSchema('storefront');\n} catch (error) {\n // This can happen at build time or when '@shopify/hydrogen-react' is not found.\n // Generally this shouldn't be an issue in real apps so let's ignore the error.\n // Also, this package could be used in non-Hydrogen apps.\n}\n\n/**\n * The resolved schema path for the Storefront API.\n */\nexport const schema = staticSFAPISchema;\n"]}
1
+ {"version":3,"sources":["../../src/schema.ts"],"names":[],"mappings":"AACA;AAgBO,SAAS,UAAU,KAAU,SAA4B;AAC9D,MAAI,QAAQ,gBAAgB,QAAQ,oBAAoB;AACtD,UAAM,IAAI;AAAA,MACR,0BAA0B,GAAG;AAAA,IAC/B;AAAA,EACF;AAEA,MAAI;AACF,WAAO,QAAQ,QAAQ,qBAAqB,GAAG,cAAc;AAAA,EAC/D,QAAQ;AACN,QAAI,SAAS,mBAAmB,OAAO;AACrC,YAAM,IAAI;AAAA,QACR,gCAAgC,GAAG;AAAA;AAAA,MACrC;AAAA,IACF;AAAA,EACF;AACF","sourcesContent":["// This comment is used during ESM build:\n//! import {createRequire} from 'module'; const require = createRequire(import.meta.url);\n\ntype Api = 'storefront' | 'customer-account';\ntype Options<T extends boolean> = {throwIfMissing?: T};\n\n/**\n * Resolves a schema path for the provided API type. Only the API types currently\n * bundled in Hydrogen are allowed: \"storefront\" and \"customer\".\n * @param api\n * @returns\n */\nexport function getSchema(api: Api, options?: Options<true>): string;\nexport function getSchema(\n api: Api,\n options: Options<false>,\n): string | undefined;\nexport function getSchema(api: Api, options?: Options<boolean>) {\n if (api !== 'storefront' && api !== 'customer-account') {\n throw new Error(\n `The provided API type \"${api}\" is unknown. Please use \"storefront\" or \"customer-account\".`,\n );\n }\n\n try {\n return require.resolve(`@shopify/hydrogen/${api}.schema.json`);\n } catch {\n if (options?.throwIfMissing !== false) {\n throw new Error(\n `Could not find a schema for \"${api}\".\\nPlease make sure a recent version of \\`@shopify/hydrogen\\` is installed.`,\n );\n }\n }\n}\n"]}
@@ -176,14 +176,7 @@ Useful in type utilities, such as checking if something does not occur.
176
176
 
177
177
  @example
178
178
  ```
179
- import type {IsNever} from 'type-fest';
180
-
181
- type And<A, B> =
182
- A extends true
183
- ? B extends true
184
- ? true
185
- : false
186
- : false;
179
+ import type {IsNever, And} from 'type-fest';
187
180
 
188
181
  // https://github.com/andnp/SimplyTyped/blob/master/src/types/strings.ts
189
182
  type AreStringsEqual<A extends string, B extends string> =
@@ -368,17 +361,18 @@ export type ClientVariablesInRestParams<GeneratedOperations extends CodegenOpera
368
361
  ];
369
362
  type PresetConfig$1 = Partial<PresetConfig>;
370
363
  export declare const preset: Types.OutputPreset<PresetConfig$1>;
364
+ export type Api = "storefront" | "customer-account";
365
+ export type Options<T extends boolean> = {
366
+ throwIfMissing?: T;
367
+ };
371
368
  /**
372
369
  * Resolves a schema path for the provided API type. Only the API types currently
373
370
  * bundled in Hydrogen are allowed: "storefront" and "customer".
374
371
  * @param api
375
372
  * @returns
376
373
  */
377
- export declare const getSchema: (api?: "storefront" | "customer-account") => string;
378
- /**
379
- * The resolved schema path for the Storefront API.
380
- */
381
- export declare const schema: string;
374
+ export declare function getSchema(api: Api, options?: Options<true>): string;
375
+ export declare function getSchema(api: Api, options: Options<false>): string | undefined;
382
376
 
383
377
  export {
384
378
  PresetConfig$1 as PresetConfig,
package/dist/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { preset } from './preset.js';
2
- export { getSchema, schema } from './schema.js';
2
+ export { getSchema } from './schema.js';
3
3
  export { pluckConfig, plugin, processSources } from '@shopify/graphql-codegen';
4
4
  //# sourceMappingURL=out.js.map
5
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,SAAQ,cAAgC;AACxC,SAAQ,QAAQ,iBAAgB;AAChC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAOK","sourcesContent":["export {preset, type PresetConfig} from './preset.js';\nexport {schema, getSchema} from './schema.js';\nexport {\n plugin,\n pluckConfig,\n processSources,\n type GenericVariables,\n type EmptyVariables,\n type ClientReturn,\n type IsOptionalVariables,\n type ClientVariables,\n type ClientVariablesInRestParams,\n} from '@shopify/graphql-codegen';\n"]}
1
+ {"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,SAAQ,cAAgC;AACxC,SAAQ,iBAAgB;AACxB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAOK","sourcesContent":["export {preset, type PresetConfig} from './preset.js';\nexport {getSchema} from './schema.js';\nexport {\n plugin,\n pluckConfig,\n processSources,\n type GenericVariables,\n type EmptyVariables,\n type ClientReturn,\n type IsOptionalVariables,\n type ClientVariables,\n type ClientVariablesInRestParams,\n} from '@shopify/graphql-codegen';\n"]}
@@ -1,19 +1,22 @@
1
1
  import {createRequire} from 'module'; const require = createRequire(import.meta.url);
2
- const getSchema = (api = "storefront") => {
2
+ function getSchema(api, options) {
3
3
  if (api !== "storefront" && api !== "customer-account") {
4
4
  throw new Error(
5
5
  `The provided API type "${api}" is unknown. Please use "storefront" or "customer-account".`
6
6
  );
7
7
  }
8
- return require.resolve(`@shopify/hydrogen-react/${api}.schema.json`);
9
- };
10
- let staticSFAPISchema = "";
11
- try {
12
- staticSFAPISchema = getSchema("storefront");
13
- } catch (error) {
8
+ try {
9
+ return require.resolve(`@shopify/hydrogen/${api}.schema.json`);
10
+ } catch {
11
+ if (options?.throwIfMissing !== false) {
12
+ throw new Error(
13
+ `Could not find a schema for "${api}".
14
+ Please make sure a recent version of \`@shopify/hydrogen\` is installed.`
15
+ );
16
+ }
17
+ }
14
18
  }
15
- const schema = staticSFAPISchema;
16
19
 
17
- export { getSchema, schema };
20
+ export { getSchema };
18
21
  //# sourceMappingURL=out.js.map
19
22
  //# sourceMappingURL=schema.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/schema.ts"],"names":[],"mappings":"AACA;AAQO,MAAM,YAAY,CACvB,MAAM,iBACH;AACH,MAAI,QAAQ,gBAAgB,QAAQ,oBAAoB;AACtD,UAAM,IAAI;AAAA,MACR,0BAA0B,GAAG;AAAA,IAC/B;AAAA,EACF;AAEA,SAAO,QAAQ,QAAQ,2BAA2B,GAAG,cAAc;AACrE;AAEA,IAAI,oBAAoB;AAExB,IAAI;AACF,sBAAoB,UAAU,YAAY;AAC5C,SAAS,OAAO;AAIhB;AAKO,MAAM,SAAS","sourcesContent":["// This comment is used during ESM build:\n//! import {createRequire} from 'module'; const require = createRequire(import.meta.url);\n\n/**\n * Resolves a schema path for the provided API type. Only the API types currently\n * bundled in Hydrogen are allowed: \"storefront\" and \"customer\".\n * @param api\n * @returns\n */\nexport const getSchema = (\n api = 'storefront' as 'storefront' | 'customer-account',\n) => {\n if (api !== 'storefront' && api !== 'customer-account') {\n throw new Error(\n `The provided API type \"${api}\" is unknown. Please use \"storefront\" or \"customer-account\".`,\n );\n }\n\n return require.resolve(`@shopify/hydrogen-react/${api}.schema.json`);\n};\n\nlet staticSFAPISchema = '';\n\ntry {\n staticSFAPISchema = getSchema('storefront');\n} catch (error) {\n // This can happen at build time or when '@shopify/hydrogen-react' is not found.\n // Generally this shouldn't be an issue in real apps so let's ignore the error.\n // Also, this package could be used in non-Hydrogen apps.\n}\n\n/**\n * The resolved schema path for the Storefront API.\n */\nexport const schema = staticSFAPISchema;\n"]}
1
+ {"version":3,"sources":["../../src/schema.ts"],"names":[],"mappings":"AACA;AAgBO,SAAS,UAAU,KAAU,SAA4B;AAC9D,MAAI,QAAQ,gBAAgB,QAAQ,oBAAoB;AACtD,UAAM,IAAI;AAAA,MACR,0BAA0B,GAAG;AAAA,IAC/B;AAAA,EACF;AAEA,MAAI;AACF,WAAO,QAAQ,QAAQ,qBAAqB,GAAG,cAAc;AAAA,EAC/D,QAAQ;AACN,QAAI,SAAS,mBAAmB,OAAO;AACrC,YAAM,IAAI;AAAA,QACR,gCAAgC,GAAG;AAAA;AAAA,MACrC;AAAA,IACF;AAAA,EACF;AACF","sourcesContent":["// This comment is used during ESM build:\n//! import {createRequire} from 'module'; const require = createRequire(import.meta.url);\n\ntype Api = 'storefront' | 'customer-account';\ntype Options<T extends boolean> = {throwIfMissing?: T};\n\n/**\n * Resolves a schema path for the provided API type. Only the API types currently\n * bundled in Hydrogen are allowed: \"storefront\" and \"customer\".\n * @param api\n * @returns\n */\nexport function getSchema(api: Api, options?: Options<true>): string;\nexport function getSchema(\n api: Api,\n options: Options<false>,\n): string | undefined;\nexport function getSchema(api: Api, options?: Options<boolean>) {\n if (api !== 'storefront' && api !== 'customer-account') {\n throw new Error(\n `The provided API type \"${api}\" is unknown. Please use \"storefront\" or \"customer-account\".`,\n );\n }\n\n try {\n return require.resolve(`@shopify/hydrogen/${api}.schema.json`);\n } catch {\n if (options?.throwIfMissing !== false) {\n throw new Error(\n `Could not find a schema for \"${api}\".\\nPlease make sure a recent version of \\`@shopify/hydrogen\\` is installed.`,\n );\n }\n }\n}\n"]}
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public",
5
5
  "@shopify:registry": "https://registry.npmjs.org"
6
6
  },
7
- "version": "0.2.2",
7
+ "version": "0.3.1",
8
8
  "license": "MIT",
9
9
  "type": "module",
10
10
  "main": "dist/cjs/index.cjs",
@@ -43,6 +43,6 @@
43
43
  "vitest": "^1.0.4"
44
44
  },
45
45
  "dependencies": {
46
- "@shopify/graphql-codegen": "^0.0.1"
46
+ "@shopify/graphql-codegen": "^0.0.2"
47
47
  }
48
48
  }