@shopify/hydrogen-codegen 0.0.0-next-112ac42-20230517085234
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 +40 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/pluck.cjs +49 -0
- package/dist/cjs/pluck.cjs.map +1 -0
- package/dist/cjs/plugin.cjs +74 -0
- package/dist/cjs/plugin.cjs.map +1 -0
- package/dist/cjs/preset.cjs +98 -0
- package/dist/cjs/preset.cjs.map +1 -0
- package/dist/cjs/schema.cjs +19 -0
- package/dist/cjs/schema.cjs.map +1 -0
- package/dist/cjs/sources.cjs +43 -0
- package/dist/cjs/sources.cjs.map +1 -0
- package/dist/esm/index.d.ts +8 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/pluck.d.ts +23 -0
- package/dist/esm/pluck.js +46 -0
- package/dist/esm/pluck.js.map +1 -0
- package/dist/esm/plugin.d.ts +18 -0
- package/dist/esm/plugin.js +72 -0
- package/dist/esm/plugin.js.map +1 -0
- package/dist/esm/preset.d.ts +8 -0
- package/dist/esm/preset.js +74 -0
- package/dist/esm/preset.js.map +1 -0
- package/dist/esm/schema.d.ts +4 -0
- package/dist/esm/schema.js +16 -0
- package/dist/esm/schema.js.map +1 -0
- package/dist/esm/sources.d.ts +8 -0
- package/dist/esm/sources.js +41 -0
- package/dist/esm/sources.js.map +1 -0
- package/package.json +51 -0
- package/vendor/graphql-tag-pluck/visitor.cjs +377 -0
- package/vendor/graphql-tag-pluck/visitor.mjs +383 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var preset_js = require('./preset.cjs');
|
|
4
|
+
var plugin_js = require('./plugin.cjs');
|
|
5
|
+
var schema_js = require('./schema.cjs');
|
|
6
|
+
var sources_js = require('./sources.cjs');
|
|
7
|
+
var pluck_js = require('./pluck.cjs');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
Object.defineProperty(exports, 'preset', {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () { return preset_js.preset; }
|
|
14
|
+
});
|
|
15
|
+
Object.defineProperty(exports, 'plugin', {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () { return plugin_js.plugin; }
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports, 'getSchema', {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () { return schema_js.getSchema; }
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports, 'schema', {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function () { return schema_js.schema; }
|
|
26
|
+
});
|
|
27
|
+
Object.defineProperty(exports, 'processSources', {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
get: function () { return sources_js.processSources; }
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(exports, 'patchGqlPluck', {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function () { return pluck_js.patchGqlPluck; }
|
|
34
|
+
});
|
|
35
|
+
Object.defineProperty(exports, 'pluckConfig', {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
get: function () { return pluck_js.pluckConfig; }
|
|
38
|
+
});
|
|
39
|
+
//# sourceMappingURL=out.js.map
|
|
40
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +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,aAAa,qBAAoB","sourcesContent":["export {preset} from './preset.js';\nexport {plugin} from './plugin.js';\nexport {schema, getSchema} from './schema.js';\nexport {processSources} from './sources.js';\nexport {pluckConfig, patchGqlPluck} from './pluck.js';\n"]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use strict';
|
|
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
|
+
const pluckConfig = {
|
|
25
|
+
isGqlTemplateLiteral: (node, options) => {
|
|
26
|
+
const hasInternalGqlComment = node.type === "TemplateLiteral" && /\s*#graphql\s*\n/i.test(node.quasis[0]?.value?.raw || "");
|
|
27
|
+
if (hasInternalGqlComment)
|
|
28
|
+
return true;
|
|
29
|
+
const { leadingComments } = node;
|
|
30
|
+
const leadingComment = leadingComments?.[leadingComments?.length - 1];
|
|
31
|
+
const leadingCommentValue = leadingComment?.value?.trim().toLowerCase();
|
|
32
|
+
return leadingCommentValue === options?.gqlMagicComment;
|
|
33
|
+
},
|
|
34
|
+
pluckStringFromFile: (code, { start, end, leadingComments }) => {
|
|
35
|
+
let gqlTemplate = code.slice(start + 1, end - 1).replace(/\$\{([^}]*)\}/g, (_, m1) => "#REQUIRED_VAR=" + m1).split("\\`").join("`");
|
|
36
|
+
const chunkStart = leadingComments?.[0]?.start ?? start;
|
|
37
|
+
const codeBeforeNode = code.slice(0, chunkStart);
|
|
38
|
+
const [, varName] = codeBeforeNode.match(/\s(\w+)\s*=\s*$/) || [];
|
|
39
|
+
if (varName) {
|
|
40
|
+
gqlTemplate += "#VAR_NAME=" + varName;
|
|
41
|
+
}
|
|
42
|
+
return gqlTemplate;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
exports.patchGqlPluck = patchGqlPluck;
|
|
47
|
+
exports.pluckConfig = pluckConfig;
|
|
48
|
+
//# sourceMappingURL=out.js.map
|
|
49
|
+
//# sourceMappingURL=pluck.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/pluck.ts"],"names":["require"],"mappings":"AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,SAAQ,qBAAoB;AAC5B,SAAQ,qBAAoB;AAE5B,eAAsB,gBAAgB;AACpC,QAAMA,WAAU,cAAc,YAAY,GAAG;AAC7C,QAAM,kBAAkBA,SAAQ,QAAQ,kCAAkC;AAG1E,QAAM,QAAQ,KAAK,QAAQ,YAAY,GAAG,MAAM,QAAQ,QAAQ;AAChE,QAAM,oBAAoB;AAAA,IACxB,IAAI,IAAI,QAAQ,6BAA6B,YAAY,GAAG;AAAA,EAC9D;AAGA,QAAM,GAAG;AAAA,IACP,KAAK,KAAK,mBAAmB,aAAa;AAAA,IAC1C,gBAAgB,QAAQ,cAAc,YAAY;AAAA,EACpD;AAEA,QAAM,GAAG;AAAA,IACP,KAAK,KAAK,mBAAmB,aAAa;AAAA,IAC1C,gBAAgB,QAAQ,OAAO,KAAK,EAAE,QAAQ,cAAc,YAAY;AAAA,EAC1E;AACF;AAMO,MAAM,cAAc;AAAA,EAKzB,sBAAsB,CAAC,MAAW,YAAiB;AAEjD,UAAM,wBACJ,KAAK,SAAS,qBACd,oBAAoB,KAAK,KAAK,OAAO,IAAI,OAAO,OAAO,EAAE;AAE3D,QAAI;AAAuB,aAAO;AAGlC,UAAM,EAAC,gBAAe,IAAI;AAC1B,UAAM,iBAAiB,kBAAkB,iBAAiB,SAAS;AACnE,UAAM,sBAAsB,gBAAgB,OAAO,KAAK,EAAE,YAAY;AAEtE,WAAO,wBAAwB,SAAS;AAAA,EAC1C;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,IAAI,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":["import fs from 'fs/promises';\nimport path from 'path';\nimport {createRequire} from 'node:module';\nimport {fileURLToPath} from 'node:url';\n\nexport async function patchGqlPluck() {\n const require = createRequire(import.meta.url);\n const 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\n const depth = path.extname(import.meta.url) === '.ts' ? '../' : '../../';\n const 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\n await fs.copyFile(\n path.join(vendorGqlTagPluck, 'visitor.cjs'),\n realGqlTagPluck.replace(/index\\.js$/, 'visitor.js'),\n );\n\n await fs.copyFile(\n path.join(vendorGqlTagPluck, 'visitor.mjs'),\n realGqlTagPluck.replace('cjs', 'esm').replace(/index\\.js$/, 'visitor.js'),\n );\n}\n\n/**\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"]}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const plugin = (_, __, { sourcesWithOperations, interfaceExtensionCode }, _info) => {
|
|
4
|
+
const code = getDocumentRegistryChunk(sourcesWithOperations);
|
|
5
|
+
code.push(interfaceExtensionCode);
|
|
6
|
+
return code.join("") + "\n";
|
|
7
|
+
};
|
|
8
|
+
const isMutationRE = /(^|}\s|\n\s*)mutation[\s({]/im;
|
|
9
|
+
const normalizeOperation = (rawSDL, variablesMap) => {
|
|
10
|
+
let variableNotFound = false;
|
|
11
|
+
while (/#REQUIRED_VAR=/.test(rawSDL) && !variableNotFound) {
|
|
12
|
+
let requiredVariables = rawSDL.matchAll(/#REQUIRED_VAR=(\w+)/g);
|
|
13
|
+
for (const [match, variableName] of requiredVariables) {
|
|
14
|
+
if (variablesMap.has(variableName)) {
|
|
15
|
+
rawSDL = rawSDL.replace(match, variablesMap.get(variableName));
|
|
16
|
+
} else {
|
|
17
|
+
variableNotFound = true;
|
|
18
|
+
console.error(
|
|
19
|
+
new Error(
|
|
20
|
+
`Variable "${variableName}" not found. This might be a bug in hydrogen-codegen, please report it.`
|
|
21
|
+
)
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return rawSDL;
|
|
27
|
+
};
|
|
28
|
+
const buildTypeLines = (name, operations) => {
|
|
29
|
+
const lines = [`interface Generated${name} {
|
|
30
|
+
`];
|
|
31
|
+
for (const [originalString, typeNames] of operations) {
|
|
32
|
+
lines.push(
|
|
33
|
+
` ${JSON.stringify(originalString)}: {return: ${typeNames.length === 1 ? typeNames[0] : "never"}, variables: ${typeNames.map((n) => n + "Variables").join(" & ")}},
|
|
34
|
+
`
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
lines.push(`}
|
|
38
|
+
`);
|
|
39
|
+
return lines;
|
|
40
|
+
};
|
|
41
|
+
function getDocumentRegistryChunk(sourcesWithOperations = []) {
|
|
42
|
+
const queries = /* @__PURE__ */ new Map();
|
|
43
|
+
const mutations = /* @__PURE__ */ new Map();
|
|
44
|
+
const variablesMap = /* @__PURE__ */ new Map();
|
|
45
|
+
for (const { source } of sourcesWithOperations) {
|
|
46
|
+
const variableName = source.rawSDL?.match(/#VAR_NAME=(\w+)/)?.[1];
|
|
47
|
+
if (variableName) {
|
|
48
|
+
source.rawSDL = source.rawSDL.replace(/#VAR_NAME=\w+$/, "");
|
|
49
|
+
variablesMap.set(variableName, source.rawSDL);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
for (const { operations, source } of sourcesWithOperations) {
|
|
53
|
+
const actualOperations = operations.filter(
|
|
54
|
+
(op) => op.definition.kind === "OperationDefinition"
|
|
55
|
+
);
|
|
56
|
+
if (actualOperations.length === 0)
|
|
57
|
+
continue;
|
|
58
|
+
const sdlString = source.rawSDL;
|
|
59
|
+
const target = isMutationRE.test(sdlString) ? mutations : queries;
|
|
60
|
+
target.set(
|
|
61
|
+
normalizeOperation(sdlString, variablesMap),
|
|
62
|
+
actualOperations.map((o) => o.initialName)
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
return [
|
|
66
|
+
...buildTypeLines("QueryTypes", queries),
|
|
67
|
+
"\n",
|
|
68
|
+
...buildTypeLines("MutationTypes", mutations)
|
|
69
|
+
];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
exports.plugin = plugin;
|
|
73
|
+
//# sourceMappingURL=out.js.map
|
|
74
|
+
//# sourceMappingURL=plugin.cjs.map
|
|
@@ -0,0 +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;AAEA,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;AAAA,UACf;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAEA,MAAM,iBAAiB,CAAC,MAAc,eAAsC;AAC1E,QAAM,QAAQ,CAAC,sBAAsB;AAAA,CAAU;AAE/C,aAAW,CAAC,gBAAgB,SAAS,KAAK,YAAY;AACpD,UAAM;AAAA,MACJ,KAAK,KAAK,UAAU,cAAc,eAIhC,UAAU,WAAW,IAAI,UAAU,KAAK,uBAC1B,UAAU,IAAI,CAAC,MAAM,IAAI,WAAW,EAAE,KAAK,KAAK;AAAA;AAAA,IAClE;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;AAC/D,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,cAAc,OAAO;AAAA,IACvC;AAAA,IACA,GAAG,eAAe,iBAAiB,SAAS;AAAA,EAC9C;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\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 Generated${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('QueryTypes', queries),\n '\\n',\n ...buildTypeLines('MutationTypes', mutations),\n ];\n}\n"]}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var addPlugin = require('@graphql-codegen/add');
|
|
4
|
+
var typescriptOperationPlugin = require('@graphql-codegen/typescript-operations');
|
|
5
|
+
var sources_js = require('./sources.cjs');
|
|
6
|
+
var plugin_js = require('./plugin.cjs');
|
|
7
|
+
var schema_js = require('./schema.cjs');
|
|
8
|
+
|
|
9
|
+
function _interopNamespaceDefault(e) {
|
|
10
|
+
var n = Object.create(null);
|
|
11
|
+
if (e) {
|
|
12
|
+
Object.keys(e).forEach(function (k) {
|
|
13
|
+
if (k !== 'default') {
|
|
14
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
15
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () { return e[k]; }
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
n.default = e;
|
|
23
|
+
return Object.freeze(n);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
var addPlugin__namespace = /*#__PURE__*/_interopNamespaceDefault(addPlugin);
|
|
27
|
+
var typescriptOperationPlugin__namespace = /*#__PURE__*/_interopNamespaceDefault(typescriptOperationPlugin);
|
|
28
|
+
|
|
29
|
+
const namespacedImportName = "StorefrontAPI";
|
|
30
|
+
const interfaceExtensionCode = `
|
|
31
|
+
declare module '@shopify/hydrogen' {
|
|
32
|
+
interface QueryTypes extends GeneratedQueryTypes {}
|
|
33
|
+
interface MutationTypes extends GeneratedMutationTypes {}
|
|
34
|
+
}`;
|
|
35
|
+
const preset = {
|
|
36
|
+
buildGeneratesSection: (options) => {
|
|
37
|
+
if (!options.baseOutputDir.endsWith(".d.ts")) {
|
|
38
|
+
throw new Error("[hydrogen-preset] target output should be a .d.ts file");
|
|
39
|
+
}
|
|
40
|
+
if (options.plugins?.length > 0 && Object.keys(options.plugins).some((p) => p.startsWith("typescript"))) {
|
|
41
|
+
throw new Error(
|
|
42
|
+
"[hydrogen-preset] providing additional typescript-based `plugins` leads to duplicated generated types"
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
const sourcesWithOperations = sources_js.processSources(options.documents);
|
|
46
|
+
const sources = sourcesWithOperations.map(({ source }) => source);
|
|
47
|
+
const pluginMap = {
|
|
48
|
+
...options.pluginMap,
|
|
49
|
+
[`add`]: addPlugin__namespace,
|
|
50
|
+
[`typescript-operations`]: typescriptOperationPlugin__namespace,
|
|
51
|
+
[`gen-dts`]: { plugin: plugin_js.plugin }
|
|
52
|
+
};
|
|
53
|
+
const plugins = [
|
|
54
|
+
{
|
|
55
|
+
[`add`]: {
|
|
56
|
+
content: `/* eslint-disable eslint-comments/disable-enable-pair */
|
|
57
|
+
/* eslint-disable eslint-comments/no-unlimited-disable */
|
|
58
|
+
/* eslint-disable */`
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
[`add`]: {
|
|
63
|
+
content: `import * as ${namespacedImportName} from '@shopify/hydrogen/storefront-api-types';
|
|
64
|
+
`
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
[`typescript-operations`]: {
|
|
69
|
+
skipTypename: true,
|
|
70
|
+
useTypeImports: true,
|
|
71
|
+
preResolveTypes: false
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
{ [`gen-dts`]: { sourcesWithOperations, interfaceExtensionCode } },
|
|
75
|
+
...options.plugins
|
|
76
|
+
];
|
|
77
|
+
return [
|
|
78
|
+
{
|
|
79
|
+
filename: options.baseOutputDir,
|
|
80
|
+
plugins,
|
|
81
|
+
pluginMap,
|
|
82
|
+
schema: options.schema || schema_js.getSchema(),
|
|
83
|
+
config: {
|
|
84
|
+
...options.config,
|
|
85
|
+
namespacedImportName
|
|
86
|
+
},
|
|
87
|
+
documents: sources,
|
|
88
|
+
documentTransforms: options.documentTransforms
|
|
89
|
+
}
|
|
90
|
+
];
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
exports.interfaceExtensionCode = interfaceExtensionCode;
|
|
95
|
+
exports.namespacedImportName = namespacedImportName;
|
|
96
|
+
exports.preset = preset;
|
|
97
|
+
//# sourceMappingURL=out.js.map
|
|
98
|
+
//# sourceMappingURL=preset.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/preset.ts"],"names":[],"mappings":"AACA,YAAY,eAAe;AAC3B,YAAY,+BAA+B;AAC3C,SAAQ,sBAAqB;AAC7B,SAAQ,UAAU,iBAAgB;AAClC,SAAQ,iBAAgB;AAIjB,MAAM,uBAAuB;AAE7B,MAAM,yBAAyB;AAAA;AAAA;AAAA;AAAA;AAM/B,MAAM,SAA2C;AAAA,EACtD,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,YAAY;AAAA,MAChB,GAAG,QAAQ;AAAA,MACX,CAAC,QAAQ;AAAA,MACT,CAAC,0BAA0B;AAAA,MAC3B,CAAC,YAAY,EAAC,QAAQ,UAAS;AAAA,IACjC;AAEA,UAAM,UAAyC;AAAA,MAE7C;AAAA,QACE,CAAC,QAAQ;AAAA,UACP,SAAS;AAAA;AAAA;AAAA,QACX;AAAA,MACF;AAAA,MAEA;AAAA,QACE,CAAC,QAAQ;AAAA,UACP,SAAS,eAAe;AAAA;AAAA,QAC1B;AAAA,MACF;AAAA,MAEA;AAAA,QACE,CAAC,0BAA0B;AAAA,UACzB,cAAc;AAAA,UACd,gBAAgB;AAAA,UAChB,iBAAiB;AAAA,QACnB;AAAA,MACF;AAAA,MAEA,EAAC,CAAC,YAAY,EAAC,uBAAuB,uBAAsB,EAAC;AAAA,MAE7D,GAAG,QAAQ;AAAA,IACb;AAEA,WAAO;AAAA,MACL;AAAA,QACE,UAAU,QAAQ;AAAA,QAClB;AAAA,QACA;AAAA,QACA,QAAQ,QAAQ,UAAU,UAAU;AAAA,QACpC,QAAQ;AAAA,UACN,GAAG,QAAQ;AAAA,UAEX;AAAA,QACF;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 typescriptOperationPlugin from '@graphql-codegen/typescript-operations';\nimport {processSources} from './sources.js';\nimport {plugin as dtsPlugin} from './plugin.js';\nimport {getSchema} from './schema.js';\n\nexport type GqlTagConfig = {};\n\nexport const namespacedImportName = 'StorefrontAPI';\n\nexport const interfaceExtensionCode = `\ndeclare module '@shopify/hydrogen' {\n interface QueryTypes extends GeneratedQueryTypes {}\n interface MutationTypes extends GeneratedMutationTypes {}\n}`;\n\nexport const preset: Types.OutputPreset<GqlTagConfig> = {\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 pluginMap = {\n ...options.pluginMap,\n [`add`]: addPlugin,\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\n {\n [`add`]: {\n content: `import * as ${namespacedImportName} from '@shopify/hydrogen/storefront-api-types';\\n`,\n },\n },\n // 3. Generate the operations (i.e. queries, mutations, and fragments types)\n {\n [`typescript-operations`]: {\n skipTypename: true, // Skip __typename fields\n useTypeImports: true, // Use `import type` instead of `import`\n preResolveTypes: false, // Use Pick<...> instead of primitives\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 || getSchema(),\n config: {\n ...options.config,\n // This is for the operations plugin\n namespacedImportName,\n },\n documents: sources,\n documentTransforms: options.documentTransforms,\n },\n ];\n },\n};\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
//! import {createRequire} from 'module'; const require = createRequire(import.meta.url);
|
|
4
|
+
const getSchema = () => require.resolve("@shopify/hydrogen-react/storefront.schema.json");
|
|
5
|
+
let staticSchema = "";
|
|
6
|
+
try {
|
|
7
|
+
staticSchema = getSchema();
|
|
8
|
+
} catch (error) {
|
|
9
|
+
console.warn(
|
|
10
|
+
"[hydrogen-codegen] storefront.schema.json not found. Is `@shopify/hydrogen` installed?\n",
|
|
11
|
+
error.message
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
const schema = staticSchema;
|
|
15
|
+
|
|
16
|
+
exports.getSchema = getSchema;
|
|
17
|
+
exports.schema = schema;
|
|
18
|
+
//# sourceMappingURL=out.js.map
|
|
19
|
+
//# sourceMappingURL=schema.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/schema.ts"],"names":[],"mappings":"AACA;AACO,MAAM,YAAY,MACP;AAElB,IAAI,eAAe;AAEnB,IAAI;AACF,iBAAe,UAAU;AAC3B,SAAS,OAAP;AAGA,UAAQ;AAAA,IACN;AAAA,IACC,MAAgB;AAAA,EACnB;AACF;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 console.warn(\n '[hydrogen-codegen] storefront.schema.json not found. Is `@shopify/hydrogen` installed?\\n',\n (error as Error).message,\n );\n}\n\nexport const schema = staticSchema;\n"]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const capitalize = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
4
|
+
const capitalizeQueries = (node) => {
|
|
5
|
+
if (node.kind === "FragmentDefinition") {
|
|
6
|
+
return "not used";
|
|
7
|
+
}
|
|
8
|
+
return capitalize(node.name.value) + capitalize(node.operation);
|
|
9
|
+
};
|
|
10
|
+
function processSources(sources, buildName = capitalizeQueries) {
|
|
11
|
+
const sourcesWithOperations = [];
|
|
12
|
+
for (const originalSource of sources) {
|
|
13
|
+
const source = fixLinebreaks(originalSource);
|
|
14
|
+
const { document } = source;
|
|
15
|
+
const operations = [];
|
|
16
|
+
for (const definition of document?.definitions ?? []) {
|
|
17
|
+
if (definition?.kind !== "OperationDefinition" && definition?.kind !== "FragmentDefinition")
|
|
18
|
+
continue;
|
|
19
|
+
if (definition.name?.kind !== `Name`)
|
|
20
|
+
continue;
|
|
21
|
+
operations.push({
|
|
22
|
+
initialName: buildName(definition),
|
|
23
|
+
definition
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
if (operations.length === 0)
|
|
27
|
+
continue;
|
|
28
|
+
sourcesWithOperations.push({
|
|
29
|
+
source,
|
|
30
|
+
operations
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return sourcesWithOperations;
|
|
34
|
+
}
|
|
35
|
+
function fixLinebreaks(source) {
|
|
36
|
+
const fixedSource = { ...source };
|
|
37
|
+
fixedSource.rawSDL = source.rawSDL?.replace(/\r\n/g, "\n");
|
|
38
|
+
return fixedSource;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
exports.processSources = processSources;
|
|
42
|
+
//# sourceMappingURL=out.js.map
|
|
43
|
+
//# sourceMappingURL=sources.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/sources.ts"],"names":[],"mappings":"AAIA,MAAM,aAAa,CAAC,QAAgB,IAAI,OAAO,CAAC,EAAE,YAAY,IAAI,IAAI,MAAM,CAAC;AAE7E,MAAM,oBAAoB,CACxB,SACG;AACH,MAAI,KAAK,SAAS,sBAAsB;AACtC,WAAO;AAAA,EACT;AAKA,SAAO,WAAW,KAAK,KAAM,KAAK,IAAI,WAAW,KAAK,SAAS;AACjE;AAEO,SAAS,eACd,SACA,YAAY,mBACZ;AACA,QAAM,wBAAqD,CAAC;AAE5D,aAAW,kBAAkB,SAAS;AACpC,UAAM,SAAS,cAAc,cAAc;AAC3C,UAAM,EAAC,SAAQ,IAAI;AACnB,UAAM,aAAyC,CAAC;AAEhD,eAAW,cAAc,UAAU,eAAe,CAAC,GAAG;AACpD,UACE,YAAY,SAAS,yBACrB,YAAY,SAAS;AAErB;AAEF,UAAI,WAAW,MAAM,SAAS;AAAQ;AAEtC,iBAAW,KAAK;AAAA,QACd,aAAa,UAAU,UAAU;AAAA,QACjC;AAAA,MACF,CAAC;AAAA,IACH;AAEA,QAAI,WAAW,WAAW;AAAG;AAE7B,0BAAsB,KAAK;AAAA,MACzB;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO;AACT;AA6CA,SAAS,cAAc,QAAgB;AACrC,QAAM,cAAc,EAAC,GAAG,OAAM;AAE9B,cAAY,SAAS,OAAO,QAAQ,QAAQ,SAAS,IAAI;AAEzD,SAAO;AACT","sourcesContent":["import type {OperationOrFragment, SourceWithOperations} from './plugin.js';\nimport type {Source} from '@graphql-tools/utils';\nimport type {FragmentDefinitionNode, OperationDefinitionNode} from 'graphql';\n\nconst capitalize = (str: string) => str.charAt(0).toUpperCase() + str.slice(1);\n\nconst capitalizeQueries = (\n node: OperationDefinitionNode | FragmentDefinitionNode,\n) => {\n if (node.kind === 'FragmentDefinition') {\n return 'not used';\n }\n\n // Match the names generated by typescript-operations plugin:\n // e.g. 'query Hello {...}' => HelloQuery\n // -- Anonymous queries are not supported.\n return capitalize(node.name!.value) + capitalize(node.operation);\n};\n\nexport function processSources(\n sources: Array<Source>,\n buildName = capitalizeQueries,\n) {\n const sourcesWithOperations: Array<SourceWithOperations> = [];\n\n for (const originalSource of sources) {\n const source = fixLinebreaks(originalSource);\n const {document} = source;\n const operations: Array<OperationOrFragment> = [];\n\n for (const definition of document?.definitions ?? []) {\n if (\n definition?.kind !== 'OperationDefinition' &&\n definition?.kind !== 'FragmentDefinition'\n )\n continue;\n\n if (definition.name?.kind !== `Name`) continue;\n\n operations.push({\n initialName: buildName(definition),\n definition,\n });\n }\n\n if (operations.length === 0) continue;\n\n sourcesWithOperations.push({\n source,\n operations,\n });\n }\n\n return sourcesWithOperations;\n}\n\n/**\n * https://github.com/dotansimha/graphql-code-generator/issues/7362\n *\n * Source file is read by @graphql/tools using fs.promises.readFile,\n * which means that the linebreaks are read as-is and the result will be different\n * depending on the OS: it will contain LF (\\n) on Linux/MacOS and CRLF (\\r\\n) on Windows.\n *\n * In most scenarios that would be OK. However, gql-tag-operation is using the resulting string\n * as a TypeScript type. Which means that the string will be compared against a template literal,\n * for example:\n *\n * <pre><code>\n * `\n * query a {\n * a\n * }\n * ` === '\\n query a {\\n a\\n }\\n '\n * </code></pre>\n *\n * According to clause 12.8.6.2 of ECMAScript Language Specification\n * (https://tc39.es/ecma262/#sec-static-semantics-trv),\n * when comparing strings, JavaScript doesn't care which linebreaks does the source file contain,\n * any linebreak (CR, LF or CRLF) is LF from JavaScript standpoint\n * (otherwise the result of the above comparison would be OS-dependent, which doesn't make sense).\n *\n * Therefore gql-tag-operation would break on Windows as it would generate\n *\n * '\\r\\n query a {\\r\\n a\\r\\n }\\r\\n '\n *\n * which is NOT equal to\n *\n * <pre><code>\n * `\n * query a {\n * a\n * }\n * `\n * </code></pre>\n *\n * Therefore we need to replace \\r\\n with \\n in the string.\n *\n * @param source\n */\nfunction fixLinebreaks(source: Source) {\n const fixedSource = {...source};\n\n fixedSource.rawSDL = source.rawSDL?.replace(/\\r\\n/g, '\\n');\n\n return fixedSource;\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { preset } from './preset.js';
|
|
2
|
+
export { plugin } from './plugin.js';
|
|
3
|
+
export { getSchema, schema } from './schema.js';
|
|
4
|
+
export { processSources } from './sources.js';
|
|
5
|
+
export { patchGqlPluck, pluckConfig } from './pluck.js';
|
|
6
|
+
import '@graphql-codegen/plugin-helpers';
|
|
7
|
+
import '@graphql-tools/utils';
|
|
8
|
+
import 'graphql';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { preset } from './preset.js';
|
|
2
|
+
export { plugin } from './plugin.js';
|
|
3
|
+
export { getSchema, schema } from './schema.js';
|
|
4
|
+
export { processSources } from './sources.js';
|
|
5
|
+
export { patchGqlPluck, pluckConfig } from './pluck.js';
|
|
6
|
+
//# sourceMappingURL=out.js.map
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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,aAAa,qBAAoB","sourcesContent":["export {preset} from './preset.js';\nexport {plugin} from './plugin.js';\nexport {schema, getSchema} from './schema.js';\nexport {processSources} from './sources.js';\nexport {pluckConfig, patchGqlPluck} from './pluck.js';\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
declare function patchGqlPluck(): Promise<void>;
|
|
2
|
+
/**
|
|
3
|
+
* This is a modified version of graphql-tag-pluck's default config.
|
|
4
|
+
* https://github.com/ardatan/graphql-tools/issues/5127
|
|
5
|
+
*/
|
|
6
|
+
declare const pluckConfig: {
|
|
7
|
+
/**
|
|
8
|
+
* Hook to determine if a node is a gql template literal.
|
|
9
|
+
* By default, graphql-tag-pluck only looks for leading comments or `gql` tag.
|
|
10
|
+
*/
|
|
11
|
+
isGqlTemplateLiteral: (node: any, options: any) => boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Instruct how to extract the gql template literal from the code.
|
|
14
|
+
* By default, embedded expressions in template literals (e.g. ${foo})
|
|
15
|
+
* are removed from the template string. This hook allows us to annotate
|
|
16
|
+
* the template string with the required embedded expressions instead of
|
|
17
|
+
* removing them. Later, we can use this information to reconstruct the
|
|
18
|
+
* embedded expressions.
|
|
19
|
+
*/
|
|
20
|
+
pluckStringFromFile: (code: string, { start, end, leadingComments }: any) => string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export { patchGqlPluck, pluckConfig };
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
const pluckConfig = {
|
|
23
|
+
isGqlTemplateLiteral: (node, options) => {
|
|
24
|
+
const hasInternalGqlComment = node.type === "TemplateLiteral" && /\s*#graphql\s*\n/i.test(node.quasis[0]?.value?.raw || "");
|
|
25
|
+
if (hasInternalGqlComment)
|
|
26
|
+
return true;
|
|
27
|
+
const { leadingComments } = node;
|
|
28
|
+
const leadingComment = leadingComments?.[leadingComments?.length - 1];
|
|
29
|
+
const leadingCommentValue = leadingComment?.value?.trim().toLowerCase();
|
|
30
|
+
return leadingCommentValue === options?.gqlMagicComment;
|
|
31
|
+
},
|
|
32
|
+
pluckStringFromFile: (code, { start, end, leadingComments }) => {
|
|
33
|
+
let gqlTemplate = code.slice(start + 1, end - 1).replace(/\$\{([^}]*)\}/g, (_, m1) => "#REQUIRED_VAR=" + m1).split("\\`").join("`");
|
|
34
|
+
const chunkStart = leadingComments?.[0]?.start ?? start;
|
|
35
|
+
const codeBeforeNode = code.slice(0, chunkStart);
|
|
36
|
+
const [, varName] = codeBeforeNode.match(/\s(\w+)\s*=\s*$/) || [];
|
|
37
|
+
if (varName) {
|
|
38
|
+
gqlTemplate += "#VAR_NAME=" + varName;
|
|
39
|
+
}
|
|
40
|
+
return gqlTemplate;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export { patchGqlPluck, pluckConfig };
|
|
45
|
+
//# sourceMappingURL=out.js.map
|
|
46
|
+
//# sourceMappingURL=pluck.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/pluck.ts"],"names":["require"],"mappings":"AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,SAAQ,qBAAoB;AAC5B,SAAQ,qBAAoB;AAE5B,eAAsB,gBAAgB;AACpC,QAAMA,WAAU,cAAc,YAAY,GAAG;AAC7C,QAAM,kBAAkBA,SAAQ,QAAQ,kCAAkC;AAG1E,QAAM,QAAQ,KAAK,QAAQ,YAAY,GAAG,MAAM,QAAQ,QAAQ;AAChE,QAAM,oBAAoB;AAAA,IACxB,IAAI,IAAI,QAAQ,6BAA6B,YAAY,GAAG;AAAA,EAC9D;AAGA,QAAM,GAAG;AAAA,IACP,KAAK,KAAK,mBAAmB,aAAa;AAAA,IAC1C,gBAAgB,QAAQ,cAAc,YAAY;AAAA,EACpD;AAEA,QAAM,GAAG;AAAA,IACP,KAAK,KAAK,mBAAmB,aAAa;AAAA,IAC1C,gBAAgB,QAAQ,OAAO,KAAK,EAAE,QAAQ,cAAc,YAAY;AAAA,EAC1E;AACF;AAMO,MAAM,cAAc;AAAA,EAKzB,sBAAsB,CAAC,MAAW,YAAiB;AAEjD,UAAM,wBACJ,KAAK,SAAS,qBACd,oBAAoB,KAAK,KAAK,OAAO,IAAI,OAAO,OAAO,EAAE;AAE3D,QAAI;AAAuB,aAAO;AAGlC,UAAM,EAAC,gBAAe,IAAI;AAC1B,UAAM,iBAAiB,kBAAkB,iBAAiB,SAAS;AACnE,UAAM,sBAAsB,gBAAgB,OAAO,KAAK,EAAE,YAAY;AAEtE,WAAO,wBAAwB,SAAS;AAAA,EAC1C;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,IAAI,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":["import fs from 'fs/promises';\nimport path from 'path';\nimport {createRequire} from 'node:module';\nimport {fileURLToPath} from 'node:url';\n\nexport async function patchGqlPluck() {\n const require = createRequire(import.meta.url);\n const 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\n const depth = path.extname(import.meta.url) === '.ts' ? '../' : '../../';\n const 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\n await fs.copyFile(\n path.join(vendorGqlTagPluck, 'visitor.cjs'),\n realGqlTagPluck.replace(/index\\.js$/, 'visitor.js'),\n );\n\n await fs.copyFile(\n path.join(vendorGqlTagPluck, 'visitor.mjs'),\n realGqlTagPluck.replace('cjs', 'esm').replace(/index\\.js$/, 'visitor.js'),\n );\n}\n\n/**\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"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { PluginFunction } from '@graphql-codegen/plugin-helpers';
|
|
2
|
+
import { Source } from '@graphql-tools/utils';
|
|
3
|
+
import { OperationDefinitionNode, FragmentDefinitionNode } from 'graphql';
|
|
4
|
+
|
|
5
|
+
type OperationOrFragment = {
|
|
6
|
+
initialName: string;
|
|
7
|
+
definition: OperationDefinitionNode | FragmentDefinitionNode;
|
|
8
|
+
};
|
|
9
|
+
type SourceWithOperations = {
|
|
10
|
+
source: Source;
|
|
11
|
+
operations: Array<OperationOrFragment>;
|
|
12
|
+
};
|
|
13
|
+
declare const plugin: PluginFunction<{
|
|
14
|
+
sourcesWithOperations: Array<SourceWithOperations>;
|
|
15
|
+
interfaceExtensionCode: string;
|
|
16
|
+
}>;
|
|
17
|
+
|
|
18
|
+
export { OperationOrFragment, SourceWithOperations, plugin };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
const plugin = (_, __, { sourcesWithOperations, interfaceExtensionCode }, _info) => {
|
|
2
|
+
const code = getDocumentRegistryChunk(sourcesWithOperations);
|
|
3
|
+
code.push(interfaceExtensionCode);
|
|
4
|
+
return code.join("") + "\n";
|
|
5
|
+
};
|
|
6
|
+
const isMutationRE = /(^|}\s|\n\s*)mutation[\s({]/im;
|
|
7
|
+
const normalizeOperation = (rawSDL, variablesMap) => {
|
|
8
|
+
let variableNotFound = false;
|
|
9
|
+
while (/#REQUIRED_VAR=/.test(rawSDL) && !variableNotFound) {
|
|
10
|
+
let requiredVariables = rawSDL.matchAll(/#REQUIRED_VAR=(\w+)/g);
|
|
11
|
+
for (const [match, variableName] of requiredVariables) {
|
|
12
|
+
if (variablesMap.has(variableName)) {
|
|
13
|
+
rawSDL = rawSDL.replace(match, variablesMap.get(variableName));
|
|
14
|
+
} else {
|
|
15
|
+
variableNotFound = true;
|
|
16
|
+
console.error(
|
|
17
|
+
new Error(
|
|
18
|
+
`Variable "${variableName}" not found. This might be a bug in hydrogen-codegen, please report it.`
|
|
19
|
+
)
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return rawSDL;
|
|
25
|
+
};
|
|
26
|
+
const buildTypeLines = (name, operations) => {
|
|
27
|
+
const lines = [`interface Generated${name} {
|
|
28
|
+
`];
|
|
29
|
+
for (const [originalString, typeNames] of operations) {
|
|
30
|
+
lines.push(
|
|
31
|
+
` ${JSON.stringify(originalString)}: {return: ${typeNames.length === 1 ? typeNames[0] : "never"}, variables: ${typeNames.map((n) => n + "Variables").join(" & ")}},
|
|
32
|
+
`
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
lines.push(`}
|
|
36
|
+
`);
|
|
37
|
+
return lines;
|
|
38
|
+
};
|
|
39
|
+
function getDocumentRegistryChunk(sourcesWithOperations = []) {
|
|
40
|
+
const queries = /* @__PURE__ */ new Map();
|
|
41
|
+
const mutations = /* @__PURE__ */ new Map();
|
|
42
|
+
const variablesMap = /* @__PURE__ */ new Map();
|
|
43
|
+
for (const { source } of sourcesWithOperations) {
|
|
44
|
+
const variableName = source.rawSDL?.match(/#VAR_NAME=(\w+)/)?.[1];
|
|
45
|
+
if (variableName) {
|
|
46
|
+
source.rawSDL = source.rawSDL.replace(/#VAR_NAME=\w+$/, "");
|
|
47
|
+
variablesMap.set(variableName, source.rawSDL);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
for (const { operations, source } of sourcesWithOperations) {
|
|
51
|
+
const actualOperations = operations.filter(
|
|
52
|
+
(op) => op.definition.kind === "OperationDefinition"
|
|
53
|
+
);
|
|
54
|
+
if (actualOperations.length === 0)
|
|
55
|
+
continue;
|
|
56
|
+
const sdlString = source.rawSDL;
|
|
57
|
+
const target = isMutationRE.test(sdlString) ? mutations : queries;
|
|
58
|
+
target.set(
|
|
59
|
+
normalizeOperation(sdlString, variablesMap),
|
|
60
|
+
actualOperations.map((o) => o.initialName)
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
return [
|
|
64
|
+
...buildTypeLines("QueryTypes", queries),
|
|
65
|
+
"\n",
|
|
66
|
+
...buildTypeLines("MutationTypes", mutations)
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export { plugin };
|
|
71
|
+
//# sourceMappingURL=out.js.map
|
|
72
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +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;AAEA,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;AAAA,UACf;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAEA,MAAM,iBAAiB,CAAC,MAAc,eAAsC;AAC1E,QAAM,QAAQ,CAAC,sBAAsB;AAAA,CAAU;AAE/C,aAAW,CAAC,gBAAgB,SAAS,KAAK,YAAY;AACpD,UAAM;AAAA,MACJ,KAAK,KAAK,UAAU,cAAc,eAIhC,UAAU,WAAW,IAAI,UAAU,KAAK,uBAC1B,UAAU,IAAI,CAAC,MAAM,IAAI,WAAW,EAAE,KAAK,KAAK;AAAA;AAAA,IAClE;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;AAC/D,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,cAAc,OAAO;AAAA,IACvC;AAAA,IACA,GAAG,eAAe,iBAAiB,SAAS;AAAA,EAC9C;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\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 Generated${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('QueryTypes', queries),\n '\\n',\n ...buildTypeLines('MutationTypes', mutations),\n ];\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Types } from '@graphql-codegen/plugin-helpers';
|
|
2
|
+
|
|
3
|
+
type GqlTagConfig = {};
|
|
4
|
+
declare const namespacedImportName = "StorefrontAPI";
|
|
5
|
+
declare const interfaceExtensionCode = "\ndeclare module '@shopify/hydrogen' {\n interface QueryTypes extends GeneratedQueryTypes {}\n interface MutationTypes extends GeneratedMutationTypes {}\n}";
|
|
6
|
+
declare const preset: Types.OutputPreset<GqlTagConfig>;
|
|
7
|
+
|
|
8
|
+
export { GqlTagConfig, interfaceExtensionCode, namespacedImportName, preset };
|