@shopify/hydrogen-codegen 0.2.2 → 0.3.0
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 +4 -2
- package/dist/cjs/index.cjs +0 -4
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/schema.cjs +11 -9
- package/dist/cjs/schema.cjs.map +1 -1
- package/dist/esm/index.d.ts +6 -5
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/schema.js +12 -9
- package/dist/esm/schema.js.map +1 -1
- package/package.json +1 -1
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
|
|
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).
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -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; }
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,SAAQ,cAAgC;AACxC,SAAQ,
|
|
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"]}
|
package/dist/cjs/schema.cjs
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
//! import {createRequire} from 'module'; const require = createRequire(import.meta.url);
|
|
4
|
-
|
|
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
|
-
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
try {
|
|
11
|
+
return require.resolve(`@shopify/hydrogen-react/${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
|
package/dist/cjs/schema.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/schema.ts"],"names":[],"mappings":"AACA;
|
|
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,2BAA2B,GAAG,cAAc;AAAA,EACrE,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-react/${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/dist/esm/index.d.ts
CHANGED
|
@@ -368,17 +368,18 @@ export type ClientVariablesInRestParams<GeneratedOperations extends CodegenOpera
|
|
|
368
368
|
];
|
|
369
369
|
type PresetConfig$1 = Partial<PresetConfig>;
|
|
370
370
|
export declare const preset: Types.OutputPreset<PresetConfig$1>;
|
|
371
|
+
export type Api = "storefront" | "customer-account";
|
|
372
|
+
export type Options<T extends boolean> = {
|
|
373
|
+
throwIfMissing?: T;
|
|
374
|
+
};
|
|
371
375
|
/**
|
|
372
376
|
* Resolves a schema path for the provided API type. Only the API types currently
|
|
373
377
|
* bundled in Hydrogen are allowed: "storefront" and "customer".
|
|
374
378
|
* @param api
|
|
375
379
|
* @returns
|
|
376
380
|
*/
|
|
377
|
-
export declare
|
|
378
|
-
|
|
379
|
-
* The resolved schema path for the Storefront API.
|
|
380
|
-
*/
|
|
381
|
-
export declare const schema: string;
|
|
381
|
+
export declare function getSchema(api: Api, options?: Options<true>): string;
|
|
382
|
+
export declare function getSchema(api: Api, options: Options<false>): string | undefined;
|
|
382
383
|
|
|
383
384
|
export {
|
|
384
385
|
PresetConfig$1 as PresetConfig,
|
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { preset } from './preset.js';
|
|
2
|
-
export { getSchema
|
|
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
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,SAAQ,cAAgC;AACxC,SAAQ,
|
|
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"]}
|
package/dist/esm/schema.js
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import {createRequire} from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
-
|
|
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
|
-
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
try {
|
|
9
|
+
return require.resolve(`@shopify/hydrogen-react/${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
|
|
20
|
+
export { getSchema };
|
|
18
21
|
//# sourceMappingURL=out.js.map
|
|
19
22
|
//# sourceMappingURL=schema.js.map
|
package/dist/esm/schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/schema.ts"],"names":[],"mappings":"AACA;
|
|
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,2BAA2B,GAAG,cAAc;AAAA,EACrE,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-react/${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"]}
|