@shopify/hydrogen-codegen 0.0.1 → 0.1.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/dist/cjs/index.cjs +0 -4
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/patch.cjs +53 -0
- package/dist/cjs/patch.cjs.map +1 -0
- package/dist/cjs/pluck.cjs +12 -22
- package/dist/cjs/pluck.cjs.map +1 -1
- package/dist/cjs/plugin.cjs +11 -4
- package/dist/cjs/plugin.cjs.map +1 -1
- package/dist/cjs/preset.cjs +43 -15
- package/dist/cjs/preset.cjs.map +1 -1
- package/dist/cjs/schema.cjs +0 -4
- package/dist/cjs/schema.cjs.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/patch.d.ts +2 -0
- package/dist/esm/patch.js +45 -0
- package/dist/esm/patch.js.map +1 -0
- package/dist/esm/pluck.d.ts +1 -2
- package/dist/esm/pluck.js +13 -22
- package/dist/esm/pluck.js.map +1 -1
- package/dist/esm/plugin.d.ts +3 -1
- package/dist/esm/plugin.js +10 -5
- package/dist/esm/plugin.js.map +1 -1
- package/dist/esm/preset.d.ts +32 -5
- package/dist/esm/preset.js +39 -12
- package/dist/esm/preset.js.map +1 -1
- package/dist/esm/schema.js +0 -4
- package/dist/esm/schema.js.map +1 -1
- package/package.json +16 -8
- package/vendor/graphql-tag-pluck/visitor.cjs +1 -1
- package/vendor/graphql-tag-pluck/visitor.mjs +3 -3
package/dist/cjs/index.cjs
CHANGED
|
@@ -28,10 +28,6 @@ Object.defineProperty(exports, 'processSources', {
|
|
|
28
28
|
enumerable: true,
|
|
29
29
|
get: function () { return sources_js.processSources; }
|
|
30
30
|
});
|
|
31
|
-
Object.defineProperty(exports, 'patchGqlPluck', {
|
|
32
|
-
enumerable: true,
|
|
33
|
-
get: function () { return pluck_js.patchGqlPluck; }
|
|
34
|
-
});
|
|
35
31
|
Object.defineProperty(exports, 'pluckConfig', {
|
|
36
32
|
enumerable: true,
|
|
37
33
|
get: function () { return pluck_js.pluckConfig; }
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,SAAQ,cAAa;AACrB,SAAQ,cAAa;AACrB,SAAQ,QAAQ,iBAAgB;AAChC,SAAQ,sBAAqB;AAC7B,SAAQ,
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,SAAQ,cAAa;AACrB,SAAQ,cAAa;AACrB,SAAQ,QAAQ,iBAAgB;AAChC,SAAQ,sBAAqB;AAC7B,SAAQ,mBAAkB","sourcesContent":["export {preset} from './preset.js';\nexport {plugin} from './plugin.js';\nexport {schema, getSchema} from './schema.js';\nexport {processSources} from './sources.js';\nexport {pluckConfig} from './pluck.js';\n"]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var path = require('node:path');
|
|
4
|
+
var fs = require('node:fs');
|
|
5
|
+
var node_module = require('node:module');
|
|
6
|
+
var node_url = require('node:url');
|
|
7
|
+
|
|
8
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
9
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
|
|
11
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
12
|
+
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
13
|
+
|
|
14
|
+
const require2 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('out.js', document.baseURI).href)));
|
|
15
|
+
const realGqlTagPluck = require2.resolve("@graphql-tools/graphql-tag-pluck");
|
|
16
|
+
const depth = path__default.default.extname((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('out.js', document.baseURI).href))) === ".ts" ? "../" : "../../";
|
|
17
|
+
const vendorGqlTagPluck = node_url.fileURLToPath(
|
|
18
|
+
new URL(depth + "/vendor/graphql-tag-pluck", (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('out.js', document.baseURI).href)))
|
|
19
|
+
);
|
|
20
|
+
fs__default.default.copyFileSync(
|
|
21
|
+
path__default.default.join(vendorGqlTagPluck, "visitor.cjs"),
|
|
22
|
+
realGqlTagPluck.replace(/index\.js$/, "visitor.js")
|
|
23
|
+
);
|
|
24
|
+
fs__default.default.copyFileSync(
|
|
25
|
+
path__default.default.join(vendorGqlTagPluck, "visitor.mjs"),
|
|
26
|
+
realGqlTagPluck.replace("cjs", "esm").replace(/index\.js$/, "visitor.js")
|
|
27
|
+
);
|
|
28
|
+
const visitorPluginCommon = require2.resolve(
|
|
29
|
+
"@graphql-codegen/visitor-plugin-common"
|
|
30
|
+
);
|
|
31
|
+
const selectionSetToObjectFileCJS = visitorPluginCommon.replace(
|
|
32
|
+
"index.js",
|
|
33
|
+
"selection-set-to-object.js"
|
|
34
|
+
);
|
|
35
|
+
const selectionSetToObjectFileESM = selectionSetToObjectFileCJS.replace(
|
|
36
|
+
"cjs",
|
|
37
|
+
"esm"
|
|
38
|
+
);
|
|
39
|
+
fs__default.default.writeFileSync(
|
|
40
|
+
selectionSetToObjectFileCJS,
|
|
41
|
+
patchSelectionSet(fs__default.default.readFileSync(selectionSetToObjectFileCJS, "utf-8")),
|
|
42
|
+
"utf-8"
|
|
43
|
+
);
|
|
44
|
+
fs__default.default.writeFileSync(
|
|
45
|
+
selectionSetToObjectFileESM,
|
|
46
|
+
patchSelectionSet(fs__default.default.readFileSync(selectionSetToObjectFileESM, "utf-8")),
|
|
47
|
+
"utf-8"
|
|
48
|
+
);
|
|
49
|
+
function patchSelectionSet(content) {
|
|
50
|
+
return content.replace("&& s.union", "&& s?.union");
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=out.js.map
|
|
53
|
+
//# sourceMappingURL=patch.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/patch.ts"],"names":["require"],"mappings":"AAAA,OAAO,UAAU;AACjB,OAAO,QAAQ;AACf,SAAQ,qBAAoB;AAC5B,SAAQ,qBAAoB;AAK5B,MAAMA,WAAU,cAAc,YAAY,GAAG;AAC7C,MAAM,kBAAkBA,SAAQ,QAAQ,kCAAkC;AAG1E,MAAM,QAAQ,KAAK,QAAQ,YAAY,GAAG,MAAM,QAAQ,QAAQ;AAChE,MAAM,oBAAoB;AAAA,EACxB,IAAI,IAAI,QAAQ,6BAA6B,YAAY,GAAG;AAC9D;AAGA,GAAG;AAAA,EACD,KAAK,KAAK,mBAAmB,aAAa;AAAA,EAC1C,gBAAgB,QAAQ,cAAc,YAAY;AACpD;AAEA,GAAG;AAAA,EACD,KAAK,KAAK,mBAAmB,aAAa;AAAA,EAC1C,gBAAgB,QAAQ,OAAO,KAAK,EAAE,QAAQ,cAAc,YAAY;AAC1E;AAMA,MAAM,sBAAsBA,SAAQ;AAAA,EAClC;AACF;AACA,MAAM,8BAA8B,oBAAoB;AAAA,EACtD;AAAA,EACA;AACF;AACA,MAAM,8BAA8B,4BAA4B;AAAA,EAC9D;AAAA,EACA;AACF;AAEA,GAAG;AAAA,EACD;AAAA,EACA,kBAAkB,GAAG,aAAa,6BAA6B,OAAO,CAAC;AAAA,EACvE;AACF;AAEA,GAAG;AAAA,EACD;AAAA,EACA,kBAAkB,GAAG,aAAa,6BAA6B,OAAO,CAAC;AAAA,EACvE;AACF;AAEA,SAAS,kBAAkB,SAAiB;AAC1C,SAAO,QAAQ,QAAQ,cAAc,aAAa;AACpD","sourcesContent":["import path from 'node:path';\nimport fs from 'node:fs';\nimport {createRequire} from 'node:module';\nimport {fileURLToPath} from 'node:url';\n\n/**\n * Patch graphql-tag-pluck to allow it to work with `#graphql` comment and other features.\n */\nconst require = createRequire(import.meta.url);\nconst realGqlTagPluck = require.resolve('@graphql-tools/graphql-tag-pluck');\n// During tests, this file is in src/xyz.ts but in dev/prod,\n// the file is in dist/(esm|cjs)/xyz.js\nconst depth = path.extname(import.meta.url) === '.ts' ? '../' : '../../';\nconst vendorGqlTagPluck = fileURLToPath(\n new URL(depth + '/vendor/graphql-tag-pluck', import.meta.url),\n);\n\n// Copy files sequencially to avoid `EBUSY` errors in Windows\nfs.copyFileSync(\n path.join(vendorGqlTagPluck, 'visitor.cjs'),\n realGqlTagPluck.replace(/index\\.js$/, 'visitor.js'),\n);\n\nfs.copyFileSync(\n path.join(vendorGqlTagPluck, 'visitor.mjs'),\n realGqlTagPluck.replace('cjs', 'esm').replace(/index\\.js$/, 'visitor.js'),\n);\n\n/**\n * Temporary patch for a bug in another package\n * https://github.com/dotansimha/graphql-code-generator/pull/9709\n */\nconst visitorPluginCommon = require.resolve(\n '@graphql-codegen/visitor-plugin-common',\n);\nconst selectionSetToObjectFileCJS = visitorPluginCommon.replace(\n 'index.js',\n 'selection-set-to-object.js',\n);\nconst selectionSetToObjectFileESM = selectionSetToObjectFileCJS.replace(\n 'cjs',\n 'esm',\n);\n\nfs.writeFileSync(\n selectionSetToObjectFileCJS,\n patchSelectionSet(fs.readFileSync(selectionSetToObjectFileCJS, 'utf-8')),\n 'utf-8',\n);\n\nfs.writeFileSync(\n selectionSetToObjectFileESM,\n patchSelectionSet(fs.readFileSync(selectionSetToObjectFileESM, 'utf-8')),\n 'utf-8',\n);\n\nfunction patchSelectionSet(content: string) {\n return content.replace('&& s.union', '&& s?.union');\n}\n"]}
|
package/dist/cjs/pluck.cjs
CHANGED
|
@@ -1,27 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var fs = require('fs/promises');
|
|
4
|
-
var path = require('path');
|
|
5
|
-
var node_module = require('node:module');
|
|
6
|
-
var node_url = require('node:url');
|
|
7
|
-
|
|
8
|
-
async function patchGqlPluck() {
|
|
9
|
-
const require2 = node_module.createRequire((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('out.js', document.baseURI).href)));
|
|
10
|
-
const realGqlTagPluck = require2.resolve("@graphql-tools/graphql-tag-pluck");
|
|
11
|
-
const depth = path.extname((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('out.js', document.baseURI).href))) === ".ts" ? "../" : "../../";
|
|
12
|
-
const vendorGqlTagPluck = node_url.fileURLToPath(
|
|
13
|
-
new URL(depth + "/vendor/graphql-tag-pluck", (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('out.js', document.baseURI).href)))
|
|
14
|
-
);
|
|
15
|
-
await fs.copyFile(
|
|
16
|
-
path.join(vendorGqlTagPluck, "visitor.cjs"),
|
|
17
|
-
realGqlTagPluck.replace(/index\.js$/, "visitor.js")
|
|
18
|
-
);
|
|
19
|
-
await fs.copyFile(
|
|
20
|
-
path.join(vendorGqlTagPluck, "visitor.mjs"),
|
|
21
|
-
realGqlTagPluck.replace("cjs", "esm").replace(/index\.js$/, "visitor.js")
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
3
|
const pluckConfig = {
|
|
4
|
+
/**
|
|
5
|
+
* Hook to determine if a node is a gql template literal.
|
|
6
|
+
* By default, graphql-tag-pluck only looks for leading comments or `gql` tag.
|
|
7
|
+
*/
|
|
25
8
|
isGqlTemplateLiteral: (node, options) => {
|
|
26
9
|
const hasInternalGqlComment = node.type === "TemplateLiteral" && /\s*#graphql\s*\n/i.test(node.quasis[0]?.value?.raw || "");
|
|
27
10
|
if (hasInternalGqlComment)
|
|
@@ -31,6 +14,14 @@ const pluckConfig = {
|
|
|
31
14
|
const leadingCommentValue = leadingComment?.value?.trim().toLowerCase();
|
|
32
15
|
return leadingCommentValue === options?.gqlMagicComment;
|
|
33
16
|
},
|
|
17
|
+
/**
|
|
18
|
+
* Instruct how to extract the gql template literal from the code.
|
|
19
|
+
* By default, embedded expressions in template literals (e.g. ${foo})
|
|
20
|
+
* are removed from the template string. This hook allows us to annotate
|
|
21
|
+
* the template string with the required embedded expressions instead of
|
|
22
|
+
* removing them. Later, we can use this information to reconstruct the
|
|
23
|
+
* embedded expressions.
|
|
24
|
+
*/
|
|
34
25
|
pluckStringFromFile: (code, { start, end, leadingComments }) => {
|
|
35
26
|
let gqlTemplate = code.slice(start + 1, end - 1).replace(/\$\{([^}]*)\}/g, (_, m1) => "#REQUIRED_VAR=" + m1).split("\\`").join("`");
|
|
36
27
|
const chunkStart = leadingComments?.[0]?.start ?? start;
|
|
@@ -43,7 +34,6 @@ const pluckConfig = {
|
|
|
43
34
|
}
|
|
44
35
|
};
|
|
45
36
|
|
|
46
|
-
exports.patchGqlPluck = patchGqlPluck;
|
|
47
37
|
exports.pluckConfig = pluckConfig;
|
|
48
38
|
//# sourceMappingURL=out.js.map
|
|
49
39
|
//# sourceMappingURL=pluck.cjs.map
|
package/dist/cjs/pluck.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/pluck.ts"],"names":[
|
|
1
|
+
{"version":3,"sources":["../../src/pluck.ts"],"names":[],"mappings":"AAIO,MAAM,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA,EAKzB,sBAAsB,CAAC,MAAW,YAAiB;AAEjD,UAAM,wBACJ,KAAK,SAAS,qBACd,oBAAoB,KAAK,KAAK,OAAO,CAAC,GAAG,OAAO,OAAO,EAAE;AAE3D,QAAI;AAAuB,aAAO;AAGlC,UAAM,EAAC,gBAAe,IAAI;AAC1B,UAAM,iBAAiB,kBAAkB,iBAAiB,SAAS,CAAC;AACpE,UAAM,sBAAsB,gBAAgB,OAAO,KAAK,EAAE,YAAY;AAEtE,WAAO,wBAAwB,SAAS;AAAA,EAC1C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,qBAAqB,CAAC,MAAc,EAAC,OAAO,KAAK,gBAAe,MAAW;AACzE,QAAI,cAAc,KAEf,MAAM,QAAQ,GAAG,MAAM,CAAC,EAGxB,QAAQ,kBAAkB,CAAC,GAAG,OAAO,mBAAmB,EAAE,EAC1D,MAAM,KAAK,EACX,KAAK,GAAG;AAEX,UAAM,aAAa,kBAAkB,CAAC,GAAG,SAAS;AAClD,UAAM,iBAAiB,KAAK,MAAM,GAAG,UAAU;AAC/C,UAAM,CAAC,EAAE,OAAO,IAAI,eAAe,MAAM,iBAAiB,KAAK,CAAC;AAEhE,QAAI,SAAS;AAGX,qBAAe,eAAe;AAAA,IAChC;AAEA,WAAO;AAAA,EACT;AACF","sourcesContent":["/**\n * This is a modified version of graphql-tag-pluck's default config.\n * https://github.com/ardatan/graphql-tools/issues/5127\n */\nexport const pluckConfig = {\n /**\n * Hook to determine if a node is a gql template literal.\n * By default, graphql-tag-pluck only looks for leading comments or `gql` tag.\n */\n isGqlTemplateLiteral: (node: any, options: any) => {\n // Check for internal gql comment: const QUERY = `#graphql ...`\n const hasInternalGqlComment =\n node.type === 'TemplateLiteral' &&\n /\\s*#graphql\\s*\\n/i.test(node.quasis[0]?.value?.raw || '');\n\n if (hasInternalGqlComment) return true;\n\n // Check for leading gql comment: const QUERY = /* GraphQL */ `...`\n const {leadingComments} = node;\n const leadingComment = leadingComments?.[leadingComments?.length - 1];\n const leadingCommentValue = leadingComment?.value?.trim().toLowerCase();\n\n return leadingCommentValue === options?.gqlMagicComment;\n },\n\n /**\n * Instruct how to extract the gql template literal from the code.\n * By default, embedded expressions in template literals (e.g. ${foo})\n * are removed from the template string. This hook allows us to annotate\n * the template string with the required embedded expressions instead of\n * removing them. Later, we can use this information to reconstruct the\n * embedded expressions.\n */\n pluckStringFromFile: (code: string, {start, end, leadingComments}: any) => {\n let gqlTemplate = code\n // Slice quotes\n .slice(start + 1, end - 1)\n // Annotate embedded expressions\n // e.g. ${foo} -> #REQUIRED_VAR=foo\n .replace(/\\$\\{([^}]*)\\}/g, (_, m1) => '#REQUIRED_VAR=' + m1)\n .split('\\\\`')\n .join('`');\n\n const chunkStart = leadingComments?.[0]?.start ?? start;\n const codeBeforeNode = code.slice(0, chunkStart);\n const [, varName] = codeBeforeNode.match(/\\s(\\w+)\\s*=\\s*$/) || [];\n\n if (varName) {\n // Annotate with the name of the variable that stores this gql template.\n // This is used to reconstruct the embedded expressions later.\n gqlTemplate += '#VAR_NAME=' + varName;\n }\n\n return gqlTemplate;\n },\n};\n"]}
|
package/dist/cjs/plugin.cjs
CHANGED
|
@@ -5,6 +5,8 @@ const plugin = (_, __, { sourcesWithOperations, interfaceExtensionCode }, _info)
|
|
|
5
5
|
code.push(interfaceExtensionCode);
|
|
6
6
|
return code.join("") + "\n";
|
|
7
7
|
};
|
|
8
|
+
const GENERATED_QUERY_INTERFACE_NAME = "GeneratedQueryTypes";
|
|
9
|
+
const GENERATED_MUTATION_INTERFACE_NAME = "GeneratedMutationTypes";
|
|
8
10
|
const isMutationRE = /(^|}\s|\n\s*)mutation[\s({]/im;
|
|
9
11
|
const normalizeOperation = (rawSDL, variablesMap) => {
|
|
10
12
|
let variableNotFound = false;
|
|
@@ -26,11 +28,14 @@ const normalizeOperation = (rawSDL, variablesMap) => {
|
|
|
26
28
|
return rawSDL;
|
|
27
29
|
};
|
|
28
30
|
const buildTypeLines = (name, operations) => {
|
|
29
|
-
const lines = [`interface
|
|
31
|
+
const lines = [`interface ${name} {
|
|
30
32
|
`];
|
|
31
33
|
for (const [originalString, typeNames] of operations) {
|
|
32
34
|
lines.push(
|
|
33
|
-
` ${JSON.stringify(originalString)}: {return: ${
|
|
35
|
+
` ${JSON.stringify(originalString)}: {return: ${// SFAPI does not support multiple operations in a single document.
|
|
36
|
+
// Use 'never' here if that's the case so that the user gets a type error.
|
|
37
|
+
// e.g. `'query q1 {...} query q2 {...}'` is invalid.
|
|
38
|
+
typeNames.length === 1 ? typeNames[0] : "never"}, variables: ${typeNames.map((n) => n + "Variables").join(" & ")}},
|
|
34
39
|
`
|
|
35
40
|
);
|
|
36
41
|
}
|
|
@@ -63,12 +68,14 @@ function getDocumentRegistryChunk(sourcesWithOperations = []) {
|
|
|
63
68
|
);
|
|
64
69
|
}
|
|
65
70
|
return [
|
|
66
|
-
...buildTypeLines(
|
|
71
|
+
...buildTypeLines(GENERATED_QUERY_INTERFACE_NAME, queries),
|
|
67
72
|
"\n",
|
|
68
|
-
...buildTypeLines(
|
|
73
|
+
...buildTypeLines(GENERATED_MUTATION_INTERFACE_NAME, mutations)
|
|
69
74
|
];
|
|
70
75
|
}
|
|
71
76
|
|
|
77
|
+
exports.GENERATED_MUTATION_INTERFACE_NAME = GENERATED_MUTATION_INTERFACE_NAME;
|
|
78
|
+
exports.GENERATED_QUERY_INTERFACE_NAME = GENERATED_QUERY_INTERFACE_NAME;
|
|
72
79
|
exports.plugin = plugin;
|
|
73
80
|
//# sourceMappingURL=out.js.map
|
|
74
81
|
//# sourceMappingURL=plugin.cjs.map
|
package/dist/cjs/plugin.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugin.ts"],"names":[],"mappings":"AAiBO,MAAM,SAGR,CAAC,GAAG,IAAI,EAAC,uBAAuB,uBAAsB,GAAG,UAAU;AACtE,QAAM,OAAO,yBAAyB,qBAAqB;AAE3D,OAAK,KAAK,sBAAsB;AAEhC,SAAO,KAAK,KAAK,EAAE,IAAI;AACzB;
|
|
1
|
+
{"version":3,"sources":["../../src/plugin.ts"],"names":[],"mappings":"AAiBO,MAAM,SAGR,CAAC,GAAG,IAAI,EAAC,uBAAuB,uBAAsB,GAAG,UAAU;AACtE,QAAM,OAAO,yBAAyB,qBAAqB;AAE3D,OAAK,KAAK,sBAAsB;AAEhC,SAAO,KAAK,KAAK,EAAE,IAAI;AACzB;AAEO,MAAM,iCAAiC;AACvC,MAAM,oCAAoC;AAEjD,MAAM,eAAe;AAIrB,MAAM,qBAAqB,CACzB,QACA,iBACG;AACH,MAAI,mBAAmB;AAEvB,SAAO,iBAAiB,KAAK,MAAM,KAAK,CAAC,kBAAkB;AACzD,QAAI,oBAAoB,OAAO,SAAS,sBAAsB;AAC9D,eAAW,CAAC,OAAO,YAAY,KAAK,mBAAmB;AACrD,UAAI,aAAa,IAAI,YAAY,GAAG;AAClC,iBAAS,OAAO,QAAQ,OAAO,aAAa,IAAI,YAAY,CAAE;AAAA,MAChE,OAAO;AAIL,2BAAmB;AACnB,gBAAQ;AAAA,UACN,IAAI;AAAA,YACF,aAAa,YAAY;AAAA,UAC3B;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAEA,MAAM,iBAAiB,CAAC,MAAc,eAAsC;AAC1E,QAAM,QAAQ,CAAC,aAAa,IAAI;AAAA,CAAM;AAEtC,aAAW,CAAC,gBAAgB,SAAS,KAAK,YAAY;AACpD,UAAM;AAAA,MACJ,KAAK,KAAK,UAAU,cAAc,CAAC;AAAA;AAAA;AAAA,MAIjC,UAAU,WAAW,IAAI,UAAU,CAAC,IAAI,OAC1C,gBAAgB,UAAU,IAAI,CAAC,MAAM,IAAI,WAAW,EAAE,KAAK,KAAK,CAAC;AAAA;AAAA,IACnE;AAAA,EACF;AAEA,QAAM,KAAK;AAAA,CAAK;AAEhB,SAAO;AACT;AAEA,SAAS,yBACP,wBAAqD,CAAC,GACtD;AACA,QAAM,UAAU,oBAAI,IAAsB;AAC1C,QAAM,YAAY,oBAAI,IAAsB;AAE5C,QAAM,eAAe,oBAAI,IAAoB;AAC7C,aAAW,EAAC,OAAM,KAAK,uBAAuB;AAC5C,UAAM,eAAe,OAAO,QAAQ,MAAM,iBAAiB,IAAI,CAAC;AAChE,QAAI,cAAc;AAChB,aAAO,SAAS,OAAO,OAAQ,QAAQ,kBAAkB,EAAE;AAC3D,mBAAa,IAAI,cAAc,OAAO,MAAO;AAAA,IAC/C;AAAA,EACF;AAEA,aAAW,EAAC,YAAY,OAAM,KAAK,uBAAuB;AACxD,UAAM,mBAAmB,WAAW;AAAA,MAClC,CAAC,OAAO,GAAG,WAAW,SAAS;AAAA,IACjC;AAEA,QAAI,iBAAiB,WAAW;AAAG;AAEnC,UAAM,YAAY,OAAO;AACzB,UAAM,SAAS,aAAa,KAAK,SAAS,IAAI,YAAY;AAC1D,WAAO;AAAA,MACL,mBAAmB,WAAW,YAAY;AAAA,MAC1C,iBAAiB,IAAI,CAAC,MAAM,EAAE,WAAW;AAAA,IAC3C;AAAA,EACF;AAEA,SAAO;AAAA,IACL,GAAG,eAAe,gCAAgC,OAAO;AAAA,IACzD;AAAA,IACA,GAAG,eAAe,mCAAmC,SAAS;AAAA,EAChE;AACF","sourcesContent":["// This plugin is based on `gql-tag-operations-preset`\n// https://www.npmjs.com/package/@graphql-codegen/gql-tag-operations-preset\n\nimport type {PluginFunction} from '@graphql-codegen/plugin-helpers';\nimport type {Source} from '@graphql-tools/utils';\nimport type {FragmentDefinitionNode, OperationDefinitionNode} from 'graphql';\n\nexport type OperationOrFragment = {\n initialName: string;\n definition: OperationDefinitionNode | FragmentDefinitionNode;\n};\n\nexport type SourceWithOperations = {\n source: Source;\n operations: Array<OperationOrFragment>;\n};\n\nexport const plugin: PluginFunction<{\n sourcesWithOperations: Array<SourceWithOperations>;\n interfaceExtensionCode: string;\n}> = (_, __, {sourcesWithOperations, interfaceExtensionCode}, _info) => {\n const code = getDocumentRegistryChunk(sourcesWithOperations);\n\n code.push(interfaceExtensionCode);\n\n return code.join('') + '\\n';\n};\n\nexport const GENERATED_QUERY_INTERFACE_NAME = 'GeneratedQueryTypes';\nexport const GENERATED_MUTATION_INTERFACE_NAME = 'GeneratedMutationTypes';\n\nconst isMutationRE = /(^|}\\s|\\n\\s*)mutation[\\s({]/im;\n\n// Iteratively replace fragment annotations with the actual fragment content\n// until there are no more annotations in the operation.\nconst normalizeOperation = (\n rawSDL: string,\n variablesMap: Map<string, string>,\n) => {\n let variableNotFound = false;\n\n while (/#REQUIRED_VAR=/.test(rawSDL) && !variableNotFound) {\n let requiredVariables = rawSDL.matchAll(/#REQUIRED_VAR=(\\w+)/g);\n for (const [match, variableName] of requiredVariables) {\n if (variablesMap.has(variableName)) {\n rawSDL = rawSDL.replace(match, variablesMap.get(variableName)!);\n } else {\n // An annotation cannot be replaced, so the operation is invalid.\n // This should not happen, but we'll handle it just in case\n // to prevent infinite loops. This should be logged as an error and fixed.\n variableNotFound = true; // break;\n console.error(\n new Error(\n `Variable \"${variableName}\" not found. This might be a bug in hydrogen-codegen, please report it.`,\n ),\n );\n }\n }\n }\n\n return rawSDL;\n};\n\nconst buildTypeLines = (name: string, operations: Map<string, string[]>) => {\n const lines = [`interface ${name} {\\n`];\n\n for (const [originalString, typeNames] of operations) {\n lines.push(\n ` ${JSON.stringify(originalString)}: {return: ${\n // SFAPI does not support multiple operations in a single document.\n // Use 'never' here if that's the case so that the user gets a type error.\n // e.g. `'query q1 {...} query q2 {...}'` is invalid.\n typeNames.length === 1 ? typeNames[0] : 'never'\n }, variables: ${typeNames.map((n) => n + 'Variables').join(' & ')}},\\n`,\n );\n }\n\n lines.push(`}\\n`);\n\n return lines;\n};\n\nfunction getDocumentRegistryChunk(\n sourcesWithOperations: Array<SourceWithOperations> = [],\n) {\n const queries = new Map<string, string[]>();\n const mutations = new Map<string, string[]>();\n\n const variablesMap = new Map<string, string>();\n for (const {source} of sourcesWithOperations) {\n const variableName = source.rawSDL?.match(/#VAR_NAME=(\\w+)/)?.[1];\n if (variableName) {\n source.rawSDL = source.rawSDL!.replace(/#VAR_NAME=\\w+$/, '');\n variablesMap.set(variableName, source.rawSDL!);\n }\n }\n\n for (const {operations, source} of sourcesWithOperations) {\n const actualOperations = operations.filter(\n (op) => op.definition.kind === 'OperationDefinition',\n );\n\n if (actualOperations.length === 0) continue;\n\n const sdlString = source.rawSDL!;\n const target = isMutationRE.test(sdlString) ? mutations : queries;\n target.set(\n normalizeOperation(sdlString, variablesMap),\n actualOperations.map((o) => o.initialName),\n );\n }\n\n return [\n ...buildTypeLines(GENERATED_QUERY_INTERFACE_NAME, queries),\n '\\n',\n ...buildTypeLines(GENERATED_MUTATION_INTERFACE_NAME, mutations),\n ];\n}\n"]}
|
package/dist/cjs/preset.cjs
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var addPlugin = require('@graphql-codegen/add');
|
|
4
|
+
var typescriptPlugin = require('@graphql-codegen/typescript');
|
|
4
5
|
var typescriptOperationPlugin = require('@graphql-codegen/typescript-operations');
|
|
5
6
|
var sources_js = require('./sources.cjs');
|
|
6
7
|
var plugin_js = require('./plugin.cjs');
|
|
7
8
|
|
|
8
|
-
function
|
|
9
|
+
function _interopNamespace(e) {
|
|
10
|
+
if (e && e.__esModule) return e;
|
|
9
11
|
var n = Object.create(null);
|
|
10
12
|
if (e) {
|
|
11
13
|
Object.keys(e).forEach(function (k) {
|
|
@@ -22,14 +24,14 @@ function _interopNamespaceDefault(e) {
|
|
|
22
24
|
return Object.freeze(n);
|
|
23
25
|
}
|
|
24
26
|
|
|
25
|
-
var addPlugin__namespace = /*#__PURE__*/
|
|
26
|
-
var
|
|
27
|
+
var addPlugin__namespace = /*#__PURE__*/_interopNamespace(addPlugin);
|
|
28
|
+
var typescriptPlugin__namespace = /*#__PURE__*/_interopNamespace(typescriptPlugin);
|
|
29
|
+
var typescriptOperationPlugin__namespace = /*#__PURE__*/_interopNamespace(typescriptOperationPlugin);
|
|
27
30
|
|
|
28
|
-
const
|
|
29
|
-
const interfaceExtensionCode = `
|
|
31
|
+
const defaultInterfaceExtensionCode = `
|
|
30
32
|
declare module '@shopify/hydrogen' {
|
|
31
|
-
interface StorefrontQueries extends
|
|
32
|
-
interface StorefrontMutations extends
|
|
33
|
+
interface StorefrontQueries extends ${plugin_js.GENERATED_QUERY_INTERFACE_NAME} {}
|
|
34
|
+
interface StorefrontMutations extends ${plugin_js.GENERATED_MUTATION_INTERFACE_NAME} {}
|
|
33
35
|
}`;
|
|
34
36
|
const preset = {
|
|
35
37
|
buildGeneratesSection: (options) => {
|
|
@@ -43,13 +45,22 @@ const preset = {
|
|
|
43
45
|
}
|
|
44
46
|
const sourcesWithOperations = sources_js.processSources(options.documents);
|
|
45
47
|
const sources = sourcesWithOperations.map(({ source }) => source);
|
|
48
|
+
const importTypes = options.presetConfig.importTypes ?? true;
|
|
49
|
+
const namespacedImportName = options.presetConfig.namespacedImportName ?? "StorefrontAPI";
|
|
50
|
+
const importTypesFrom = options.presetConfig.importTypesFrom ?? "@shopify/hydrogen/storefront-api-types";
|
|
51
|
+
const interfaceExtensionCode = options.presetConfig.interfaceExtension?.({
|
|
52
|
+
queryType: plugin_js.GENERATED_QUERY_INTERFACE_NAME,
|
|
53
|
+
mutationType: plugin_js.GENERATED_MUTATION_INTERFACE_NAME
|
|
54
|
+
}) ?? defaultInterfaceExtensionCode;
|
|
46
55
|
const pluginMap = {
|
|
47
56
|
...options.pluginMap,
|
|
48
57
|
[`add`]: addPlugin__namespace,
|
|
58
|
+
[`typescript`]: typescriptPlugin__namespace,
|
|
49
59
|
[`typescript-operations`]: typescriptOperationPlugin__namespace,
|
|
50
60
|
[`gen-dts`]: { plugin: plugin_js.plugin }
|
|
51
61
|
};
|
|
52
62
|
const plugins = [
|
|
63
|
+
// 1. Disable eslint for the generated file
|
|
53
64
|
{
|
|
54
65
|
[`add`]: {
|
|
55
66
|
content: `/* eslint-disable eslint-comments/disable-enable-pair */
|
|
@@ -57,20 +68,36 @@ const preset = {
|
|
|
57
68
|
/* eslint-disable */`
|
|
58
69
|
}
|
|
59
70
|
},
|
|
60
|
-
|
|
71
|
+
// 2. Import all the generated API types from Hydrogen or generate all the types from the schema.
|
|
72
|
+
importTypes ? {
|
|
61
73
|
[`add`]: {
|
|
62
|
-
content: `import * as ${namespacedImportName} from '
|
|
74
|
+
content: `import * as ${namespacedImportName} from '${importTypesFrom}';
|
|
63
75
|
`
|
|
64
76
|
}
|
|
77
|
+
} : {
|
|
78
|
+
[`typescript`]: {
|
|
79
|
+
useTypeImports: true,
|
|
80
|
+
useImplementingTypes: true,
|
|
81
|
+
enumsAsTypes: true
|
|
82
|
+
}
|
|
65
83
|
},
|
|
84
|
+
// 3. Generate the operations (i.e. queries, mutations, and fragments types)
|
|
66
85
|
{
|
|
67
86
|
[`typescript-operations`]: {
|
|
68
|
-
skipTypename: true,
|
|
69
87
|
useTypeImports: true,
|
|
70
|
-
|
|
88
|
+
// Use `import type` instead of `import`
|
|
89
|
+
preResolveTypes: false,
|
|
90
|
+
// Use Pick<...> instead of primitives
|
|
91
|
+
mergeFragmentTypes: true,
|
|
92
|
+
// Merge equal fragment interfaces. Avoids adding `| {}` to Metaobject
|
|
93
|
+
skipTypename: options.presetConfig.skipTypenameInOperations ?? true,
|
|
94
|
+
// Skip __typename fields
|
|
95
|
+
namespacedImportName: importTypes ? namespacedImportName : void 0
|
|
71
96
|
}
|
|
72
97
|
},
|
|
98
|
+
// 4. Augment Hydrogen query/mutation interfaces with the generated operations
|
|
73
99
|
{ [`gen-dts`]: { sourcesWithOperations, interfaceExtensionCode } },
|
|
100
|
+
// 5. Custom plugins from the user
|
|
74
101
|
...options.plugins
|
|
75
102
|
];
|
|
76
103
|
return [
|
|
@@ -80,8 +107,10 @@ const preset = {
|
|
|
80
107
|
pluginMap,
|
|
81
108
|
schema: options.schema,
|
|
82
109
|
config: {
|
|
83
|
-
|
|
84
|
-
|
|
110
|
+
// For the TS plugin:
|
|
111
|
+
defaultScalarType: "unknown",
|
|
112
|
+
// Allow overwriting defaults:
|
|
113
|
+
...options.config
|
|
85
114
|
},
|
|
86
115
|
documents: sources,
|
|
87
116
|
documentTransforms: options.documentTransforms
|
|
@@ -90,8 +119,7 @@ const preset = {
|
|
|
90
119
|
}
|
|
91
120
|
};
|
|
92
121
|
|
|
93
|
-
exports.
|
|
94
|
-
exports.namespacedImportName = namespacedImportName;
|
|
122
|
+
exports.defaultInterfaceExtensionCode = defaultInterfaceExtensionCode;
|
|
95
123
|
exports.preset = preset;
|
|
96
124
|
//# sourceMappingURL=out.js.map
|
|
97
125
|
//# sourceMappingURL=preset.cjs.map
|
package/dist/cjs/preset.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/preset.ts"],"names":[],"mappings":"AACA,YAAY,eAAe;AAC3B,YAAY,+BAA+B;AAC3C,SAAQ,sBAAqB;AAC7B,
|
|
1
|
+
{"version":3,"sources":["../../src/preset.ts"],"names":[],"mappings":"AACA,YAAY,eAAe;AAC3B,YAAY,sBAAsB;AAClC,YAAY,+BAA+B;AAC3C,SAAQ,sBAAqB;AAC7B;AAAA,EACE,UAAU;AAAA,EACV;AAAA,EACA;AAAA,OACK;AAgCA,MAAM,gCAAgC;AAAA;AAAA,wCAEL,8BAA8B;AAAA,0CAC5B,iCAAiC;AAAA;AAGpE,MAAM,SAAmD;AAAA,EAC9D,uBAAuB,CAAC,YAAY;AAClC,QAAI,CAAC,QAAQ,cAAc,SAAS,OAAO,GAAG;AAC5C,YAAM,IAAI,MAAM,wDAAwD;AAAA,IAC1E;AAEA,QACE,QAAQ,SAAS,SAAS,KAC1B,OAAO,KAAK,QAAQ,OAAO,EAAE,KAAK,CAAC,MAAM,EAAE,WAAW,YAAY,CAAC,GACnE;AACA,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,UAAM,wBAAwB,eAAe,QAAQ,SAAS;AAC9D,UAAM,UAAU,sBAAsB,IAAI,CAAC,EAAC,OAAM,MAAM,MAAM;AAE9D,UAAM,cAAc,QAAQ,aAAa,eAAe;AACxD,UAAM,uBACJ,QAAQ,aAAa,wBAAwB;AAC/C,UAAM,kBACJ,QAAQ,aAAa,mBACrB;AAEF,UAAM,yBACJ,QAAQ,aAAa,qBAAqB;AAAA,MACxC,WAAW;AAAA,MACX,cAAc;AAAA,IAChB,CAAC,KAAK;AAER,UAAM,YAAY;AAAA,MAChB,GAAG,QAAQ;AAAA,MACX,CAAC,KAAK,GAAG;AAAA,MACT,CAAC,YAAY,GAAG;AAAA,MAChB,CAAC,uBAAuB,GAAG;AAAA,MAC3B,CAAC,SAAS,GAAG,EAAC,QAAQ,UAAS;AAAA,IACjC;AAEA,UAAM,UAAyC;AAAA;AAAA,MAE7C;AAAA,QACE,CAAC,KAAK,GAAG;AAAA,UACP,SAAS;AAAA;AAAA;AAAA,QACX;AAAA,MACF;AAAA;AAAA,MAEA,cACI;AAAA,QACE,CAAC,KAAK,GAAG;AAAA,UACP,SAAS,eAAe,oBAAoB,UAAU,eAAe;AAAA;AAAA,QACvE;AAAA,MACF,IACA;AAAA,QACE,CAAC,YAAY,GAAG;AAAA,UACd,gBAAgB;AAAA,UAChB,sBAAsB;AAAA,UACtB,cAAc;AAAA,QAChB;AAAA,MACF;AAAA;AAAA,MAEJ;AAAA,QACE,CAAC,uBAAuB,GAAG;AAAA,UACzB,gBAAgB;AAAA;AAAA,UAChB,iBAAiB;AAAA;AAAA,UACjB,oBAAoB;AAAA;AAAA,UACpB,cAAc,QAAQ,aAAa,4BAA4B;AAAA;AAAA,UAC/D,sBAAsB,cAAc,uBAAuB;AAAA,QAC7D;AAAA,MACF;AAAA;AAAA,MAEA,EAAC,CAAC,SAAS,GAAG,EAAC,uBAAuB,uBAAsB,EAAC;AAAA;AAAA,MAE7D,GAAG,QAAQ;AAAA,IACb;AAEA,WAAO;AAAA,MACL;AAAA,QACE,UAAU,QAAQ;AAAA,QAClB;AAAA,QACA;AAAA,QACA,QAAQ,QAAQ;AAAA,QAChB,QAAQ;AAAA;AAAA,UAEN,mBAAmB;AAAA;AAAA,UAEnB,GAAG,QAAQ;AAAA,QACb;AAAA,QACA,WAAW;AAAA,QACX,oBAAoB,QAAQ;AAAA,MAC9B;AAAA,IACF;AAAA,EACF;AACF","sourcesContent":["import type {Types} from '@graphql-codegen/plugin-helpers';\nimport * as addPlugin from '@graphql-codegen/add';\nimport * as typescriptPlugin from '@graphql-codegen/typescript';\nimport * as typescriptOperationPlugin from '@graphql-codegen/typescript-operations';\nimport {processSources} from './sources.js';\nimport {\n plugin as dtsPlugin,\n GENERATED_MUTATION_INTERFACE_NAME,\n GENERATED_QUERY_INTERFACE_NAME,\n} from './plugin.js';\n\nexport type HydrogenPresetConfig = {\n /**\n * Name for the variable that contains the imported types.\n * @default 'StorefrontAPI'\n */\n namespacedImportName?: string;\n /**\n * Module to import the types from.\n * @default '@shopify/hydrogen/storefront-api-types'\n */\n importTypesFrom?: string;\n /**\n * Whether types should be imported from the `importTypesFrom` module, or generated inline.\n * @default true\n */\n importTypes?: boolean;\n /**\n * Whether to skip adding `__typename` to generated operation types.\n * @default true\n */\n skipTypenameInOperations?: boolean;\n /**\n * Override the default interface extension.\n */\n interfaceExtension?: (options: {\n queryType: string;\n mutationType: string;\n }) => string;\n};\n\nexport const defaultInterfaceExtensionCode = `\ndeclare module '@shopify/hydrogen' {\n interface StorefrontQueries extends ${GENERATED_QUERY_INTERFACE_NAME} {}\n interface StorefrontMutations extends ${GENERATED_MUTATION_INTERFACE_NAME} {}\n}`;\n\nexport const preset: Types.OutputPreset<HydrogenPresetConfig> = {\n buildGeneratesSection: (options) => {\n if (!options.baseOutputDir.endsWith('.d.ts')) {\n throw new Error('[hydrogen-preset] target output should be a .d.ts file');\n }\n\n if (\n options.plugins?.length > 0 &&\n Object.keys(options.plugins).some((p) => p.startsWith('typescript'))\n ) {\n throw new Error(\n '[hydrogen-preset] providing additional typescript-based `plugins` leads to duplicated generated types',\n );\n }\n\n const sourcesWithOperations = processSources(options.documents);\n const sources = sourcesWithOperations.map(({source}) => source);\n\n const importTypes = options.presetConfig.importTypes ?? true;\n const namespacedImportName =\n options.presetConfig.namespacedImportName ?? 'StorefrontAPI';\n const importTypesFrom =\n options.presetConfig.importTypesFrom ??\n '@shopify/hydrogen/storefront-api-types';\n\n const interfaceExtensionCode =\n options.presetConfig.interfaceExtension?.({\n queryType: GENERATED_QUERY_INTERFACE_NAME,\n mutationType: GENERATED_MUTATION_INTERFACE_NAME,\n }) ?? defaultInterfaceExtensionCode;\n\n const pluginMap = {\n ...options.pluginMap,\n [`add`]: addPlugin,\n [`typescript`]: typescriptPlugin,\n [`typescript-operations`]: typescriptOperationPlugin,\n [`gen-dts`]: {plugin: dtsPlugin},\n };\n\n const plugins: Array<Types.ConfiguredPlugin> = [\n // 1. Disable eslint for the generated file\n {\n [`add`]: {\n content: `/* eslint-disable eslint-comments/disable-enable-pair */\\n/* eslint-disable eslint-comments/no-unlimited-disable */\\n/* eslint-disable */`,\n },\n },\n // 2. Import all the generated API types from Hydrogen or generate all the types from the schema.\n importTypes\n ? {\n [`add`]: {\n content: `import * as ${namespacedImportName} from '${importTypesFrom}';\\n`,\n },\n }\n : {\n [`typescript`]: {\n useTypeImports: true,\n useImplementingTypes: true,\n enumsAsTypes: true,\n },\n },\n // 3. Generate the operations (i.e. queries, mutations, and fragments types)\n {\n [`typescript-operations`]: {\n useTypeImports: true, // Use `import type` instead of `import`\n preResolveTypes: false, // Use Pick<...> instead of primitives\n mergeFragmentTypes: true, // Merge equal fragment interfaces. Avoids adding `| {}` to Metaobject\n skipTypename: options.presetConfig.skipTypenameInOperations ?? true, // Skip __typename fields\n namespacedImportName: importTypes ? namespacedImportName : undefined,\n },\n },\n // 4. Augment Hydrogen query/mutation interfaces with the generated operations\n {[`gen-dts`]: {sourcesWithOperations, interfaceExtensionCode}},\n // 5. Custom plugins from the user\n ...options.plugins,\n ];\n\n return [\n {\n filename: options.baseOutputDir,\n plugins,\n pluginMap,\n schema: options.schema,\n config: {\n // For the TS plugin:\n defaultScalarType: 'unknown',\n // Allow overwriting defaults:\n ...options.config,\n },\n documents: sources,\n documentTransforms: options.documentTransforms,\n },\n ];\n },\n};\n"]}
|
package/dist/cjs/schema.cjs
CHANGED
package/dist/cjs/schema.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/schema.ts"],"names":[],"mappings":"AACA;AACO,MAAM,YAAY,
|
|
1
|
+
{"version":3,"sources":["../../src/schema.ts"],"names":[],"mappings":"AACA;AACO,MAAM,YAAY,MACvB,gBAAgB,gDAAgD;AAElE,IAAI,eAAe;AAEnB,IAAI;AACF,iBAAe,UAAU;AAC3B,SAAS,OAAO;AAIhB;AAEO,MAAM,SAAS","sourcesContent":["// This comment is used during ESM build:\n//! import {createRequire} from 'module'; const require = createRequire(import.meta.url);\nexport const getSchema = () =>\n require.resolve('@shopify/hydrogen-react/storefront.schema.json');\n\nlet staticSchema = '';\n\ntry {\n staticSchema = getSchema();\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\nexport const schema = staticSchema;\n"]}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { preset } from './preset.js';
|
|
|
2
2
|
export { plugin } from './plugin.js';
|
|
3
3
|
export { getSchema, schema } from './schema.js';
|
|
4
4
|
export { processSources } from './sources.js';
|
|
5
|
-
export {
|
|
5
|
+
export { pluckConfig } from './pluck.js';
|
|
6
6
|
import '@graphql-codegen/plugin-helpers';
|
|
7
7
|
import '@graphql-tools/utils';
|
|
8
8
|
import 'graphql';
|
package/dist/esm/index.js
CHANGED
|
@@ -2,6 +2,6 @@ export { preset } from './preset.js';
|
|
|
2
2
|
export { plugin } from './plugin.js';
|
|
3
3
|
export { getSchema, schema } from './schema.js';
|
|
4
4
|
export { processSources } from './sources.js';
|
|
5
|
-
export {
|
|
5
|
+
export { pluckConfig } from './pluck.js';
|
|
6
6
|
//# sourceMappingURL=out.js.map
|
|
7
7
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,SAAQ,cAAa;AACrB,SAAQ,cAAa;AACrB,SAAQ,QAAQ,iBAAgB;AAChC,SAAQ,sBAAqB;AAC7B,SAAQ,
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,SAAQ,cAAa;AACrB,SAAQ,cAAa;AACrB,SAAQ,QAAQ,iBAAgB;AAChC,SAAQ,sBAAqB;AAC7B,SAAQ,mBAAkB","sourcesContent":["export {preset} from './preset.js';\nexport {plugin} from './plugin.js';\nexport {schema, getSchema} from './schema.js';\nexport {processSources} from './sources.js';\nexport {pluckConfig} from './pluck.js';\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
|
|
6
|
+
const require2 = createRequire(import.meta.url);
|
|
7
|
+
const realGqlTagPluck = require2.resolve("@graphql-tools/graphql-tag-pluck");
|
|
8
|
+
const depth = path.extname(import.meta.url) === ".ts" ? "../" : "../../";
|
|
9
|
+
const vendorGqlTagPluck = fileURLToPath(
|
|
10
|
+
new URL(depth + "/vendor/graphql-tag-pluck", import.meta.url)
|
|
11
|
+
);
|
|
12
|
+
fs.copyFileSync(
|
|
13
|
+
path.join(vendorGqlTagPluck, "visitor.cjs"),
|
|
14
|
+
realGqlTagPluck.replace(/index\.js$/, "visitor.js")
|
|
15
|
+
);
|
|
16
|
+
fs.copyFileSync(
|
|
17
|
+
path.join(vendorGqlTagPluck, "visitor.mjs"),
|
|
18
|
+
realGqlTagPluck.replace("cjs", "esm").replace(/index\.js$/, "visitor.js")
|
|
19
|
+
);
|
|
20
|
+
const visitorPluginCommon = require2.resolve(
|
|
21
|
+
"@graphql-codegen/visitor-plugin-common"
|
|
22
|
+
);
|
|
23
|
+
const selectionSetToObjectFileCJS = visitorPluginCommon.replace(
|
|
24
|
+
"index.js",
|
|
25
|
+
"selection-set-to-object.js"
|
|
26
|
+
);
|
|
27
|
+
const selectionSetToObjectFileESM = selectionSetToObjectFileCJS.replace(
|
|
28
|
+
"cjs",
|
|
29
|
+
"esm"
|
|
30
|
+
);
|
|
31
|
+
fs.writeFileSync(
|
|
32
|
+
selectionSetToObjectFileCJS,
|
|
33
|
+
patchSelectionSet(fs.readFileSync(selectionSetToObjectFileCJS, "utf-8")),
|
|
34
|
+
"utf-8"
|
|
35
|
+
);
|
|
36
|
+
fs.writeFileSync(
|
|
37
|
+
selectionSetToObjectFileESM,
|
|
38
|
+
patchSelectionSet(fs.readFileSync(selectionSetToObjectFileESM, "utf-8")),
|
|
39
|
+
"utf-8"
|
|
40
|
+
);
|
|
41
|
+
function patchSelectionSet(content) {
|
|
42
|
+
return content.replace("&& s.union", "&& s?.union");
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=out.js.map
|
|
45
|
+
//# sourceMappingURL=patch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/patch.ts"],"names":["require"],"mappings":"AAAA,OAAO,UAAU;AACjB,OAAO,QAAQ;AACf,SAAQ,qBAAoB;AAC5B,SAAQ,qBAAoB;AAK5B,MAAMA,WAAU,cAAc,YAAY,GAAG;AAC7C,MAAM,kBAAkBA,SAAQ,QAAQ,kCAAkC;AAG1E,MAAM,QAAQ,KAAK,QAAQ,YAAY,GAAG,MAAM,QAAQ,QAAQ;AAChE,MAAM,oBAAoB;AAAA,EACxB,IAAI,IAAI,QAAQ,6BAA6B,YAAY,GAAG;AAC9D;AAGA,GAAG;AAAA,EACD,KAAK,KAAK,mBAAmB,aAAa;AAAA,EAC1C,gBAAgB,QAAQ,cAAc,YAAY;AACpD;AAEA,GAAG;AAAA,EACD,KAAK,KAAK,mBAAmB,aAAa;AAAA,EAC1C,gBAAgB,QAAQ,OAAO,KAAK,EAAE,QAAQ,cAAc,YAAY;AAC1E;AAMA,MAAM,sBAAsBA,SAAQ;AAAA,EAClC;AACF;AACA,MAAM,8BAA8B,oBAAoB;AAAA,EACtD;AAAA,EACA;AACF;AACA,MAAM,8BAA8B,4BAA4B;AAAA,EAC9D;AAAA,EACA;AACF;AAEA,GAAG;AAAA,EACD;AAAA,EACA,kBAAkB,GAAG,aAAa,6BAA6B,OAAO,CAAC;AAAA,EACvE;AACF;AAEA,GAAG;AAAA,EACD;AAAA,EACA,kBAAkB,GAAG,aAAa,6BAA6B,OAAO,CAAC;AAAA,EACvE;AACF;AAEA,SAAS,kBAAkB,SAAiB;AAC1C,SAAO,QAAQ,QAAQ,cAAc,aAAa;AACpD","sourcesContent":["import path from 'node:path';\nimport fs from 'node:fs';\nimport {createRequire} from 'node:module';\nimport {fileURLToPath} from 'node:url';\n\n/**\n * Patch graphql-tag-pluck to allow it to work with `#graphql` comment and other features.\n */\nconst require = createRequire(import.meta.url);\nconst realGqlTagPluck = require.resolve('@graphql-tools/graphql-tag-pluck');\n// During tests, this file is in src/xyz.ts but in dev/prod,\n// the file is in dist/(esm|cjs)/xyz.js\nconst depth = path.extname(import.meta.url) === '.ts' ? '../' : '../../';\nconst vendorGqlTagPluck = fileURLToPath(\n new URL(depth + '/vendor/graphql-tag-pluck', import.meta.url),\n);\n\n// Copy files sequencially to avoid `EBUSY` errors in Windows\nfs.copyFileSync(\n path.join(vendorGqlTagPluck, 'visitor.cjs'),\n realGqlTagPluck.replace(/index\\.js$/, 'visitor.js'),\n);\n\nfs.copyFileSync(\n path.join(vendorGqlTagPluck, 'visitor.mjs'),\n realGqlTagPluck.replace('cjs', 'esm').replace(/index\\.js$/, 'visitor.js'),\n);\n\n/**\n * Temporary patch for a bug in another package\n * https://github.com/dotansimha/graphql-code-generator/pull/9709\n */\nconst visitorPluginCommon = require.resolve(\n '@graphql-codegen/visitor-plugin-common',\n);\nconst selectionSetToObjectFileCJS = visitorPluginCommon.replace(\n 'index.js',\n 'selection-set-to-object.js',\n);\nconst selectionSetToObjectFileESM = selectionSetToObjectFileCJS.replace(\n 'cjs',\n 'esm',\n);\n\nfs.writeFileSync(\n selectionSetToObjectFileCJS,\n patchSelectionSet(fs.readFileSync(selectionSetToObjectFileCJS, 'utf-8')),\n 'utf-8',\n);\n\nfs.writeFileSync(\n selectionSetToObjectFileESM,\n patchSelectionSet(fs.readFileSync(selectionSetToObjectFileESM, 'utf-8')),\n 'utf-8',\n);\n\nfunction patchSelectionSet(content: string) {\n return content.replace('&& s.union', '&& s?.union');\n}\n"]}
|
package/dist/esm/pluck.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
declare function patchGqlPluck(): Promise<void>;
|
|
2
1
|
/**
|
|
3
2
|
* This is a modified version of graphql-tag-pluck's default config.
|
|
4
3
|
* https://github.com/ardatan/graphql-tools/issues/5127
|
|
@@ -20,4 +19,4 @@ declare const pluckConfig: {
|
|
|
20
19
|
pluckStringFromFile: (code: string, { start, end, leadingComments }: any) => string;
|
|
21
20
|
};
|
|
22
21
|
|
|
23
|
-
export {
|
|
22
|
+
export { pluckConfig };
|
package/dist/esm/pluck.js
CHANGED
|
@@ -1,25 +1,8 @@
|
|
|
1
|
-
import fs from 'fs/promises';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { createRequire } from 'node:module';
|
|
4
|
-
import { fileURLToPath } from 'node:url';
|
|
5
|
-
|
|
6
|
-
async function patchGqlPluck() {
|
|
7
|
-
const require2 = createRequire(import.meta.url);
|
|
8
|
-
const realGqlTagPluck = require2.resolve("@graphql-tools/graphql-tag-pluck");
|
|
9
|
-
const depth = path.extname(import.meta.url) === ".ts" ? "../" : "../../";
|
|
10
|
-
const vendorGqlTagPluck = fileURLToPath(
|
|
11
|
-
new URL(depth + "/vendor/graphql-tag-pluck", import.meta.url)
|
|
12
|
-
);
|
|
13
|
-
await fs.copyFile(
|
|
14
|
-
path.join(vendorGqlTagPluck, "visitor.cjs"),
|
|
15
|
-
realGqlTagPluck.replace(/index\.js$/, "visitor.js")
|
|
16
|
-
);
|
|
17
|
-
await fs.copyFile(
|
|
18
|
-
path.join(vendorGqlTagPluck, "visitor.mjs"),
|
|
19
|
-
realGqlTagPluck.replace("cjs", "esm").replace(/index\.js$/, "visitor.js")
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
1
|
const pluckConfig = {
|
|
2
|
+
/**
|
|
3
|
+
* Hook to determine if a node is a gql template literal.
|
|
4
|
+
* By default, graphql-tag-pluck only looks for leading comments or `gql` tag.
|
|
5
|
+
*/
|
|
23
6
|
isGqlTemplateLiteral: (node, options) => {
|
|
24
7
|
const hasInternalGqlComment = node.type === "TemplateLiteral" && /\s*#graphql\s*\n/i.test(node.quasis[0]?.value?.raw || "");
|
|
25
8
|
if (hasInternalGqlComment)
|
|
@@ -29,6 +12,14 @@ const pluckConfig = {
|
|
|
29
12
|
const leadingCommentValue = leadingComment?.value?.trim().toLowerCase();
|
|
30
13
|
return leadingCommentValue === options?.gqlMagicComment;
|
|
31
14
|
},
|
|
15
|
+
/**
|
|
16
|
+
* Instruct how to extract the gql template literal from the code.
|
|
17
|
+
* By default, embedded expressions in template literals (e.g. ${foo})
|
|
18
|
+
* are removed from the template string. This hook allows us to annotate
|
|
19
|
+
* the template string with the required embedded expressions instead of
|
|
20
|
+
* removing them. Later, we can use this information to reconstruct the
|
|
21
|
+
* embedded expressions.
|
|
22
|
+
*/
|
|
32
23
|
pluckStringFromFile: (code, { start, end, leadingComments }) => {
|
|
33
24
|
let gqlTemplate = code.slice(start + 1, end - 1).replace(/\$\{([^}]*)\}/g, (_, m1) => "#REQUIRED_VAR=" + m1).split("\\`").join("`");
|
|
34
25
|
const chunkStart = leadingComments?.[0]?.start ?? start;
|
|
@@ -41,6 +32,6 @@ const pluckConfig = {
|
|
|
41
32
|
}
|
|
42
33
|
};
|
|
43
34
|
|
|
44
|
-
export {
|
|
35
|
+
export { pluckConfig };
|
|
45
36
|
//# sourceMappingURL=out.js.map
|
|
46
37
|
//# sourceMappingURL=pluck.js.map
|
package/dist/esm/pluck.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/pluck.ts"],"names":[
|
|
1
|
+
{"version":3,"sources":["../../src/pluck.ts"],"names":[],"mappings":"AAIO,MAAM,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA,EAKzB,sBAAsB,CAAC,MAAW,YAAiB;AAEjD,UAAM,wBACJ,KAAK,SAAS,qBACd,oBAAoB,KAAK,KAAK,OAAO,CAAC,GAAG,OAAO,OAAO,EAAE;AAE3D,QAAI;AAAuB,aAAO;AAGlC,UAAM,EAAC,gBAAe,IAAI;AAC1B,UAAM,iBAAiB,kBAAkB,iBAAiB,SAAS,CAAC;AACpE,UAAM,sBAAsB,gBAAgB,OAAO,KAAK,EAAE,YAAY;AAEtE,WAAO,wBAAwB,SAAS;AAAA,EAC1C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,qBAAqB,CAAC,MAAc,EAAC,OAAO,KAAK,gBAAe,MAAW;AACzE,QAAI,cAAc,KAEf,MAAM,QAAQ,GAAG,MAAM,CAAC,EAGxB,QAAQ,kBAAkB,CAAC,GAAG,OAAO,mBAAmB,EAAE,EAC1D,MAAM,KAAK,EACX,KAAK,GAAG;AAEX,UAAM,aAAa,kBAAkB,CAAC,GAAG,SAAS;AAClD,UAAM,iBAAiB,KAAK,MAAM,GAAG,UAAU;AAC/C,UAAM,CAAC,EAAE,OAAO,IAAI,eAAe,MAAM,iBAAiB,KAAK,CAAC;AAEhE,QAAI,SAAS;AAGX,qBAAe,eAAe;AAAA,IAChC;AAEA,WAAO;AAAA,EACT;AACF","sourcesContent":["/**\n * This is a modified version of graphql-tag-pluck's default config.\n * https://github.com/ardatan/graphql-tools/issues/5127\n */\nexport const pluckConfig = {\n /**\n * Hook to determine if a node is a gql template literal.\n * By default, graphql-tag-pluck only looks for leading comments or `gql` tag.\n */\n isGqlTemplateLiteral: (node: any, options: any) => {\n // Check for internal gql comment: const QUERY = `#graphql ...`\n const hasInternalGqlComment =\n node.type === 'TemplateLiteral' &&\n /\\s*#graphql\\s*\\n/i.test(node.quasis[0]?.value?.raw || '');\n\n if (hasInternalGqlComment) return true;\n\n // Check for leading gql comment: const QUERY = /* GraphQL */ `...`\n const {leadingComments} = node;\n const leadingComment = leadingComments?.[leadingComments?.length - 1];\n const leadingCommentValue = leadingComment?.value?.trim().toLowerCase();\n\n return leadingCommentValue === options?.gqlMagicComment;\n },\n\n /**\n * Instruct how to extract the gql template literal from the code.\n * By default, embedded expressions in template literals (e.g. ${foo})\n * are removed from the template string. This hook allows us to annotate\n * the template string with the required embedded expressions instead of\n * removing them. Later, we can use this information to reconstruct the\n * embedded expressions.\n */\n pluckStringFromFile: (code: string, {start, end, leadingComments}: any) => {\n let gqlTemplate = code\n // Slice quotes\n .slice(start + 1, end - 1)\n // Annotate embedded expressions\n // e.g. ${foo} -> #REQUIRED_VAR=foo\n .replace(/\\$\\{([^}]*)\\}/g, (_, m1) => '#REQUIRED_VAR=' + m1)\n .split('\\\\`')\n .join('`');\n\n const chunkStart = leadingComments?.[0]?.start ?? start;\n const codeBeforeNode = code.slice(0, chunkStart);\n const [, varName] = codeBeforeNode.match(/\\s(\\w+)\\s*=\\s*$/) || [];\n\n if (varName) {\n // Annotate with the name of the variable that stores this gql template.\n // This is used to reconstruct the embedded expressions later.\n gqlTemplate += '#VAR_NAME=' + varName;\n }\n\n return gqlTemplate;\n },\n};\n"]}
|
package/dist/esm/plugin.d.ts
CHANGED
|
@@ -14,5 +14,7 @@ declare const plugin: PluginFunction<{
|
|
|
14
14
|
sourcesWithOperations: Array<SourceWithOperations>;
|
|
15
15
|
interfaceExtensionCode: string;
|
|
16
16
|
}>;
|
|
17
|
+
declare const GENERATED_QUERY_INTERFACE_NAME = "GeneratedQueryTypes";
|
|
18
|
+
declare const GENERATED_MUTATION_INTERFACE_NAME = "GeneratedMutationTypes";
|
|
17
19
|
|
|
18
|
-
export { OperationOrFragment, SourceWithOperations, plugin };
|
|
20
|
+
export { GENERATED_MUTATION_INTERFACE_NAME, GENERATED_QUERY_INTERFACE_NAME, OperationOrFragment, SourceWithOperations, plugin };
|
package/dist/esm/plugin.js
CHANGED
|
@@ -3,6 +3,8 @@ const plugin = (_, __, { sourcesWithOperations, interfaceExtensionCode }, _info)
|
|
|
3
3
|
code.push(interfaceExtensionCode);
|
|
4
4
|
return code.join("") + "\n";
|
|
5
5
|
};
|
|
6
|
+
const GENERATED_QUERY_INTERFACE_NAME = "GeneratedQueryTypes";
|
|
7
|
+
const GENERATED_MUTATION_INTERFACE_NAME = "GeneratedMutationTypes";
|
|
6
8
|
const isMutationRE = /(^|}\s|\n\s*)mutation[\s({]/im;
|
|
7
9
|
const normalizeOperation = (rawSDL, variablesMap) => {
|
|
8
10
|
let variableNotFound = false;
|
|
@@ -24,11 +26,14 @@ const normalizeOperation = (rawSDL, variablesMap) => {
|
|
|
24
26
|
return rawSDL;
|
|
25
27
|
};
|
|
26
28
|
const buildTypeLines = (name, operations) => {
|
|
27
|
-
const lines = [`interface
|
|
29
|
+
const lines = [`interface ${name} {
|
|
28
30
|
`];
|
|
29
31
|
for (const [originalString, typeNames] of operations) {
|
|
30
32
|
lines.push(
|
|
31
|
-
` ${JSON.stringify(originalString)}: {return: ${
|
|
33
|
+
` ${JSON.stringify(originalString)}: {return: ${// SFAPI does not support multiple operations in a single document.
|
|
34
|
+
// Use 'never' here if that's the case so that the user gets a type error.
|
|
35
|
+
// e.g. `'query q1 {...} query q2 {...}'` is invalid.
|
|
36
|
+
typeNames.length === 1 ? typeNames[0] : "never"}, variables: ${typeNames.map((n) => n + "Variables").join(" & ")}},
|
|
32
37
|
`
|
|
33
38
|
);
|
|
34
39
|
}
|
|
@@ -61,12 +66,12 @@ function getDocumentRegistryChunk(sourcesWithOperations = []) {
|
|
|
61
66
|
);
|
|
62
67
|
}
|
|
63
68
|
return [
|
|
64
|
-
...buildTypeLines(
|
|
69
|
+
...buildTypeLines(GENERATED_QUERY_INTERFACE_NAME, queries),
|
|
65
70
|
"\n",
|
|
66
|
-
...buildTypeLines(
|
|
71
|
+
...buildTypeLines(GENERATED_MUTATION_INTERFACE_NAME, mutations)
|
|
67
72
|
];
|
|
68
73
|
}
|
|
69
74
|
|
|
70
|
-
export { plugin };
|
|
75
|
+
export { GENERATED_MUTATION_INTERFACE_NAME, GENERATED_QUERY_INTERFACE_NAME, plugin };
|
|
71
76
|
//# sourceMappingURL=out.js.map
|
|
72
77
|
//# sourceMappingURL=plugin.js.map
|
package/dist/esm/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugin.ts"],"names":[],"mappings":"AAiBO,MAAM,SAGR,CAAC,GAAG,IAAI,EAAC,uBAAuB,uBAAsB,GAAG,UAAU;AACtE,QAAM,OAAO,yBAAyB,qBAAqB;AAE3D,OAAK,KAAK,sBAAsB;AAEhC,SAAO,KAAK,KAAK,EAAE,IAAI;AACzB;
|
|
1
|
+
{"version":3,"sources":["../../src/plugin.ts"],"names":[],"mappings":"AAiBO,MAAM,SAGR,CAAC,GAAG,IAAI,EAAC,uBAAuB,uBAAsB,GAAG,UAAU;AACtE,QAAM,OAAO,yBAAyB,qBAAqB;AAE3D,OAAK,KAAK,sBAAsB;AAEhC,SAAO,KAAK,KAAK,EAAE,IAAI;AACzB;AAEO,MAAM,iCAAiC;AACvC,MAAM,oCAAoC;AAEjD,MAAM,eAAe;AAIrB,MAAM,qBAAqB,CACzB,QACA,iBACG;AACH,MAAI,mBAAmB;AAEvB,SAAO,iBAAiB,KAAK,MAAM,KAAK,CAAC,kBAAkB;AACzD,QAAI,oBAAoB,OAAO,SAAS,sBAAsB;AAC9D,eAAW,CAAC,OAAO,YAAY,KAAK,mBAAmB;AACrD,UAAI,aAAa,IAAI,YAAY,GAAG;AAClC,iBAAS,OAAO,QAAQ,OAAO,aAAa,IAAI,YAAY,CAAE;AAAA,MAChE,OAAO;AAIL,2BAAmB;AACnB,gBAAQ;AAAA,UACN,IAAI;AAAA,YACF,aAAa,YAAY;AAAA,UAC3B;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAEA,MAAM,iBAAiB,CAAC,MAAc,eAAsC;AAC1E,QAAM,QAAQ,CAAC,aAAa,IAAI;AAAA,CAAM;AAEtC,aAAW,CAAC,gBAAgB,SAAS,KAAK,YAAY;AACpD,UAAM;AAAA,MACJ,KAAK,KAAK,UAAU,cAAc,CAAC;AAAA;AAAA;AAAA,MAIjC,UAAU,WAAW,IAAI,UAAU,CAAC,IAAI,OAC1C,gBAAgB,UAAU,IAAI,CAAC,MAAM,IAAI,WAAW,EAAE,KAAK,KAAK,CAAC;AAAA;AAAA,IACnE;AAAA,EACF;AAEA,QAAM,KAAK;AAAA,CAAK;AAEhB,SAAO;AACT;AAEA,SAAS,yBACP,wBAAqD,CAAC,GACtD;AACA,QAAM,UAAU,oBAAI,IAAsB;AAC1C,QAAM,YAAY,oBAAI,IAAsB;AAE5C,QAAM,eAAe,oBAAI,IAAoB;AAC7C,aAAW,EAAC,OAAM,KAAK,uBAAuB;AAC5C,UAAM,eAAe,OAAO,QAAQ,MAAM,iBAAiB,IAAI,CAAC;AAChE,QAAI,cAAc;AAChB,aAAO,SAAS,OAAO,OAAQ,QAAQ,kBAAkB,EAAE;AAC3D,mBAAa,IAAI,cAAc,OAAO,MAAO;AAAA,IAC/C;AAAA,EACF;AAEA,aAAW,EAAC,YAAY,OAAM,KAAK,uBAAuB;AACxD,UAAM,mBAAmB,WAAW;AAAA,MAClC,CAAC,OAAO,GAAG,WAAW,SAAS;AAAA,IACjC;AAEA,QAAI,iBAAiB,WAAW;AAAG;AAEnC,UAAM,YAAY,OAAO;AACzB,UAAM,SAAS,aAAa,KAAK,SAAS,IAAI,YAAY;AAC1D,WAAO;AAAA,MACL,mBAAmB,WAAW,YAAY;AAAA,MAC1C,iBAAiB,IAAI,CAAC,MAAM,EAAE,WAAW;AAAA,IAC3C;AAAA,EACF;AAEA,SAAO;AAAA,IACL,GAAG,eAAe,gCAAgC,OAAO;AAAA,IACzD;AAAA,IACA,GAAG,eAAe,mCAAmC,SAAS;AAAA,EAChE;AACF","sourcesContent":["// This plugin is based on `gql-tag-operations-preset`\n// https://www.npmjs.com/package/@graphql-codegen/gql-tag-operations-preset\n\nimport type {PluginFunction} from '@graphql-codegen/plugin-helpers';\nimport type {Source} from '@graphql-tools/utils';\nimport type {FragmentDefinitionNode, OperationDefinitionNode} from 'graphql';\n\nexport type OperationOrFragment = {\n initialName: string;\n definition: OperationDefinitionNode | FragmentDefinitionNode;\n};\n\nexport type SourceWithOperations = {\n source: Source;\n operations: Array<OperationOrFragment>;\n};\n\nexport const plugin: PluginFunction<{\n sourcesWithOperations: Array<SourceWithOperations>;\n interfaceExtensionCode: string;\n}> = (_, __, {sourcesWithOperations, interfaceExtensionCode}, _info) => {\n const code = getDocumentRegistryChunk(sourcesWithOperations);\n\n code.push(interfaceExtensionCode);\n\n return code.join('') + '\\n';\n};\n\nexport const GENERATED_QUERY_INTERFACE_NAME = 'GeneratedQueryTypes';\nexport const GENERATED_MUTATION_INTERFACE_NAME = 'GeneratedMutationTypes';\n\nconst isMutationRE = /(^|}\\s|\\n\\s*)mutation[\\s({]/im;\n\n// Iteratively replace fragment annotations with the actual fragment content\n// until there are no more annotations in the operation.\nconst normalizeOperation = (\n rawSDL: string,\n variablesMap: Map<string, string>,\n) => {\n let variableNotFound = false;\n\n while (/#REQUIRED_VAR=/.test(rawSDL) && !variableNotFound) {\n let requiredVariables = rawSDL.matchAll(/#REQUIRED_VAR=(\\w+)/g);\n for (const [match, variableName] of requiredVariables) {\n if (variablesMap.has(variableName)) {\n rawSDL = rawSDL.replace(match, variablesMap.get(variableName)!);\n } else {\n // An annotation cannot be replaced, so the operation is invalid.\n // This should not happen, but we'll handle it just in case\n // to prevent infinite loops. This should be logged as an error and fixed.\n variableNotFound = true; // break;\n console.error(\n new Error(\n `Variable \"${variableName}\" not found. This might be a bug in hydrogen-codegen, please report it.`,\n ),\n );\n }\n }\n }\n\n return rawSDL;\n};\n\nconst buildTypeLines = (name: string, operations: Map<string, string[]>) => {\n const lines = [`interface ${name} {\\n`];\n\n for (const [originalString, typeNames] of operations) {\n lines.push(\n ` ${JSON.stringify(originalString)}: {return: ${\n // SFAPI does not support multiple operations in a single document.\n // Use 'never' here if that's the case so that the user gets a type error.\n // e.g. `'query q1 {...} query q2 {...}'` is invalid.\n typeNames.length === 1 ? typeNames[0] : 'never'\n }, variables: ${typeNames.map((n) => n + 'Variables').join(' & ')}},\\n`,\n );\n }\n\n lines.push(`}\\n`);\n\n return lines;\n};\n\nfunction getDocumentRegistryChunk(\n sourcesWithOperations: Array<SourceWithOperations> = [],\n) {\n const queries = new Map<string, string[]>();\n const mutations = new Map<string, string[]>();\n\n const variablesMap = new Map<string, string>();\n for (const {source} of sourcesWithOperations) {\n const variableName = source.rawSDL?.match(/#VAR_NAME=(\\w+)/)?.[1];\n if (variableName) {\n source.rawSDL = source.rawSDL!.replace(/#VAR_NAME=\\w+$/, '');\n variablesMap.set(variableName, source.rawSDL!);\n }\n }\n\n for (const {operations, source} of sourcesWithOperations) {\n const actualOperations = operations.filter(\n (op) => op.definition.kind === 'OperationDefinition',\n );\n\n if (actualOperations.length === 0) continue;\n\n const sdlString = source.rawSDL!;\n const target = isMutationRE.test(sdlString) ? mutations : queries;\n target.set(\n normalizeOperation(sdlString, variablesMap),\n actualOperations.map((o) => o.initialName),\n );\n }\n\n return [\n ...buildTypeLines(GENERATED_QUERY_INTERFACE_NAME, queries),\n '\\n',\n ...buildTypeLines(GENERATED_MUTATION_INTERFACE_NAME, mutations),\n ];\n}\n"]}
|
package/dist/esm/preset.d.ts
CHANGED
|
@@ -1,8 +1,35 @@
|
|
|
1
1
|
import { Types } from '@graphql-codegen/plugin-helpers';
|
|
2
2
|
|
|
3
|
-
type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
type HydrogenPresetConfig = {
|
|
4
|
+
/**
|
|
5
|
+
* Name for the variable that contains the imported types.
|
|
6
|
+
* @default 'StorefrontAPI'
|
|
7
|
+
*/
|
|
8
|
+
namespacedImportName?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Module to import the types from.
|
|
11
|
+
* @default '@shopify/hydrogen/storefront-api-types'
|
|
12
|
+
*/
|
|
13
|
+
importTypesFrom?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Whether types should be imported from the `importTypesFrom` module, or generated inline.
|
|
16
|
+
* @default true
|
|
17
|
+
*/
|
|
18
|
+
importTypes?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Whether to skip adding `__typename` to generated operation types.
|
|
21
|
+
* @default true
|
|
22
|
+
*/
|
|
23
|
+
skipTypenameInOperations?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Override the default interface extension.
|
|
26
|
+
*/
|
|
27
|
+
interfaceExtension?: (options: {
|
|
28
|
+
queryType: string;
|
|
29
|
+
mutationType: string;
|
|
30
|
+
}) => string;
|
|
31
|
+
};
|
|
32
|
+
declare const defaultInterfaceExtensionCode = "\ndeclare module '@shopify/hydrogen' {\n interface StorefrontQueries extends GeneratedQueryTypes {}\n interface StorefrontMutations extends GeneratedMutationTypes {}\n}";
|
|
33
|
+
declare const preset: Types.OutputPreset<HydrogenPresetConfig>;
|
|
7
34
|
|
|
8
|
-
export {
|
|
35
|
+
export { HydrogenPresetConfig, defaultInterfaceExtensionCode, preset };
|
package/dist/esm/preset.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import * as addPlugin from '@graphql-codegen/add';
|
|
2
|
+
import * as typescriptPlugin from '@graphql-codegen/typescript';
|
|
2
3
|
import * as typescriptOperationPlugin from '@graphql-codegen/typescript-operations';
|
|
3
4
|
import { processSources } from './sources.js';
|
|
4
|
-
import { plugin } from './plugin.js';
|
|
5
|
+
import { GENERATED_QUERY_INTERFACE_NAME, GENERATED_MUTATION_INTERFACE_NAME, plugin } from './plugin.js';
|
|
5
6
|
|
|
6
|
-
const
|
|
7
|
-
const interfaceExtensionCode = `
|
|
7
|
+
const defaultInterfaceExtensionCode = `
|
|
8
8
|
declare module '@shopify/hydrogen' {
|
|
9
|
-
interface StorefrontQueries extends
|
|
10
|
-
interface StorefrontMutations extends
|
|
9
|
+
interface StorefrontQueries extends ${GENERATED_QUERY_INTERFACE_NAME} {}
|
|
10
|
+
interface StorefrontMutations extends ${GENERATED_MUTATION_INTERFACE_NAME} {}
|
|
11
11
|
}`;
|
|
12
12
|
const preset = {
|
|
13
13
|
buildGeneratesSection: (options) => {
|
|
@@ -21,13 +21,22 @@ const preset = {
|
|
|
21
21
|
}
|
|
22
22
|
const sourcesWithOperations = processSources(options.documents);
|
|
23
23
|
const sources = sourcesWithOperations.map(({ source }) => source);
|
|
24
|
+
const importTypes = options.presetConfig.importTypes ?? true;
|
|
25
|
+
const namespacedImportName = options.presetConfig.namespacedImportName ?? "StorefrontAPI";
|
|
26
|
+
const importTypesFrom = options.presetConfig.importTypesFrom ?? "@shopify/hydrogen/storefront-api-types";
|
|
27
|
+
const interfaceExtensionCode = options.presetConfig.interfaceExtension?.({
|
|
28
|
+
queryType: GENERATED_QUERY_INTERFACE_NAME,
|
|
29
|
+
mutationType: GENERATED_MUTATION_INTERFACE_NAME
|
|
30
|
+
}) ?? defaultInterfaceExtensionCode;
|
|
24
31
|
const pluginMap = {
|
|
25
32
|
...options.pluginMap,
|
|
26
33
|
[`add`]: addPlugin,
|
|
34
|
+
[`typescript`]: typescriptPlugin,
|
|
27
35
|
[`typescript-operations`]: typescriptOperationPlugin,
|
|
28
36
|
[`gen-dts`]: { plugin: plugin }
|
|
29
37
|
};
|
|
30
38
|
const plugins = [
|
|
39
|
+
// 1. Disable eslint for the generated file
|
|
31
40
|
{
|
|
32
41
|
[`add`]: {
|
|
33
42
|
content: `/* eslint-disable eslint-comments/disable-enable-pair */
|
|
@@ -35,20 +44,36 @@ const preset = {
|
|
|
35
44
|
/* eslint-disable */`
|
|
36
45
|
}
|
|
37
46
|
},
|
|
38
|
-
|
|
47
|
+
// 2. Import all the generated API types from Hydrogen or generate all the types from the schema.
|
|
48
|
+
importTypes ? {
|
|
39
49
|
[`add`]: {
|
|
40
|
-
content: `import * as ${namespacedImportName} from '
|
|
50
|
+
content: `import * as ${namespacedImportName} from '${importTypesFrom}';
|
|
41
51
|
`
|
|
42
52
|
}
|
|
53
|
+
} : {
|
|
54
|
+
[`typescript`]: {
|
|
55
|
+
useTypeImports: true,
|
|
56
|
+
useImplementingTypes: true,
|
|
57
|
+
enumsAsTypes: true
|
|
58
|
+
}
|
|
43
59
|
},
|
|
60
|
+
// 3. Generate the operations (i.e. queries, mutations, and fragments types)
|
|
44
61
|
{
|
|
45
62
|
[`typescript-operations`]: {
|
|
46
|
-
skipTypename: true,
|
|
47
63
|
useTypeImports: true,
|
|
48
|
-
|
|
64
|
+
// Use `import type` instead of `import`
|
|
65
|
+
preResolveTypes: false,
|
|
66
|
+
// Use Pick<...> instead of primitives
|
|
67
|
+
mergeFragmentTypes: true,
|
|
68
|
+
// Merge equal fragment interfaces. Avoids adding `| {}` to Metaobject
|
|
69
|
+
skipTypename: options.presetConfig.skipTypenameInOperations ?? true,
|
|
70
|
+
// Skip __typename fields
|
|
71
|
+
namespacedImportName: importTypes ? namespacedImportName : void 0
|
|
49
72
|
}
|
|
50
73
|
},
|
|
74
|
+
// 4. Augment Hydrogen query/mutation interfaces with the generated operations
|
|
51
75
|
{ [`gen-dts`]: { sourcesWithOperations, interfaceExtensionCode } },
|
|
76
|
+
// 5. Custom plugins from the user
|
|
52
77
|
...options.plugins
|
|
53
78
|
];
|
|
54
79
|
return [
|
|
@@ -58,8 +83,10 @@ const preset = {
|
|
|
58
83
|
pluginMap,
|
|
59
84
|
schema: options.schema,
|
|
60
85
|
config: {
|
|
61
|
-
|
|
62
|
-
|
|
86
|
+
// For the TS plugin:
|
|
87
|
+
defaultScalarType: "unknown",
|
|
88
|
+
// Allow overwriting defaults:
|
|
89
|
+
...options.config
|
|
63
90
|
},
|
|
64
91
|
documents: sources,
|
|
65
92
|
documentTransforms: options.documentTransforms
|
|
@@ -68,6 +95,6 @@ const preset = {
|
|
|
68
95
|
}
|
|
69
96
|
};
|
|
70
97
|
|
|
71
|
-
export {
|
|
98
|
+
export { defaultInterfaceExtensionCode, preset };
|
|
72
99
|
//# sourceMappingURL=out.js.map
|
|
73
100
|
//# sourceMappingURL=preset.js.map
|
package/dist/esm/preset.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/preset.ts"],"names":[],"mappings":"AACA,YAAY,eAAe;AAC3B,YAAY,+BAA+B;AAC3C,SAAQ,sBAAqB;AAC7B,
|
|
1
|
+
{"version":3,"sources":["../../src/preset.ts"],"names":[],"mappings":"AACA,YAAY,eAAe;AAC3B,YAAY,sBAAsB;AAClC,YAAY,+BAA+B;AAC3C,SAAQ,sBAAqB;AAC7B;AAAA,EACE,UAAU;AAAA,EACV;AAAA,EACA;AAAA,OACK;AAgCA,MAAM,gCAAgC;AAAA;AAAA,wCAEL,8BAA8B;AAAA,0CAC5B,iCAAiC;AAAA;AAGpE,MAAM,SAAmD;AAAA,EAC9D,uBAAuB,CAAC,YAAY;AAClC,QAAI,CAAC,QAAQ,cAAc,SAAS,OAAO,GAAG;AAC5C,YAAM,IAAI,MAAM,wDAAwD;AAAA,IAC1E;AAEA,QACE,QAAQ,SAAS,SAAS,KAC1B,OAAO,KAAK,QAAQ,OAAO,EAAE,KAAK,CAAC,MAAM,EAAE,WAAW,YAAY,CAAC,GACnE;AACA,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,UAAM,wBAAwB,eAAe,QAAQ,SAAS;AAC9D,UAAM,UAAU,sBAAsB,IAAI,CAAC,EAAC,OAAM,MAAM,MAAM;AAE9D,UAAM,cAAc,QAAQ,aAAa,eAAe;AACxD,UAAM,uBACJ,QAAQ,aAAa,wBAAwB;AAC/C,UAAM,kBACJ,QAAQ,aAAa,mBACrB;AAEF,UAAM,yBACJ,QAAQ,aAAa,qBAAqB;AAAA,MACxC,WAAW;AAAA,MACX,cAAc;AAAA,IAChB,CAAC,KAAK;AAER,UAAM,YAAY;AAAA,MAChB,GAAG,QAAQ;AAAA,MACX,CAAC,KAAK,GAAG;AAAA,MACT,CAAC,YAAY,GAAG;AAAA,MAChB,CAAC,uBAAuB,GAAG;AAAA,MAC3B,CAAC,SAAS,GAAG,EAAC,QAAQ,UAAS;AAAA,IACjC;AAEA,UAAM,UAAyC;AAAA;AAAA,MAE7C;AAAA,QACE,CAAC,KAAK,GAAG;AAAA,UACP,SAAS;AAAA;AAAA;AAAA,QACX;AAAA,MACF;AAAA;AAAA,MAEA,cACI;AAAA,QACE,CAAC,KAAK,GAAG;AAAA,UACP,SAAS,eAAe,oBAAoB,UAAU,eAAe;AAAA;AAAA,QACvE;AAAA,MACF,IACA;AAAA,QACE,CAAC,YAAY,GAAG;AAAA,UACd,gBAAgB;AAAA,UAChB,sBAAsB;AAAA,UACtB,cAAc;AAAA,QAChB;AAAA,MACF;AAAA;AAAA,MAEJ;AAAA,QACE,CAAC,uBAAuB,GAAG;AAAA,UACzB,gBAAgB;AAAA;AAAA,UAChB,iBAAiB;AAAA;AAAA,UACjB,oBAAoB;AAAA;AAAA,UACpB,cAAc,QAAQ,aAAa,4BAA4B;AAAA;AAAA,UAC/D,sBAAsB,cAAc,uBAAuB;AAAA,QAC7D;AAAA,MACF;AAAA;AAAA,MAEA,EAAC,CAAC,SAAS,GAAG,EAAC,uBAAuB,uBAAsB,EAAC;AAAA;AAAA,MAE7D,GAAG,QAAQ;AAAA,IACb;AAEA,WAAO;AAAA,MACL;AAAA,QACE,UAAU,QAAQ;AAAA,QAClB;AAAA,QACA;AAAA,QACA,QAAQ,QAAQ;AAAA,QAChB,QAAQ;AAAA;AAAA,UAEN,mBAAmB;AAAA;AAAA,UAEnB,GAAG,QAAQ;AAAA,QACb;AAAA,QACA,WAAW;AAAA,QACX,oBAAoB,QAAQ;AAAA,MAC9B;AAAA,IACF;AAAA,EACF;AACF","sourcesContent":["import type {Types} from '@graphql-codegen/plugin-helpers';\nimport * as addPlugin from '@graphql-codegen/add';\nimport * as typescriptPlugin from '@graphql-codegen/typescript';\nimport * as typescriptOperationPlugin from '@graphql-codegen/typescript-operations';\nimport {processSources} from './sources.js';\nimport {\n plugin as dtsPlugin,\n GENERATED_MUTATION_INTERFACE_NAME,\n GENERATED_QUERY_INTERFACE_NAME,\n} from './plugin.js';\n\nexport type HydrogenPresetConfig = {\n /**\n * Name for the variable that contains the imported types.\n * @default 'StorefrontAPI'\n */\n namespacedImportName?: string;\n /**\n * Module to import the types from.\n * @default '@shopify/hydrogen/storefront-api-types'\n */\n importTypesFrom?: string;\n /**\n * Whether types should be imported from the `importTypesFrom` module, or generated inline.\n * @default true\n */\n importTypes?: boolean;\n /**\n * Whether to skip adding `__typename` to generated operation types.\n * @default true\n */\n skipTypenameInOperations?: boolean;\n /**\n * Override the default interface extension.\n */\n interfaceExtension?: (options: {\n queryType: string;\n mutationType: string;\n }) => string;\n};\n\nexport const defaultInterfaceExtensionCode = `\ndeclare module '@shopify/hydrogen' {\n interface StorefrontQueries extends ${GENERATED_QUERY_INTERFACE_NAME} {}\n interface StorefrontMutations extends ${GENERATED_MUTATION_INTERFACE_NAME} {}\n}`;\n\nexport const preset: Types.OutputPreset<HydrogenPresetConfig> = {\n buildGeneratesSection: (options) => {\n if (!options.baseOutputDir.endsWith('.d.ts')) {\n throw new Error('[hydrogen-preset] target output should be a .d.ts file');\n }\n\n if (\n options.plugins?.length > 0 &&\n Object.keys(options.plugins).some((p) => p.startsWith('typescript'))\n ) {\n throw new Error(\n '[hydrogen-preset] providing additional typescript-based `plugins` leads to duplicated generated types',\n );\n }\n\n const sourcesWithOperations = processSources(options.documents);\n const sources = sourcesWithOperations.map(({source}) => source);\n\n const importTypes = options.presetConfig.importTypes ?? true;\n const namespacedImportName =\n options.presetConfig.namespacedImportName ?? 'StorefrontAPI';\n const importTypesFrom =\n options.presetConfig.importTypesFrom ??\n '@shopify/hydrogen/storefront-api-types';\n\n const interfaceExtensionCode =\n options.presetConfig.interfaceExtension?.({\n queryType: GENERATED_QUERY_INTERFACE_NAME,\n mutationType: GENERATED_MUTATION_INTERFACE_NAME,\n }) ?? defaultInterfaceExtensionCode;\n\n const pluginMap = {\n ...options.pluginMap,\n [`add`]: addPlugin,\n [`typescript`]: typescriptPlugin,\n [`typescript-operations`]: typescriptOperationPlugin,\n [`gen-dts`]: {plugin: dtsPlugin},\n };\n\n const plugins: Array<Types.ConfiguredPlugin> = [\n // 1. Disable eslint for the generated file\n {\n [`add`]: {\n content: `/* eslint-disable eslint-comments/disable-enable-pair */\\n/* eslint-disable eslint-comments/no-unlimited-disable */\\n/* eslint-disable */`,\n },\n },\n // 2. Import all the generated API types from Hydrogen or generate all the types from the schema.\n importTypes\n ? {\n [`add`]: {\n content: `import * as ${namespacedImportName} from '${importTypesFrom}';\\n`,\n },\n }\n : {\n [`typescript`]: {\n useTypeImports: true,\n useImplementingTypes: true,\n enumsAsTypes: true,\n },\n },\n // 3. Generate the operations (i.e. queries, mutations, and fragments types)\n {\n [`typescript-operations`]: {\n useTypeImports: true, // Use `import type` instead of `import`\n preResolveTypes: false, // Use Pick<...> instead of primitives\n mergeFragmentTypes: true, // Merge equal fragment interfaces. Avoids adding `| {}` to Metaobject\n skipTypename: options.presetConfig.skipTypenameInOperations ?? true, // Skip __typename fields\n namespacedImportName: importTypes ? namespacedImportName : undefined,\n },\n },\n // 4. Augment Hydrogen query/mutation interfaces with the generated operations\n {[`gen-dts`]: {sourcesWithOperations, interfaceExtensionCode}},\n // 5. Custom plugins from the user\n ...options.plugins,\n ];\n\n return [\n {\n filename: options.baseOutputDir,\n plugins,\n pluginMap,\n schema: options.schema,\n config: {\n // For the TS plugin:\n defaultScalarType: 'unknown',\n // Allow overwriting defaults:\n ...options.config,\n },\n documents: sources,\n documentTransforms: options.documentTransforms,\n },\n ];\n },\n};\n"]}
|
package/dist/esm/schema.js
CHANGED
package/dist/esm/schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/schema.ts"],"names":[],"mappings":"AACA;AACO,MAAM,YAAY,
|
|
1
|
+
{"version":3,"sources":["../../src/schema.ts"],"names":[],"mappings":"AACA;AACO,MAAM,YAAY,MACvB,gBAAgB,gDAAgD;AAElE,IAAI,eAAe;AAEnB,IAAI;AACF,iBAAe,UAAU;AAC3B,SAAS,OAAO;AAIhB;AAEO,MAAM,SAAS","sourcesContent":["// This comment is used during ESM build:\n//! import {createRequire} from 'module'; const require = createRequire(import.meta.url);\nexport const getSchema = () =>\n require.resolve('@shopify/hydrogen-react/storefront.schema.json');\n\nlet staticSchema = '';\n\ntry {\n staticSchema = getSchema();\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\nexport const schema = staticSchema;\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.0
|
|
7
|
+
"version": "0.1.0",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"type": "module",
|
|
10
10
|
"main": "dist/cjs/index.cjs",
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"types": "dist/esm/index.d.ts",
|
|
13
13
|
"sideEffects": false,
|
|
14
14
|
"scripts": {
|
|
15
|
-
"build": "tsup --clean
|
|
16
|
-
"dev": "tsup --watch
|
|
15
|
+
"build": "tsup --clean",
|
|
16
|
+
"dev": "tsup --watch",
|
|
17
17
|
"typecheck": "tsc --noEmit",
|
|
18
18
|
"test": "cross-env SHOPIFY_UNIT_TEST=1 vitest run",
|
|
19
19
|
"test:watch": "cross-env SHOPIFY_UNIT_TEST=1 vitest"
|
|
@@ -25,6 +25,12 @@
|
|
|
25
25
|
"import": "./dist/esm/index.js",
|
|
26
26
|
"default": "./dist/esm/index.js"
|
|
27
27
|
},
|
|
28
|
+
"./patch": {
|
|
29
|
+
"types": "./dist/esm/patch.d.ts",
|
|
30
|
+
"require": "./dist/cjs/patch.cjs",
|
|
31
|
+
"import": "./dist/esm/patch.js",
|
|
32
|
+
"default": "./dist/esm/patch.js"
|
|
33
|
+
},
|
|
28
34
|
"./package.json": "./package.json"
|
|
29
35
|
},
|
|
30
36
|
"repository": {
|
|
@@ -37,13 +43,15 @@
|
|
|
37
43
|
"vendor"
|
|
38
44
|
],
|
|
39
45
|
"devDependencies": {
|
|
40
|
-
"@graphql-codegen/cli": "
|
|
41
|
-
"@graphql-codegen/plugin-helpers": "^
|
|
42
|
-
"@graphql-tools/utils": "^
|
|
46
|
+
"@graphql-codegen/cli": "^5.0.0",
|
|
47
|
+
"@graphql-codegen/plugin-helpers": "^5.0.0",
|
|
48
|
+
"@graphql-tools/utils": "^10.0.3",
|
|
49
|
+
"vitest": "^0.33.0"
|
|
43
50
|
},
|
|
44
51
|
"dependencies": {
|
|
45
|
-
"@graphql-codegen/add": "^
|
|
46
|
-
"@graphql-codegen/typescript
|
|
52
|
+
"@graphql-codegen/add": "^5.0.0",
|
|
53
|
+
"@graphql-codegen/typescript": "^4.0.1",
|
|
54
|
+
"@graphql-codegen/typescript-operations": "^4.0.1"
|
|
47
55
|
},
|
|
48
56
|
"peerDependencies": {
|
|
49
57
|
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
Object.defineProperty(exports, '__esModule', {value: true});
|
|
3
|
-
const utils_js_1 = require('./utils.js');
|
|
4
3
|
const types_1 = require('@babel/types');
|
|
5
4
|
const utils_1 = require('@graphql-tools/utils');
|
|
5
|
+
const utils_js_1 = require('./utils.js');
|
|
6
6
|
const defaults = {
|
|
7
7
|
modules: [
|
|
8
8
|
{
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {freeText} from './utils.js';
|
|
2
1
|
import {
|
|
3
|
-
isVariableDeclarator,
|
|
4
2
|
isIdentifier,
|
|
5
|
-
isTemplateLiteral,
|
|
6
3
|
isImportDefaultSpecifier,
|
|
7
4
|
isImportSpecifier,
|
|
5
|
+
isTemplateLiteral,
|
|
8
6
|
isTSAsExpression,
|
|
9
7
|
isTSTypeReference,
|
|
8
|
+
isVariableDeclarator,
|
|
10
9
|
} from '@babel/types';
|
|
11
10
|
import {asArray} from '@graphql-tools/utils';
|
|
11
|
+
import {freeText} from './utils.js';
|
|
12
12
|
const defaults = {
|
|
13
13
|
modules: [
|
|
14
14
|
{
|