@remkoj/optimizely-graph-functions 1.0.1 → 1.0.3
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/index.d.ts +19 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -1
- package/dist/preset.js +32 -3
- package/dist/preset.js.map +1 -1
- package/dist/transform.js +67 -37
- package/dist/transform.js.map +1 -1
- package/package.json +9 -11
- package/dist/src/documents.d.ts +0 -9
- package/dist/src/documents.js +0 -173
- package/dist/src/documents.js.map +0 -1
- package/dist/src/index.d.ts +0 -30
- package/dist/src/index.js +0 -138
- package/dist/src/index.js.map +0 -1
- package/dist/src/preset.d.ts +0 -7
- package/dist/src/preset.js +0 -79
- package/dist/src/preset.js.map +0 -1
- package/dist/src/transform.d.ts +0 -11
- package/dist/src/transform.js +0 -136
- package/dist/src/transform.js.map +0 -1
- package/dist/src/types.d.ts +0 -21
- package/dist/src/types.js +0 -3
- package/dist/src/types.js.map +0 -1
- package/dist/src/utils.d.ts +0 -8
- package/dist/src/utils.js +0 -38
- package/dist/src/utils.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,26 @@ export type PluginOptions = {
|
|
|
5
5
|
clientPath?: string;
|
|
6
6
|
};
|
|
7
7
|
export declare function pickPluginOptions(options: Record<string, any>): PluginOptions;
|
|
8
|
+
/**
|
|
9
|
+
* Validate the plugin configuration
|
|
10
|
+
*
|
|
11
|
+
* @param schema
|
|
12
|
+
* @param document
|
|
13
|
+
* @param config
|
|
14
|
+
* @param outputFile
|
|
15
|
+
* @param allPlugins
|
|
16
|
+
* @param pluginContext
|
|
17
|
+
*/
|
|
8
18
|
export declare const validate: PluginValidateFn<PluginOptions>;
|
|
19
|
+
/**
|
|
20
|
+
* Actual Plugin logic
|
|
21
|
+
*
|
|
22
|
+
* @param schema
|
|
23
|
+
* @param documents
|
|
24
|
+
* @param config
|
|
25
|
+
* @param info
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
9
28
|
export declare const plugin: PluginFunction<PluginOptions>;
|
|
10
29
|
declare const _default: CodegenPlugin<PluginOptions>;
|
|
11
30
|
export default _default;
|
package/dist/index.js
CHANGED
|
@@ -11,6 +11,16 @@ function pickPluginOptions(options) {
|
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
13
|
exports.pickPluginOptions = pickPluginOptions;
|
|
14
|
+
/**
|
|
15
|
+
* Validate the plugin configuration
|
|
16
|
+
*
|
|
17
|
+
* @param schema
|
|
18
|
+
* @param document
|
|
19
|
+
* @param config
|
|
20
|
+
* @param outputFile
|
|
21
|
+
* @param allPlugins
|
|
22
|
+
* @param pluginContext
|
|
23
|
+
*/
|
|
14
24
|
const validate = (schema, document, config, outputFile, allPlugins, pluginContext) => {
|
|
15
25
|
if (config.functions) {
|
|
16
26
|
if (!Array.isArray(config.functions))
|
|
@@ -20,10 +30,21 @@ const validate = (schema, document, config, outputFile, allPlugins, pluginContex
|
|
|
20
30
|
}
|
|
21
31
|
};
|
|
22
32
|
exports.validate = validate;
|
|
33
|
+
/**
|
|
34
|
+
* Actual Plugin logic
|
|
35
|
+
*
|
|
36
|
+
* @param schema
|
|
37
|
+
* @param documents
|
|
38
|
+
* @param config
|
|
39
|
+
* @param info
|
|
40
|
+
* @returns
|
|
41
|
+
*/
|
|
23
42
|
const plugin = async (schema, documents, config, info) => {
|
|
43
|
+
// Read the functions to fully build & extend
|
|
24
44
|
const functions = config.functions || [];
|
|
25
45
|
if (functions.length == 0)
|
|
26
46
|
return "// NO FUNCTIONS TO BE EXPORTED";
|
|
47
|
+
// Output the functions
|
|
27
48
|
const docs = (0, graphql_1.concatAST)(documents.map(x => x.document).filter(utils_1.isNotNullOrUndefined));
|
|
28
49
|
const output = functions.map(fn => {
|
|
29
50
|
try {
|
|
@@ -59,6 +80,7 @@ const plugin = async (schema, documents, config, info) => {
|
|
|
59
80
|
};
|
|
60
81
|
exports.plugin = plugin;
|
|
61
82
|
function resolveSpreads(definition, document, availableFragments = []) {
|
|
83
|
+
// Collect the fragment names we need to add
|
|
62
84
|
const spreadNames = [];
|
|
63
85
|
(0, graphql_1.visit)(definition, {
|
|
64
86
|
"FragmentSpread": {
|
|
@@ -68,6 +90,7 @@ function resolveSpreads(definition, document, availableFragments = []) {
|
|
|
68
90
|
}
|
|
69
91
|
}
|
|
70
92
|
});
|
|
93
|
+
// Collect these fragments from the document
|
|
71
94
|
const fragments = [];
|
|
72
95
|
(0, graphql_1.visit)(document, {
|
|
73
96
|
FragmentDefinition: {
|
|
@@ -77,10 +100,13 @@ function resolveSpreads(definition, document, availableFragments = []) {
|
|
|
77
100
|
}
|
|
78
101
|
}
|
|
79
102
|
});
|
|
103
|
+
// Recurse down the fragments to build the full query
|
|
80
104
|
const dependencies = [];
|
|
81
105
|
const availableFragmentNames = [...availableFragments, ...fragments.map(x => x.name.value)];
|
|
82
106
|
fragments.forEach(fragment => {
|
|
107
|
+
// Set the available names based on what was previously available, loaded above and loaded within this loop
|
|
83
108
|
const resolvedSpreads = [...availableFragmentNames, ...dependencies.map(x => x.name.value)];
|
|
109
|
+
// Recurse into fragments
|
|
84
110
|
const fragmentDependencies = resolveSpreads(fragment, document, resolvedSpreads);
|
|
85
111
|
dependencies.push(...fragmentDependencies);
|
|
86
112
|
});
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AACA,qCAAgK;AAChK,mCAAwE;AAQxE,SAAgB,iBAAiB,CAAC,OAA2B;IAEzD,OAAO;QACH,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,CAAE,kBAAkB,EAAE,gBAAgB,CAAE;QACxE,gBAAgB,EAAE,OAAO,CAAC,gBAAgB,IAAI,KAAK;QACnD,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,WAAW;KAChD,CAAA;AACL,CAAC;AAPD,8CAOC;
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M,WAAW,GAAG,OAAO,CAAA;QAC3B,MAAM,QAAQ,GAAG,GAAI,WAAY,IAAK,UAAW,gBAAgB,CAAA;QACjE,MAAM,UAAU,GAAG,GAAI,WAAY,IAAK,UAAW,OAAO,CAAA;QAC1D,OAAO,cAAe,EAAG,eAAgB,QAAQ,eAAgB,UAAW;;iBAE9D,EAAG;MACf,CAAA;IAAA,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;EACnB,CAAA;AACF,CAAC;AAED,kBAAe,EAAE,QAAQ,EAAR,gBAAQ,EAAE,MAAM,EAAN,cAAM,EAAkC,CAAA"}
|
package/dist/preset.js
CHANGED
|
@@ -1,15 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.preset = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
27
|
const documents_1 = require("./documents");
|
|
28
|
+
// Import base preset
|
|
6
29
|
const client_preset_1 = require("@graphql-codegen/client-preset");
|
|
7
|
-
|
|
8
|
-
const
|
|
30
|
+
// Import injected parts
|
|
31
|
+
const index_1 = __importStar(require("./index"));
|
|
32
|
+
const transform_1 = __importStar(require("./transform"));
|
|
9
33
|
exports.preset = {
|
|
10
34
|
prepareDocuments: async (outputFilePath, outputSpecificDocuments) => {
|
|
35
|
+
// Get the base documents
|
|
11
36
|
const documents = client_preset_1.preset.prepareDocuments ? await client_preset_1.preset.prepareDocuments(outputFilePath, outputSpecificDocuments) : [...outputSpecificDocuments, `!${outputFilePath}`];
|
|
37
|
+
// Then add the implicit documents to it
|
|
12
38
|
documents.push([...documents_1.fragments, ...documents_1.queries].join("\n"));
|
|
39
|
+
// Finally return the extended array
|
|
13
40
|
return documents;
|
|
14
41
|
},
|
|
15
42
|
buildGeneratesSection: async (options) => {
|
|
@@ -21,6 +48,7 @@ exports.preset = {
|
|
|
21
48
|
}
|
|
22
49
|
];
|
|
23
50
|
const section = await client_preset_1.preset.buildGeneratesSection(options);
|
|
51
|
+
// Add the functions file
|
|
24
52
|
section.push({
|
|
25
53
|
filename: `${options.baseOutputDir}functions.ts`,
|
|
26
54
|
pluginMap: {
|
|
@@ -36,6 +64,7 @@ exports.preset = {
|
|
|
36
64
|
documents: options.documents,
|
|
37
65
|
documentTransforms: options.documentTransforms
|
|
38
66
|
});
|
|
67
|
+
// Add functions to index plugin
|
|
39
68
|
section.forEach((fileConfig, idx) => {
|
|
40
69
|
if (fileConfig.filename.endsWith("index.ts")) {
|
|
41
70
|
const currentContent = section[idx].plugins[0]?.add?.content;
|
package/dist/preset.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preset.js","sourceRoot":"","sources":["../src/preset.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"preset.js","sourceRoot":"","sources":["../src/preset.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,2CAAgD;AAEhD,qBAAqB;AACrB,kEAAuH;AAEvH,wBAAwB;AACxB,iDAAuE;AACvE,yDAAoF;AAKvE,QAAA,MAAM,GACnB;IACI,gBAAgB,EAAE,KAAK,EAAE,cAAc,EAAE,uBAAuB,EAAE,EAAE;QAChE,yBAAyB;QACzB,MAAM,SAAS,GAAG,sBAAY,CAAC,gBAAgB,CAAC,CAAC,CAAC,MAAM,sBAAY,CAAC,gBAAgB,CAAC,cAAc,EAAE,uBAAuB,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,uBAAuB,EAAE,IAAI,cAAc,EAAE,CAAC,CAAA;QAEnL,wCAAwC;QACxC,SAAS,CAAC,IAAI,CAAC,CAAC,GAAG,qBAAS,EAAE,GAAG,mBAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;QAErD,oCAAoC;QACpC,OAAO,SAAS,CAAA;IACpB,CAAC;IAED,qBAAqB,EAAE,KAAK,EAAE,OAAO,EAAG,EAAE;QACtC,OAAO,CAAC,kBAAkB,GAAG;YACzB;gBACI,IAAI,EAAE,iBAAiB;gBACvB,eAAe,EAAE,mBAAS;gBAC1B,MAAM,EAAE,IAAA,gCAAoB,EAAC,OAAO,CAAC,YAAY,CAAC;aACrD;SACJ,CAAA;QAED,MAAM,OAAO,GAAG,MAAM,sBAAY,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAA;QAEjE,yBAAyB;QACzB,OAAO,CAAC,IAAI,CAAC;YACT,QAAQ,EAAE,GAAI,OAAO,CAAC,aAAc,cAAc;YAClD,SAAS,EAAE;gBACP,CAAC,iBAAiB,CAAC,EAAE,eAAM;aAC9B;YACD,OAAO,EAAE;gBACL;oBACI,CAAC,iBAAiB,CAAC,EAAE,EAAE;iBAC1B;aACJ;YACD,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,MAAM,EAAE,IAAA,yBAAiB,EAAC,OAAO,CAAC,YAAY,CAAC;YAC/C,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,kBAAkB,EAAE,OAAO,CAAC,kBAAkB;SACjD,CAAC,CAAA;QAEF,gCAAgC;QAChC,OAAO,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,GAAG,EAAE,EAAE;YAChC,IAAI,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;gBAC3C,MAAM,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,CAAA;gBAC5D,IAAI,cAAc;oBACd,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,GAAG,yCAAyC,cAAc,gCAAgC,CAAA;YACrI,CAAC;QACL,CAAC,CAAC,CAAA;QAEF,OAAO,OAAO,CAAA;IAClB,CAAC;CACJ,CAAA;AAED,kBAAe,cAAM,CAAA"}
|
package/dist/transform.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.transform = exports.pickTransformOptions = void 0;
|
|
4
7
|
const graphql_1 = require("graphql");
|
|
8
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
5
9
|
function pickTransformOptions(options) {
|
|
6
10
|
return {
|
|
7
11
|
injections: options.injections ?? []
|
|
@@ -9,8 +13,10 @@ function pickTransformOptions(options) {
|
|
|
9
13
|
}
|
|
10
14
|
exports.pickTransformOptions = pickTransformOptions;
|
|
11
15
|
function isArray(toTest) { return Array.isArray(toTest); }
|
|
12
|
-
const transform = async ({ documents: files, config }) => {
|
|
16
|
+
const transform = async ({ documents: files, config, schema }) => {
|
|
17
|
+
//console.log("[STARTED] Optimizely document transformation")
|
|
13
18
|
const injections = config.injections ?? [];
|
|
19
|
+
// Retrieve component fragments
|
|
14
20
|
const componentFragments = {};
|
|
15
21
|
files.forEach(file => {
|
|
16
22
|
if (!file.document)
|
|
@@ -19,12 +25,14 @@ const transform = async ({ documents: files, config }) => {
|
|
|
19
25
|
if (!applicableInjections || applicableInjections.length == 0)
|
|
20
26
|
return;
|
|
21
27
|
(0, graphql_1.visit)(file.document, {
|
|
22
|
-
|
|
28
|
+
FragmentDefinition: {
|
|
23
29
|
enter(node) {
|
|
30
|
+
console.log("[ DEBUG ] Visiting fragment:", node.name.value, node.typeCondition.name.value);
|
|
24
31
|
const matchingInjections = applicableInjections.filter(injection => !injection.nameRegex || (new RegExp(injection.nameRegex)).test(node.name.value));
|
|
25
32
|
if (!matchingInjections || matchingInjections.length == 0)
|
|
26
33
|
return false;
|
|
27
34
|
matchingInjections.forEach(injection => {
|
|
35
|
+
//console.log(`[ DEBUG ] Matched ${ node.name.value } for ${ injection.into } in file ${ node.loc?.source?.name }`)
|
|
28
36
|
if (!componentFragments[injection.into])
|
|
29
37
|
componentFragments[injection.into] = [];
|
|
30
38
|
if (!componentFragments[injection.into].some(f => f.name.value == node.name.value))
|
|
@@ -35,49 +43,68 @@ const transform = async ({ documents: files, config }) => {
|
|
|
35
43
|
}
|
|
36
44
|
});
|
|
37
45
|
});
|
|
46
|
+
// Get the names we actually need to inject into, and return when none are present
|
|
38
47
|
const intoNames = Object.getOwnPropertyNames(componentFragments);
|
|
39
|
-
if (intoNames.length == 0)
|
|
40
|
-
return files;
|
|
41
|
-
const recursiveFragments = ["BlockContentAreaItemSearchData", "BlockContentAreaItemData"];
|
|
42
48
|
const componentSpreads = {};
|
|
43
|
-
intoNames.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
kind
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
49
|
+
if (intoNames.length > 0) {
|
|
50
|
+
// Process the fragments, add matching spreads if need be
|
|
51
|
+
const recursiveFragments = ["BlockContentAreaItemSearchData", "BlockContentAreaItemData"];
|
|
52
|
+
intoNames.forEach(intoName => {
|
|
53
|
+
//console.log(`[ DEBUG ] Preparing mutations for ${ intoName }`)
|
|
54
|
+
componentFragments[intoName].forEach(fragment => {
|
|
55
|
+
//console.log(`[ DEBUG ] Preparing mutations for fragment ${ fragment.name.value } within ${ intoName }`)
|
|
56
|
+
(0, graphql_1.visit)(fragment, {
|
|
57
|
+
FragmentSpread: {
|
|
58
|
+
leave(node, key, parent, path, ancestors) {
|
|
59
|
+
if (recursiveFragments.includes(node.name.value) && !isArray(ancestors[0]) && ancestors[0].kind == graphql_1.Kind.FRAGMENT_DEFINITION) {
|
|
60
|
+
//console.log(`[ DEBUG ] Leaving ${ node.name.value } within ${ fragment.name.value } for ${ intoName}, creating recursive fragment`)
|
|
61
|
+
const fields = ancestors.filter(a => !isArray(a) && a.kind != graphql_1.Kind.FRAGMENT_DEFINITION && a.kind != graphql_1.Kind.SELECTION_SET);
|
|
62
|
+
if (fields.length < 1)
|
|
63
|
+
return undefined;
|
|
64
|
+
if (fields.length > 1)
|
|
65
|
+
throw new Error("Recursive items on embedded blocks are not supported at the moment");
|
|
66
|
+
const newNode = {
|
|
67
|
+
kind: graphql_1.Kind.INLINE_FRAGMENT,
|
|
68
|
+
typeCondition: ancestors[0].typeCondition,
|
|
69
|
+
selectionSet: {
|
|
70
|
+
kind: graphql_1.Kind.SELECTION_SET,
|
|
71
|
+
selections: [{
|
|
72
|
+
kind: graphql_1.Kind.FIELD,
|
|
73
|
+
name: fields[0].name,
|
|
74
|
+
alias: fields[0].alias,
|
|
75
|
+
selectionSet: {
|
|
76
|
+
kind: graphql_1.Kind.SELECTION_SET,
|
|
77
|
+
selections: recursiveSelections
|
|
78
|
+
}
|
|
79
|
+
}]
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
if (!componentSpreads[intoName])
|
|
83
|
+
componentSpreads[intoName] = [];
|
|
84
|
+
componentSpreads[intoName].push(newNode);
|
|
85
|
+
}
|
|
73
86
|
}
|
|
74
87
|
}
|
|
75
|
-
}
|
|
88
|
+
});
|
|
76
89
|
});
|
|
77
90
|
});
|
|
78
|
-
}
|
|
91
|
+
}
|
|
92
|
+
//console.log(`[ DEBUG ] Start building transformed files`)
|
|
79
93
|
const newFiles = files.map(file => {
|
|
94
|
+
//console.log(`[ DEBUG ] Entering file ${ file.location } }`)
|
|
80
95
|
const document = file.document ? (0, graphql_1.visit)(file.document, {
|
|
96
|
+
FragmentDefinition: {
|
|
97
|
+
enter(node) {
|
|
98
|
+
if (file.location && !node_fs_1.default.existsSync(file.location)) {
|
|
99
|
+
const typePresent = schema.definitions.some(definition => (definition.kind == graphql_1.Kind.OBJECT_TYPE_DEFINITION || definition.kind == graphql_1.Kind.INTERFACE_TYPE_DEFINITION) && definition.name.value == node.typeCondition.name.value);
|
|
100
|
+
//console.log(`[ DEBUG ] Entering fragment ${ node.name.value } on ${ node.typeCondition.name.value }; ${ node.typeCondition.name.value } present in schema: ${ typePresent ? 'yes' : 'no'}`)
|
|
101
|
+
if (!typePresent) {
|
|
102
|
+
//console.log(`[OPTIMIZELY] Type ${ node.typeCondition.name.value } not found, dropping fragment ${ node.name.value }`)
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
},
|
|
81
108
|
SelectionSet: {
|
|
82
109
|
enter(node, key, parent) {
|
|
83
110
|
if (!isArray(parent) && parent?.kind == graphql_1.Kind.FRAGMENT_DEFINITION && intoNames.includes(parent.name.value)) {
|
|
@@ -92,6 +119,7 @@ const transform = async ({ documents: files, config }) => {
|
|
|
92
119
|
};
|
|
93
120
|
});
|
|
94
121
|
componentSpreads[parent.name.value]?.forEach(spread => {
|
|
122
|
+
//console.log("[ DEBUG ] Pushing inline fragment for", parent.name.value)
|
|
95
123
|
addedSelections.push(spread);
|
|
96
124
|
});
|
|
97
125
|
return {
|
|
@@ -111,10 +139,12 @@ const transform = async ({ documents: files, config }) => {
|
|
|
111
139
|
document: document,
|
|
112
140
|
};
|
|
113
141
|
});
|
|
142
|
+
//console.log("[SUCCESS] Optimizely document transformation")
|
|
114
143
|
return newFiles;
|
|
115
144
|
};
|
|
116
145
|
exports.transform = transform;
|
|
117
146
|
exports.default = { transform: exports.transform };
|
|
147
|
+
// The recursive sections to add
|
|
118
148
|
const recursiveSelections = (0, graphql_1.parse)(`fragment BlockContentAreaItemData on ContentAreaItemModel {
|
|
119
149
|
item: ContentLink {
|
|
120
150
|
data: Expanded @recursive(depth: 3) {
|
package/dist/transform.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../src/transform.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../src/transform.ts"],"names":[],"mappings":";;;;;;AAGA,qCAA4C;AAC5C,sDAAwB;AAMxB,SAAgB,oBAAoB,CAAC,OAA2B;IAE5D,OAAO;QACH,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,EAAE;KACvC,CAAA;AACL,CAAC;AALD,oDAKC;AAED,SAAS,OAAO,CAAI,MAAyB,IAA6B,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA,CAAC,CAAC;AAEjG,MAAM,SAAS,GAAuD,KAAK,EAAE,EAAC,SAA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ACJ,CAAA;wBACL,CAAC,CAAC,CAAA;wBACF,gBAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE;4BAClD,yEAAyE;4BACzE,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;wBAChC,CAAC,CAAC,CAAA;wBACF,OAAO;4BACH,GAAG,IAAI;4BACP,UAAU,EAAE;gCACR,GAAG,IAAI,CAAC,UAAU;gCAClB,GAAG,eAAe;6BACrB;yBACgB,CAAA;oBACzB,CAAC;oBACD,OAAO,SAAS,CAAA;gBACpB,CAAC;aACJ;SACJ,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;QACd,OAAO;YACH,GAAG,IAAI;YACP,QAAQ,EAAE,QAAQ;SACrB,CAAA;IACL,CAAC,CAAC,CAAA;IACF,6DAA6D;IAC7D,OAAO,QAAQ,CAAA;AACnB,CAAC,CAAA;AAlIY,QAAA,SAAS,aAkIrB;AAED,kBAAe,EAAE,SAAS,EAAT,iBAAS,EAAE,CAAA;AAE5B,gCAAgC;AAChC,MAAM,mBAAmB,GAAI,IAAA,eAAK,EAAC;;;;;;EAMjC,CAAC,CAAC,WAAW,CAAC,CAAC,CAA4B,EAAE,YAAY,CAAC,UAAU,IAAI,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remkoj/optimizely-graph-functions",
|
|
3
|
-
"private": false,
|
|
4
3
|
"license": "Apache-2.0",
|
|
5
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.3",
|
|
6
5
|
"packageManager": "yarn@4.1.1",
|
|
7
6
|
"repository": "https://github.com/remkoj/optimizely-dxp-clients.git",
|
|
8
7
|
"author": "Remko Jantzen <693172+remkoj@users.noreply.github.com>",
|
|
@@ -36,14 +35,16 @@
|
|
|
36
35
|
}
|
|
37
36
|
},
|
|
38
37
|
"devDependencies": {
|
|
39
|
-
"@graphql-codegen/add": "^5.0.2",
|
|
40
|
-
"@graphql-codegen/client-preset": "^4.2.4",
|
|
41
38
|
"@graphql-codegen/plugin-helpers": "^5.0.3",
|
|
42
|
-
"@types/node": "^20.
|
|
39
|
+
"@types/node": "^20.12.4",
|
|
43
40
|
"graphql": "^16.8.1",
|
|
44
|
-
"tslib": "^2.6.2",
|
|
45
41
|
"typescript": "^5.4.3"
|
|
46
42
|
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@graphql-codegen/add": "^5.0.2",
|
|
45
|
+
"@graphql-codegen/client-preset": "^4.2.5",
|
|
46
|
+
"tslib": "^2.6.2"
|
|
47
|
+
},
|
|
47
48
|
"scripts": {
|
|
48
49
|
"clean": "tsc --clean",
|
|
49
50
|
"prepare": "tsc --build",
|
|
@@ -51,12 +52,9 @@
|
|
|
51
52
|
"watch": "tsc --watch"
|
|
52
53
|
},
|
|
53
54
|
"peerDependencies": {
|
|
54
|
-
"
|
|
55
|
-
"@graphql-codegen/client-preset": "*",
|
|
56
|
-
"graphql": "*",
|
|
57
|
-
"tslib": "*"
|
|
55
|
+
"graphql": "*"
|
|
58
56
|
},
|
|
59
57
|
"optionalDependencies": {
|
|
60
|
-
"@remkoj/optimizely-graph-client": "1.0.
|
|
58
|
+
"@remkoj/optimizely-graph-client": "1.0.3"
|
|
61
59
|
}
|
|
62
60
|
}
|
package/dist/src/documents.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { Types } from '@graphql-codegen/plugin-helpers';
|
|
2
|
-
type DocumentsConfigNode = NonNullable<Types.Config['documents']>;
|
|
3
|
-
export declare const IContentDataProps: string[];
|
|
4
|
-
export declare const fragments: string[];
|
|
5
|
-
export declare const queries: string[];
|
|
6
|
-
export declare const DefaultFunctions: string[];
|
|
7
|
-
export declare const documents: string[];
|
|
8
|
-
export declare const injectFragments: (base: DocumentsConfigNode) => DocumentsConfigNode;
|
|
9
|
-
export {};
|
package/dist/src/documents.js
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.injectFragments = exports.documents = exports.DefaultFunctions = exports.queries = exports.fragments = exports.IContentDataProps = void 0;
|
|
4
|
-
exports.IContentDataProps = ["contentType", "id", "locale", "path", "__typename"];
|
|
5
|
-
exports.fragments = [
|
|
6
|
-
`fragment ContentLink on ContentModelReference {
|
|
7
|
-
id: Id,
|
|
8
|
-
workId: WorkId,
|
|
9
|
-
guidValue: GuidValue
|
|
10
|
-
}`,
|
|
11
|
-
`fragment ContentLinkSearch on ContentModelReferenceSearch {
|
|
12
|
-
id: Id,
|
|
13
|
-
workId: WorkId,
|
|
14
|
-
guidValue: GuidValue
|
|
15
|
-
}`,
|
|
16
|
-
`fragment IContentData on IContent {
|
|
17
|
-
contentType: ContentType
|
|
18
|
-
id: ContentLink {
|
|
19
|
-
...ContentLink
|
|
20
|
-
}
|
|
21
|
-
locale: Language {
|
|
22
|
-
name: Name
|
|
23
|
-
}
|
|
24
|
-
path:RelativePath
|
|
25
|
-
}`,
|
|
26
|
-
`fragment ContentAreaItemData on ContentAreaItemModelSearch {
|
|
27
|
-
item: ContentLink {
|
|
28
|
-
...ContentLinkSearch
|
|
29
|
-
data: Expanded {
|
|
30
|
-
...BlockData
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
displayOption:DisplayOption
|
|
34
|
-
}`,
|
|
35
|
-
`fragment BlockContentAreaItemSearchData on ContentAreaItemModelSearch {
|
|
36
|
-
item: ContentLink {
|
|
37
|
-
...ContentLinkSearch
|
|
38
|
-
data: Expanded {
|
|
39
|
-
...IContentData
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
displayOption:DisplayOption
|
|
43
|
-
}`,
|
|
44
|
-
`fragment BlockContentAreaItemData on ContentAreaItemModel {
|
|
45
|
-
item: ContentLink {
|
|
46
|
-
...ContentLink
|
|
47
|
-
data: Expanded {
|
|
48
|
-
...IContentData
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
displayOption:DisplayOption
|
|
52
|
-
}`,
|
|
53
|
-
`fragment LinkItemData on LinkItemNode {
|
|
54
|
-
children: Text
|
|
55
|
-
title: Title
|
|
56
|
-
href: Href
|
|
57
|
-
target: Target
|
|
58
|
-
content: ContentLink {
|
|
59
|
-
href: Url
|
|
60
|
-
data: Expanded {
|
|
61
|
-
path: RelativePath
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}`,
|
|
65
|
-
`fragment ImageData on ContentModelReference {
|
|
66
|
-
...ContentLink
|
|
67
|
-
url: Url
|
|
68
|
-
data: Expanded {
|
|
69
|
-
...IContentData
|
|
70
|
-
url: Url
|
|
71
|
-
alt: Name
|
|
72
|
-
path: RelativePath
|
|
73
|
-
}
|
|
74
|
-
}`,
|
|
75
|
-
`fragment ImageDataSearch on ContentModelReferenceSearch {
|
|
76
|
-
...ContentLinkSearch
|
|
77
|
-
url: Url
|
|
78
|
-
data: Expanded {
|
|
79
|
-
...IContentData
|
|
80
|
-
url: Url
|
|
81
|
-
alt: Name
|
|
82
|
-
path: RelativePath
|
|
83
|
-
}
|
|
84
|
-
}`,
|
|
85
|
-
`fragment BlockData on IContent {
|
|
86
|
-
...IContentData
|
|
87
|
-
}`,
|
|
88
|
-
`fragment PageData on IContent {
|
|
89
|
-
...IContentData
|
|
90
|
-
}`,
|
|
91
|
-
`fragment ContentAreaItemBase on ContentAreaItemModelSearch {
|
|
92
|
-
contentLink:ContentLink {
|
|
93
|
-
id:Id
|
|
94
|
-
workId:WorkId
|
|
95
|
-
guidValue:GuidValue
|
|
96
|
-
component:Expanded {
|
|
97
|
-
path:RelativePath
|
|
98
|
-
type:ContentType
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
displayOption:DisplayOption
|
|
102
|
-
}`
|
|
103
|
-
];
|
|
104
|
-
exports.queries = [`query getContentById($id: Int, $workId: Int, $guidValue: String, $locale: [Locales!], $isCommonDraft: Boolean) {
|
|
105
|
-
Content(
|
|
106
|
-
where: {
|
|
107
|
-
ContentLink: {
|
|
108
|
-
Id: { eq: $id },
|
|
109
|
-
WorkId: { eq: $workId },
|
|
110
|
-
GuidValue: { eq: $guidValue }
|
|
111
|
-
}
|
|
112
|
-
IsCommonDraft: { eq: $isCommonDraft }
|
|
113
|
-
}
|
|
114
|
-
locale: $locale
|
|
115
|
-
) {
|
|
116
|
-
total
|
|
117
|
-
items {
|
|
118
|
-
...IContentData
|
|
119
|
-
...PageData
|
|
120
|
-
...BlockData
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}`,
|
|
124
|
-
`query getContentByPath($path: String!, $locale: [Locales], $siteId: String)
|
|
125
|
-
{
|
|
126
|
-
Content(
|
|
127
|
-
where: {
|
|
128
|
-
RelativePath: {
|
|
129
|
-
eq: $path
|
|
130
|
-
}
|
|
131
|
-
SiteId: {
|
|
132
|
-
eq: $siteId
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
locale: $locale
|
|
136
|
-
) {
|
|
137
|
-
items {
|
|
138
|
-
...PageData
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}`, `query getContentType($id: Int, $workId: Int, $guidValue: String, $locale: [Locales])
|
|
142
|
-
{
|
|
143
|
-
Content(
|
|
144
|
-
where: {
|
|
145
|
-
ContentLink: {
|
|
146
|
-
GuidValue: {
|
|
147
|
-
eq: $guidValue
|
|
148
|
-
}
|
|
149
|
-
Id: {
|
|
150
|
-
eq: $id
|
|
151
|
-
},
|
|
152
|
-
WorkId: {
|
|
153
|
-
eq: $workId
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
},
|
|
157
|
-
locale: $locale
|
|
158
|
-
limit: 1
|
|
159
|
-
) {
|
|
160
|
-
items {
|
|
161
|
-
ContentType
|
|
162
|
-
},
|
|
163
|
-
total
|
|
164
|
-
}
|
|
165
|
-
}`];
|
|
166
|
-
exports.DefaultFunctions = ['getContentType', 'getContentByPath', 'getContentById'];
|
|
167
|
-
exports.documents = [...exports.queries, ...exports.fragments];
|
|
168
|
-
const injectFragments = (base) => {
|
|
169
|
-
const baseIsArray = Array.isArray(base);
|
|
170
|
-
return baseIsArray ? [...exports.fragments, ...base] : [...exports.fragments, base];
|
|
171
|
-
};
|
|
172
|
-
exports.injectFragments = injectFragments;
|
|
173
|
-
//# sourceMappingURL=documents.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"documents.js","sourceRoot":"","sources":["../../src/documents.ts"],"names":[],"mappings":";;;AAIa,QAAA,iBAAiB,GAAG,CAAC,aAAa,EAAC,IAAI,EAAC,QAAQ,EAAC,MAAM,EAAC,YAAY,CAAC,CAAA;AAErE,QAAA,SAAS,GAAG;IACrB;;;;MAIE;IACF;;;;MAIE;IACF;;;;;;;;;MASE;IACF;;;;;;;;MAQE;IACF;;;;;;;;MAQE;IACF;;;;;;;;MAQE;IACF;;;;;;;;;;;MAWE;IACF;;;;;;;;;MASE;IACF;;;;;;;;;MASE;IACF;;MAEE;IACF;;MAEE;IACF;;;;;;;;;;;MAWE;CACL,CAAA;AACY,QAAA,OAAO,GAAG,CAAC;;;;;;;;;;;;;;;;;;;EAmBtB;IACF;;;;;;;;;;;;;;;;;EAiBE,EAAC;;;;;;;;;;;;;;;;;;;;;;;;EAwBD,CAAC,CAAA;AAEU,QAAA,gBAAgB,GAAG,CAAC,gBAAgB,EAAC,kBAAkB,EAAC,gBAAgB,CAAC,CAAA;AACzE,QAAA,SAAS,GAAG,CAAE,GAAG,eAAO,EAAE,GAAG,iBAAS,CAAE,CAAA;AAC9C,MAAM,eAAe,GAAwD,CAAC,IAAI,EAAE,EAAE;IAEzF,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IACvC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAE,GAAG,iBAAS,EAAE,GAAG,IAAI,CAAE,CAAC,CAAC,CAAC,CAAE,GAAG,iBAAS,EAAE,IAAI,CAAE,CAAA;AAC3E,CAAC,CAAA;AAJY,QAAA,eAAe,mBAI3B"}
|
package/dist/src/index.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { CodegenPlugin, PluginFunction, PluginValidateFn } from '@graphql-codegen/plugin-helpers';
|
|
2
|
-
export type PluginOptions = {
|
|
3
|
-
functions?: string[];
|
|
4
|
-
prettyPrintQuery?: boolean;
|
|
5
|
-
clientPath?: string;
|
|
6
|
-
};
|
|
7
|
-
export declare function pickPluginOptions(options: Record<string, any>): PluginOptions;
|
|
8
|
-
/**
|
|
9
|
-
* Validate the plugin configuration
|
|
10
|
-
*
|
|
11
|
-
* @param schema
|
|
12
|
-
* @param document
|
|
13
|
-
* @param config
|
|
14
|
-
* @param outputFile
|
|
15
|
-
* @param allPlugins
|
|
16
|
-
* @param pluginContext
|
|
17
|
-
*/
|
|
18
|
-
export declare const validate: PluginValidateFn<PluginOptions>;
|
|
19
|
-
/**
|
|
20
|
-
* Actual Plugin logic
|
|
21
|
-
*
|
|
22
|
-
* @param schema
|
|
23
|
-
* @param documents
|
|
24
|
-
* @param config
|
|
25
|
-
* @param info
|
|
26
|
-
* @returns
|
|
27
|
-
*/
|
|
28
|
-
export declare const plugin: PluginFunction<PluginOptions>;
|
|
29
|
-
declare const _default: CodegenPlugin<PluginOptions>;
|
|
30
|
-
export default _default;
|