@remkoj/optimizely-graph-functions 6.0.0-pre8 → 6.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +12 -12
- package/README.md +60 -14
- package/dist/_transform/cleanFragments.d.ts +10 -0
- package/dist/_transform/cleanFragments.js +39 -0
- package/dist/_transform/cleanFragments.js.map +1 -0
- package/dist/_transform/cleanSpreads.d.ts +10 -0
- package/dist/_transform/cleanSpreads.js +36 -0
- package/dist/_transform/cleanSpreads.js.map +1 -0
- package/dist/_transform/handleDependDirective.d.ts +11 -0
- package/dist/_transform/handleDependDirective.js +128 -0
- package/dist/_transform/handleDependDirective.js.map +1 -0
- package/dist/_transform/injectComponentDocuments.d.ts +16 -0
- package/dist/_transform/injectComponentDocuments.js +177 -0
- package/dist/_transform/injectComponentDocuments.js.map +1 -0
- package/dist/_transform/injectPageQueries.d.ts +5 -0
- package/dist/_transform/injectPageQueries.js +114 -0
- package/dist/_transform/injectPageQueries.js.map +1 -0
- package/dist/_transform/injectSectionQueries.d.ts +5 -0
- package/dist/_transform/injectSectionQueries.js +128 -0
- package/dist/_transform/injectSectionQueries.js.map +1 -0
- package/dist/_transform/normalizeFragmentNames.d.ts +12 -0
- package/dist/_transform/normalizeFragmentNames.js +77 -0
- package/dist/_transform/normalizeFragmentNames.js.map +1 -0
- package/dist/_transform/normalizeQueryNames.d.ts +12 -0
- package/dist/_transform/normalizeQueryNames.js +83 -0
- package/dist/_transform/normalizeQueryNames.js.map +1 -0
- package/dist/_transform/options.d.ts +3 -0
- package/dist/_transform/options.js +21 -0
- package/dist/_transform/options.js.map +1 -0
- package/dist/_transform/performInjections.d.ts +24 -0
- package/dist/_transform/performInjections.js +192 -0
- package/dist/_transform/performInjections.js.map +1 -0
- package/dist/_transform/tools.d.ts +34 -0
- package/dist/_transform/tools.js +103 -0
- package/dist/_transform/tools.js.map +1 -0
- package/dist/cms/index.d.ts +11 -0
- package/dist/cms/index.js +121 -0
- package/dist/cms/index.js.map +1 -0
- package/dist/contenttype-loader.d.ts +11 -0
- package/dist/contenttype-loader.js +72 -0
- package/dist/contenttype-loader.js.map +1 -0
- package/dist/documents/fragments.cms13.js +147 -39
- package/dist/documents/fragments.cms13.js.map +1 -1
- package/dist/documents/queries.cms13.js +9 -3
- package/dist/documents/queries.cms13.js.map +1 -1
- package/dist/embedded-loader.js +31 -16
- package/dist/embedded-loader.js.map +1 -1
- package/dist/generator/collision-tracker.d.ts +22 -0
- package/dist/generator/collision-tracker.js +103 -0
- package/dist/generator/collision-tracker.js.map +1 -0
- package/dist/generator/generator.d.ts +77 -0
- package/dist/generator/generator.js +272 -0
- package/dist/generator/generator.js.map +1 -0
- package/dist/generator/index.d.ts +3 -0
- package/dist/generator/index.js +42 -0
- package/dist/generator/index.js.map +1 -0
- package/dist/generator/virtual-location.d.ts +41 -0
- package/dist/generator/virtual-location.js +139 -0
- package/dist/generator/virtual-location.js.map +1 -0
- package/dist/index.d.ts +2 -5
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/preset.d.ts +2 -4
- package/dist/preset.js +112 -73
- package/dist/preset.js.map +1 -1
- package/dist/tools.d.ts +4 -0
- package/dist/tools.js +20 -0
- package/dist/tools.js.map +1 -0
- package/dist/transform.d.ts +12 -1
- package/dist/transform.js +48 -58
- package/dist/transform.js.map +1 -1
- package/dist/types.d.ts +23 -0
- package/package.json +27 -21
package/dist/preset.js
CHANGED
|
@@ -34,14 +34,13 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.preset = void 0;
|
|
37
|
-
const graphql_1 = require("graphql");
|
|
38
37
|
// Import base preset
|
|
39
38
|
const client_preset_1 = require("@graphql-codegen/client-preset");
|
|
40
39
|
const GraphQLRequestPlugin = __importStar(require("@graphql-codegen/typescript-graphql-request"));
|
|
41
40
|
const AddPlugin = __importStar(require("@graphql-codegen/add"));
|
|
42
41
|
// Import injected parts
|
|
43
42
|
const index_1 = __importStar(require("./index"));
|
|
44
|
-
const transform_1 =
|
|
43
|
+
const transform_1 = require("./transform");
|
|
45
44
|
exports.preset = {
|
|
46
45
|
/**
|
|
47
46
|
* Prepare the documents to be parsed by this preset, without modifying the original array
|
|
@@ -52,20 +51,46 @@ exports.preset = {
|
|
|
52
51
|
*/
|
|
53
52
|
prepareDocuments: async (outputFilePath, outputSpecificDocuments) => {
|
|
54
53
|
// Get the configured documents
|
|
55
|
-
const optiDocs = outputSpecificDocuments.filter((x => typeof
|
|
56
|
-
const normalDocs = outputSpecificDocuments.filter(x => !(typeof
|
|
54
|
+
const optiDocs = outputSpecificDocuments.filter(((x) => typeof x == 'string' && x.startsWith('opti-cms:')));
|
|
55
|
+
const normalDocs = outputSpecificDocuments.filter((x) => !(typeof x == 'string' && x.startsWith('opti-cms:')));
|
|
57
56
|
// Get the base documents
|
|
58
|
-
const documents = client_preset_1.preset.prepareDocuments
|
|
59
|
-
await client_preset_1.preset.prepareDocuments(outputFilePath, normalDocs)
|
|
60
|
-
[...normalDocs, `!${outputFilePath}`];
|
|
57
|
+
const documents = client_preset_1.preset.prepareDocuments
|
|
58
|
+
? await client_preset_1.preset.prepareDocuments(outputFilePath, normalDocs)
|
|
59
|
+
: [...normalDocs, `!${outputFilePath}`];
|
|
61
60
|
// Transform / inject the Opti-CMS documents
|
|
62
|
-
const CmsDocLoaders = (optiDocs.length == 0
|
|
61
|
+
const CmsDocLoaders = (optiDocs.length == 0
|
|
62
|
+
? ['opti-cms:/fragments/13', /*'opti-cms:/queries/13'*/]
|
|
63
|
+
: optiDocs).map((optiDoc) => {
|
|
63
64
|
const loader = {};
|
|
64
|
-
loader[optiDoc] = { loader:
|
|
65
|
+
loader[optiDoc] = { loader: '@remkoj/optimizely-graph-functions/loader' };
|
|
65
66
|
return loader;
|
|
66
67
|
});
|
|
68
|
+
// Get page documents
|
|
69
|
+
const [pageDocuments, sectionDocuments, componentDocuments, injectionTargets] = await Promise.all([
|
|
70
|
+
(0, transform_1.getPageDocuments)(),
|
|
71
|
+
(0, transform_1.getSectionDocuments)(),
|
|
72
|
+
(0, transform_1.getComponentDocuments)(),
|
|
73
|
+
(0, transform_1.getInjectionTargetDocuments)()
|
|
74
|
+
]);
|
|
67
75
|
// Create a new, extended, array
|
|
68
|
-
|
|
76
|
+
const allDocuments = [
|
|
77
|
+
...CmsDocLoaders,
|
|
78
|
+
...pageDocuments,
|
|
79
|
+
...sectionDocuments,
|
|
80
|
+
...componentDocuments,
|
|
81
|
+
...injectionTargets
|
|
82
|
+
];
|
|
83
|
+
function compareOperationDocuments(a, b) {
|
|
84
|
+
const aPath = typeof (a) === 'string' ? a : Object.getOwnPropertyNames(a).join(';');
|
|
85
|
+
const bPath = typeof (b) === 'string' ? b : Object.getOwnPropertyNames(b).join(';');
|
|
86
|
+
if (aPath < bPath)
|
|
87
|
+
return -1;
|
|
88
|
+
if (aPath > bPath)
|
|
89
|
+
return 1;
|
|
90
|
+
return 0;
|
|
91
|
+
}
|
|
92
|
+
allDocuments.sort(compareOperationDocuments);
|
|
93
|
+
return [...documents, ...allDocuments];
|
|
69
94
|
},
|
|
70
95
|
buildGeneratesSection: async (options) => {
|
|
71
96
|
// Extend the default plugin configuration
|
|
@@ -76,9 +101,9 @@ exports.preset = {
|
|
|
76
101
|
// Provided options
|
|
77
102
|
...options.config,
|
|
78
103
|
// Enforced settings
|
|
79
|
-
namingConvention:
|
|
104
|
+
namingConvention: 'keep', // Keep casing "as-is" from Optimizely Graph
|
|
80
105
|
};
|
|
81
|
-
// Change the default for fragment masking from 'useFragment' to
|
|
106
|
+
// Change the default for fragment masking from 'useFragment' to
|
|
82
107
|
// 'getFragmentData', in order to prevent issues with code checks for
|
|
83
108
|
// React hooks
|
|
84
109
|
if (options.presetConfig.fragmentMasking !== false) {
|
|
@@ -86,69 +111,51 @@ exports.preset = {
|
|
|
86
111
|
...options.presetConfig,
|
|
87
112
|
fragmentMasking: {
|
|
88
113
|
unmaskFunctionName: 'getFragmentData',
|
|
89
|
-
...(typeof
|
|
90
|
-
|
|
114
|
+
...(typeof options.presetConfig?.fragmentMasking == 'object'
|
|
115
|
+
? options.presetConfig?.fragmentMasking
|
|
116
|
+
: {}),
|
|
117
|
+
},
|
|
91
118
|
};
|
|
92
119
|
}
|
|
93
|
-
//
|
|
94
|
-
|
|
95
|
-
options.
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
];
|
|
106
|
-
// The packages contain quite a few utility fragments, however these
|
|
107
|
-
// can cause errors if there're no Content Types using the types
|
|
108
|
-
// targeted by these fragments as they won't be available in Optimizely
|
|
109
|
-
// Graph - so we're removing them first
|
|
110
|
-
options.documents = options.documents.map(doc => {
|
|
111
|
-
if (doc.document) {
|
|
112
|
-
const newDocument = (0, graphql_1.visit)(doc.document, {
|
|
113
|
-
FragmentDefinition: {
|
|
114
|
-
enter: (node) => {
|
|
115
|
-
if (!options.schema.definitions.some(x => (x.kind == graphql_1.Kind.OBJECT_TYPE_DEFINITION || x.kind == graphql_1.Kind.INTERFACE_TYPE_DEFINITION) && x.name.value == node.typeCondition.name.value)) {
|
|
116
|
-
if (options.presetConfig.verbose)
|
|
117
|
-
console.log(`⚠ Removing fragment ${node.name.value} from the documents, as its target ${node.typeCondition.name.value} is not available in the schema`);
|
|
118
|
-
return null;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
return {
|
|
124
|
-
...doc,
|
|
125
|
-
document: newDocument
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
return doc;
|
|
129
|
-
});
|
|
120
|
+
// Apply all changes to the document set, prior to validating it. They're executed in the order of the array
|
|
121
|
+
options.documentTransforms = injectOptimizelyTransforms(options.documentTransforms, options);
|
|
122
|
+
options.documents = await (0, transform_1.executeDocumentTransforms)(options.documents, [
|
|
123
|
+
transform_1.cleanFragments, // Remove fragments that target non-existing types
|
|
124
|
+
transform_1.normalizeFragmentNames, // Allow overriding of built-in fragments
|
|
125
|
+
transform_1.normalizeQueryNames, // Allow overriding of built-in queries
|
|
126
|
+
transform_1.performInjections, // Run injections of component fragments adjacent to placeholder fragments
|
|
127
|
+
transform_1.cleanFragmentSpreads, // Remove all fragment spreads that target a fragment that does not exist in the documents
|
|
128
|
+
transform_1.handleDependDirective, // Remove the "item" field in queries and fragments from the "ContentReference" type if it's not in the schema
|
|
129
|
+
], options);
|
|
130
130
|
// Build the preset files
|
|
131
131
|
const section = await client_preset_1.preset.buildGeneratesSection(options);
|
|
132
|
-
// Add GraphQL Request Client
|
|
132
|
+
// Add GraphQL Request Client.
|
|
133
133
|
section.push({
|
|
134
134
|
filename: `${options.baseOutputDir}client.ts`,
|
|
135
135
|
pluginMap: {
|
|
136
|
-
|
|
137
|
-
|
|
136
|
+
add: AddPlugin,
|
|
137
|
+
'typescript-graphql-request': GraphQLRequestPlugin,
|
|
138
138
|
},
|
|
139
139
|
plugins: [
|
|
140
140
|
{
|
|
141
141
|
add: {
|
|
142
|
-
content: [
|
|
142
|
+
content: [
|
|
143
|
+
'// This is an auto-generated file, do not modify',
|
|
144
|
+
'import type * as Schema from "./graphql";',
|
|
145
|
+
],
|
|
143
146
|
},
|
|
144
147
|
},
|
|
145
148
|
{
|
|
146
149
|
'typescript-graphql-request': {
|
|
147
|
-
...options.config,
|
|
148
150
|
useTypeImports: true,
|
|
149
|
-
importOperationTypesFrom:
|
|
150
|
-
|
|
151
|
-
|
|
151
|
+
importOperationTypesFrom: 'Schema',
|
|
152
|
+
//rawRequest: options.presetConfig.recursion ? true : undefined,
|
|
153
|
+
//documentMode: options.presetConfig.recursion ? DocumentMode.string : undefined,
|
|
154
|
+
experimentalAddDocumentNodeType: options.presetConfig.recursion ? true : undefined,
|
|
155
|
+
//rawString: options.presetConfig.recursion ? true : undefined,
|
|
156
|
+
...options.config,
|
|
157
|
+
},
|
|
158
|
+
},
|
|
152
159
|
],
|
|
153
160
|
schema: options.schema,
|
|
154
161
|
schemaAst: options.schemaAst,
|
|
@@ -157,18 +164,19 @@ exports.preset = {
|
|
|
157
164
|
},
|
|
158
165
|
profiler: options.profiler,
|
|
159
166
|
documents: options.documents,
|
|
160
|
-
documentTransforms: options.documentTransforms
|
|
167
|
+
documentTransforms: options.documentTransforms,
|
|
161
168
|
});
|
|
162
|
-
// Add the functions file
|
|
169
|
+
// Add the functions file, which will materialize the defined
|
|
170
|
+
// functions.
|
|
163
171
|
section.push({
|
|
164
172
|
filename: `${options.baseOutputDir}functions.ts`,
|
|
165
173
|
pluginMap: {
|
|
166
|
-
['optly-functions']: index_1.default
|
|
174
|
+
['optly-functions']: index_1.default,
|
|
167
175
|
},
|
|
168
176
|
plugins: [
|
|
169
177
|
{
|
|
170
|
-
['optly-functions']: {}
|
|
171
|
-
}
|
|
178
|
+
['optly-functions']: {},
|
|
179
|
+
},
|
|
172
180
|
],
|
|
173
181
|
schema: options.schema,
|
|
174
182
|
schemaAst: options.schemaAst,
|
|
@@ -178,41 +186,72 @@ exports.preset = {
|
|
|
178
186
|
...(0, index_1.pickPluginOptions)(options.presetConfig),
|
|
179
187
|
},
|
|
180
188
|
documents: options.documents,
|
|
181
|
-
documentTransforms: options.documentTransforms
|
|
189
|
+
documentTransforms: options.documentTransforms,
|
|
182
190
|
});
|
|
183
|
-
// Update
|
|
191
|
+
// Update file generation configs
|
|
184
192
|
section.forEach((fileConfig, idx) => {
|
|
185
193
|
// Modify index.ts with additional exports
|
|
186
|
-
if (fileConfig.filename.endsWith(
|
|
194
|
+
if (fileConfig.filename.endsWith('index.ts')) {
|
|
187
195
|
section[idx].plugins.unshift({
|
|
188
196
|
add: {
|
|
189
197
|
content: [
|
|
190
198
|
'export * as Schema from "./graphql";',
|
|
191
199
|
'export * from "./functions";',
|
|
192
200
|
'export { getSdk, type Sdk } from "./client";',
|
|
193
|
-
]
|
|
194
|
-
}
|
|
201
|
+
],
|
|
202
|
+
},
|
|
195
203
|
});
|
|
196
204
|
section[idx].plugins.push({
|
|
197
205
|
add: {
|
|
198
|
-
content: [
|
|
199
|
-
|
|
206
|
+
content: [
|
|
207
|
+
'',
|
|
208
|
+
`export const WITH_RECURSIVE_SUPPORT = ${options.presetConfig.recursion === true ? 'true' : 'false'};`,
|
|
209
|
+
],
|
|
210
|
+
},
|
|
200
211
|
});
|
|
201
212
|
}
|
|
213
|
+
//if (!hasOptimizelyTransform(fileConfig.documentTransforms))
|
|
214
|
+
// fileConfig.documentTransforms = injectOptimizelyTransforms(fileConfig.documentTransforms)
|
|
202
215
|
// Optimizely Graph supports recursive queries to allow fetching
|
|
203
216
|
// data as created in the CMS. This can cause issues when using
|
|
204
217
|
// multiple GraphQL sources, hence the ability to enable/disalbe
|
|
205
218
|
// the support for recursive queries.
|
|
206
|
-
if (fileConfig.skipDocumentsValidation != true &&
|
|
219
|
+
if (fileConfig.skipDocumentsValidation != true &&
|
|
220
|
+
options.presetConfig.recursion === true) {
|
|
207
221
|
const currentOptions = fileConfig.skipDocumentsValidation || {};
|
|
208
222
|
section[idx].skipDocumentsValidation = {
|
|
209
223
|
...currentOptions,
|
|
210
|
-
ignoreRules: [
|
|
224
|
+
ignoreRules: [
|
|
225
|
+
...(currentOptions.ignoreRules ?? []),
|
|
226
|
+
'NoFragmentCyclesRule',
|
|
227
|
+
],
|
|
211
228
|
};
|
|
212
229
|
}
|
|
213
230
|
});
|
|
214
231
|
return section;
|
|
215
232
|
},
|
|
216
233
|
};
|
|
234
|
+
function injectOptimizelyTransforms(currentTransforms, options) {
|
|
235
|
+
const dt = currentTransforms ?? [];
|
|
236
|
+
dt.unshift({
|
|
237
|
+
name: 'Optimizely.CMS',
|
|
238
|
+
transformObject: {
|
|
239
|
+
transform: (tOpts) => (0, transform_1.executeDocumentTransforms)(tOpts.documents, [
|
|
240
|
+
transform_1.cleanFragments, // Remove fragments that target non-existing types
|
|
241
|
+
transform_1.normalizeFragmentNames, // Allow overriding of built-in fragments
|
|
242
|
+
transform_1.normalizeQueryNames, // Allow overriding of built-in queries
|
|
243
|
+
transform_1.performInjections, // Run injections of component fragments adjacent to placeholder fragments
|
|
244
|
+
transform_1.cleanFragmentSpreads, // Remove all fragment spreads that target a fragment that does not exist in the documents
|
|
245
|
+
transform_1.handleDependDirective, // Remove the "item" field in queries and fragments from the "ContentReference" type if it's not in the schema
|
|
246
|
+
], options),
|
|
247
|
+
},
|
|
248
|
+
});
|
|
249
|
+
return dt;
|
|
250
|
+
}
|
|
251
|
+
function hasOptimizelyTransform(currentTransforms) {
|
|
252
|
+
if (!Array.isArray(currentTransforms))
|
|
253
|
+
return false;
|
|
254
|
+
return currentTransforms.some(x => x.name === 'Optimizely.CMS');
|
|
255
|
+
}
|
|
217
256
|
exports.default = exports.preset;
|
|
218
257
|
//# sourceMappingURL=preset.js.map
|
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,qBAAqB;AACrB,kEAAuE;AAEvE,kGAAmF;AACnF,gEAAiD;AAEjD,wBAAwB;AACxB,iDAAmD;AACnD,2CAYoB;AAMP,QAAA,MAAM,GAAsC;IACvD;;;;;;OAMG;IACH,gBAAgB,EAAE,KAAK,EACrB,cAAgC,EAChC,uBAA+D,EAC/D,EAAE;QACF,+BAA+B;QAC/B,MAAM,QAAQ,GAAG,uBAAuB,CAAC,MAAM,CAC7C,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,QAAQ,IAAI,CAAC,CAAC,UAAU,CAAC,WAAW,CAAC,CAEz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O,KAAK,CAAA;IACnD,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,gBAAgB,CAAC,CAAA;AACjE,CAAC;AAED,kBAAe,cAAM,CAAA"}
|
package/dist/tools.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function ucFirst<S extends string>(input: S): Capitalize<S>;
|
|
2
|
+
export declare function lcFirst<S extends string>(input: S): Uncapitalize<S>;
|
|
3
|
+
export declare function trimStart(target: string, toTrim?: string): string;
|
|
4
|
+
export declare function isNonEmptyString<S extends string>(toTest: S | null | undefined | object | number | boolean): toTest is S;
|
package/dist/tools.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ucFirst = ucFirst;
|
|
4
|
+
exports.lcFirst = lcFirst;
|
|
5
|
+
exports.trimStart = trimStart;
|
|
6
|
+
exports.isNonEmptyString = isNonEmptyString;
|
|
7
|
+
function ucFirst(input) {
|
|
8
|
+
return (input.substring(0, 1).toUpperCase() + input.substring(1));
|
|
9
|
+
}
|
|
10
|
+
function lcFirst(input) {
|
|
11
|
+
return (input.substring(0, 1).toLowerCase() + input.substring(1));
|
|
12
|
+
}
|
|
13
|
+
function trimStart(target, toTrim = ' ') {
|
|
14
|
+
const regex = new RegExp(`/^(${toTrim})+/`);
|
|
15
|
+
return target.replace(regex, '');
|
|
16
|
+
}
|
|
17
|
+
function isNonEmptyString(toTest) {
|
|
18
|
+
return typeof toTest === 'string' && toTest.length > 0;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":";;AAAA,0BAEC;AAED,0BAEC;AAED,8BAGC;AAED,4CAEC;AAfD,SAAgB,OAAO,CAAmB,KAAQ;IAChD,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAkB,CAAC;AACrF,CAAC;AAED,SAAgB,OAAO,CAAmB,KAAQ;IAChD,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAoB,CAAC;AACvF,CAAC;AAED,SAAgB,SAAS,CAAC,MAAc,EAAE,SAAiB,GAAG;IAC5D,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,MAAM,MAAM,KAAK,CAAC,CAAA;IAC3C,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;AAClC,CAAC;AAED,SAAgB,gBAAgB,CAAmB,MAAwD;IACzG,OAAO,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,CAAA;AACxD,CAAC"}
|
package/dist/transform.d.ts
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import { type Types } from '@graphql-codegen/plugin-helpers';
|
|
2
2
|
import type { TransformOptions } from './types';
|
|
3
|
-
export
|
|
3
|
+
export { cleanFragments } from "./_transform/cleanFragments";
|
|
4
|
+
export { injectComponentDocuments, getComponentDocuments, injectInjectionTargets, getInjectionTargetDocuments } from "./_transform/injectComponentDocuments";
|
|
5
|
+
export { normalizeFragmentNames } from "./_transform/normalizeFragmentNames";
|
|
6
|
+
export { normalizeQueryNames } from "./_transform/normalizeQueryNames";
|
|
7
|
+
export { pickTransformOptions } from "./_transform/options";
|
|
8
|
+
export { injectPageQueries, getPageDocuments } from "./_transform/injectPageQueries";
|
|
9
|
+
export { injectSectionQueries, getSectionDocuments } from "./_transform/injectSectionQueries";
|
|
10
|
+
export { performInjections } from "./_transform/performInjections";
|
|
11
|
+
export { cleanFragmentSpreads } from "./_transform/cleanSpreads";
|
|
12
|
+
export { handleDependDirective } from "./_transform/handleDependDirective";
|
|
13
|
+
export type TransformFn<T = any> = (files: Types.DocumentFile[], options: Types.PresetFnArgs<T>) => Promise<Types.DocumentFile[]> | Types.DocumentFile[];
|
|
14
|
+
export declare function executeDocumentTransforms<T = any>(files: Types.DocumentFile[], transforms: Array<TransformFn<T>>, options: Types.PresetFnArgs<T>): Promise<Types.DocumentFile[]>;
|
|
4
15
|
export declare const transform: Types.DocumentTransformFunction<TransformOptions>;
|
|
5
16
|
declare const _default: {
|
|
6
17
|
transform: Types.DocumentTransformFunction<TransformOptions>;
|
package/dist/transform.js
CHANGED
|
@@ -1,71 +1,61 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.transform = void 0;
|
|
4
|
-
exports.
|
|
3
|
+
exports.transform = exports.handleDependDirective = exports.cleanFragmentSpreads = exports.performInjections = exports.getSectionDocuments = exports.injectSectionQueries = exports.getPageDocuments = exports.injectPageQueries = exports.pickTransformOptions = exports.normalizeQueryNames = exports.normalizeFragmentNames = exports.getInjectionTargetDocuments = exports.injectInjectionTargets = exports.getComponentDocuments = exports.injectComponentDocuments = exports.cleanFragments = void 0;
|
|
4
|
+
exports.executeDocumentTransforms = executeDocumentTransforms;
|
|
5
5
|
const graphql_1 = require("graphql");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
var cleanFragments_1 = require("./_transform/cleanFragments");
|
|
7
|
+
Object.defineProperty(exports, "cleanFragments", { enumerable: true, get: function () { return cleanFragments_1.cleanFragments; } });
|
|
8
|
+
var injectComponentDocuments_1 = require("./_transform/injectComponentDocuments");
|
|
9
|
+
Object.defineProperty(exports, "injectComponentDocuments", { enumerable: true, get: function () { return injectComponentDocuments_1.injectComponentDocuments; } });
|
|
10
|
+
Object.defineProperty(exports, "getComponentDocuments", { enumerable: true, get: function () { return injectComponentDocuments_1.getComponentDocuments; } });
|
|
11
|
+
Object.defineProperty(exports, "injectInjectionTargets", { enumerable: true, get: function () { return injectComponentDocuments_1.injectInjectionTargets; } });
|
|
12
|
+
Object.defineProperty(exports, "getInjectionTargetDocuments", { enumerable: true, get: function () { return injectComponentDocuments_1.getInjectionTargetDocuments; } });
|
|
13
|
+
var normalizeFragmentNames_1 = require("./_transform/normalizeFragmentNames");
|
|
14
|
+
Object.defineProperty(exports, "normalizeFragmentNames", { enumerable: true, get: function () { return normalizeFragmentNames_1.normalizeFragmentNames; } });
|
|
15
|
+
var normalizeQueryNames_1 = require("./_transform/normalizeQueryNames");
|
|
16
|
+
Object.defineProperty(exports, "normalizeQueryNames", { enumerable: true, get: function () { return normalizeQueryNames_1.normalizeQueryNames; } });
|
|
17
|
+
var options_1 = require("./_transform/options");
|
|
18
|
+
Object.defineProperty(exports, "pickTransformOptions", { enumerable: true, get: function () { return options_1.pickTransformOptions; } });
|
|
19
|
+
var injectPageQueries_1 = require("./_transform/injectPageQueries");
|
|
20
|
+
Object.defineProperty(exports, "injectPageQueries", { enumerable: true, get: function () { return injectPageQueries_1.injectPageQueries; } });
|
|
21
|
+
Object.defineProperty(exports, "getPageDocuments", { enumerable: true, get: function () { return injectPageQueries_1.getPageDocuments; } });
|
|
22
|
+
var injectSectionQueries_1 = require("./_transform/injectSectionQueries");
|
|
23
|
+
Object.defineProperty(exports, "injectSectionQueries", { enumerable: true, get: function () { return injectSectionQueries_1.injectSectionQueries; } });
|
|
24
|
+
Object.defineProperty(exports, "getSectionDocuments", { enumerable: true, get: function () { return injectSectionQueries_1.getSectionDocuments; } });
|
|
25
|
+
var performInjections_1 = require("./_transform/performInjections");
|
|
26
|
+
Object.defineProperty(exports, "performInjections", { enumerable: true, get: function () { return performInjections_1.performInjections; } });
|
|
27
|
+
var cleanSpreads_1 = require("./_transform/cleanSpreads");
|
|
28
|
+
Object.defineProperty(exports, "cleanFragmentSpreads", { enumerable: true, get: function () { return cleanSpreads_1.cleanFragmentSpreads; } });
|
|
29
|
+
var handleDependDirective_1 = require("./_transform/handleDependDirective");
|
|
30
|
+
Object.defineProperty(exports, "handleDependDirective", { enumerable: true, get: function () { return handleDependDirective_1.handleDependDirective; } });
|
|
31
|
+
async function executeDocumentTransforms(files, transforms, options) {
|
|
32
|
+
let transformedFiles = files;
|
|
33
|
+
for (const transform of transforms)
|
|
34
|
+
transformedFiles = await transform(transformedFiles, options);
|
|
35
|
+
return transformedFiles;
|
|
12
36
|
}
|
|
13
|
-
const
|
|
14
|
-
|
|
37
|
+
const options_2 = require("./_transform/options");
|
|
38
|
+
const performInjections_2 = require("./_transform/performInjections");
|
|
39
|
+
const transform = async ({ documents: files, config, schema, pluginContext }) => {
|
|
40
|
+
// Create context
|
|
41
|
+
const transformConfig = { ...options_2.defaultOptions, ...config };
|
|
42
|
+
if (transformConfig.verbose)
|
|
15
43
|
console.debug(`[ OPTIMIZELY ] Starting Optimizely Graph Query & Fragment transformations`);
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (config.verbose)
|
|
19
|
-
console.debug(`[ OPTIMIZELY ] Searching for fragments to inject`);
|
|
20
|
-
const componentFragments = {};
|
|
21
|
-
files.forEach(file => {
|
|
22
|
-
if (!file.document)
|
|
23
|
-
return;
|
|
24
|
-
const applicableInjections = injections.filter(injection => !injection.pathRegex || (new RegExp(injection.pathRegex)).test(file.location ?? ""));
|
|
25
|
-
if (!applicableInjections || applicableInjections.length == 0)
|
|
26
|
-
return;
|
|
27
|
-
(0, graphql_1.visit)(file.document, {
|
|
28
|
-
FragmentDefinition: {
|
|
29
|
-
enter(node) {
|
|
30
|
-
const matchingInjections = applicableInjections.filter(injection => !injection.nameRegex || (new RegExp(injection.nameRegex)).test(node.name.value));
|
|
31
|
-
if (!matchingInjections || matchingInjections.length == 0)
|
|
32
|
-
return false;
|
|
33
|
-
matchingInjections.forEach(injection => {
|
|
34
|
-
if (config.verbose)
|
|
35
|
-
console.debug(`[ OPTIMIZELY ] Found ${node.name.value} for ${injection.into} in file ${node.loc?.source?.name}`);
|
|
36
|
-
if (!componentFragments[injection.into])
|
|
37
|
-
componentFragments[injection.into] = [];
|
|
38
|
-
if (!componentFragments[injection.into].some(f => f.name.value == node.name.value))
|
|
39
|
-
componentFragments[injection.into].push(node);
|
|
40
|
-
});
|
|
41
|
-
return undefined;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
});
|
|
44
|
+
// Process all documents to extract the fragments that must be injected
|
|
45
|
+
const componentFragments = await (0, performInjections_2.getComponentFragments)(files, transformConfig);
|
|
46
46
|
// Get the names we actually need to inject into, and return when none are present
|
|
47
|
-
const intoNames =
|
|
47
|
+
const intoNames = Array.from(componentFragments.keys());
|
|
48
48
|
if (intoNames.length == 0)
|
|
49
49
|
return files;
|
|
50
50
|
if (config.verbose)
|
|
51
|
-
|
|
51
|
+
intoNames.forEach(intoName => {
|
|
52
|
+
console.debug(`[ OPTIMIZELY ] Update queries & fragments using the fragment ${intoName} to also use the fragments: ${(componentFragments.get(intoName) ?? []).map(x => x.name).join(',')}`);
|
|
53
|
+
});
|
|
52
54
|
// Update the documents
|
|
53
55
|
const transformedFiles = files.map(file => {
|
|
54
56
|
if (config.verbose)
|
|
55
57
|
console.debug(`[ OPTIMIZELY ] Processing ${file.location}`);
|
|
56
58
|
const document = file.document ? (0, graphql_1.visit)(file.document, {
|
|
57
|
-
// Remove fragments from the preset, for which the target type does not exist
|
|
58
|
-
/*FragmentDefinition: {
|
|
59
|
-
enter(node) {
|
|
60
|
-
if (file.location && !fs.existsSync(file.location)) {
|
|
61
|
-
const typePresent = schema.definitions.some(definition => (definition.kind == Kind.OBJECT_TYPE_DEFINITION || definition.kind == Kind.INTERFACE_TYPE_DEFINITION) && definition.name.value == node.typeCondition.name.value)
|
|
62
|
-
if (!typePresent) {
|
|
63
|
-
if (config.verbose) console.debug(`[OPTIMIZELY] Type ${ node.typeCondition.name.value } not found, dropping fragment ${ node.name.value }`)
|
|
64
|
-
return null
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
},*/
|
|
69
59
|
// Replace the fragment occurances
|
|
70
60
|
SelectionSet: {
|
|
71
61
|
leave(node, key, parent, path, ancestors) {
|
|
@@ -86,10 +76,10 @@ const transform = ({ documents: files, config, schema, pluginContext }) => {
|
|
|
86
76
|
console.debug(`[ OPTIMIZELY ] Identified usage of fragment(s) ${sectionsToAdd.join(', ')} in ${parentName}, starting injection procedure`);
|
|
87
77
|
const newSelections = []; //.filter(selection => !(selection.kind == Kind.FRAGMENT_SPREAD && intoNames.includes(selection.name.value)))
|
|
88
78
|
sectionsToAdd.forEach(sectionName => {
|
|
89
|
-
const addedSelections = componentFragments[
|
|
90
|
-
if (newSelections.some(selection => selection.kind == graphql_1.Kind.FRAGMENT_SPREAD && selection.name.value == fragment.name
|
|
79
|
+
const addedSelections = (componentFragments.get(sectionName) ?? []).map(fragment => {
|
|
80
|
+
if (newSelections.some(selection => selection.kind == graphql_1.Kind.FRAGMENT_SPREAD && selection.name.value == fragment.name)) {
|
|
91
81
|
if (config.verbose)
|
|
92
|
-
console.debug(`[ OPTIMIZELY ] Fragment ${fragment.name
|
|
82
|
+
console.debug(`[ OPTIMIZELY ] Fragment ${fragment.name} is already adjacent to ${sectionName}`);
|
|
93
83
|
return undefined;
|
|
94
84
|
}
|
|
95
85
|
/*if (config.verbose)
|
|
@@ -99,7 +89,7 @@ const transform = ({ documents: files, config, schema, pluginContext }) => {
|
|
|
99
89
|
directives: [],
|
|
100
90
|
name: {
|
|
101
91
|
kind: graphql_1.Kind.NAME,
|
|
102
|
-
value: fragment.name
|
|
92
|
+
value: fragment.name
|
|
103
93
|
}
|
|
104
94
|
};
|
|
105
95
|
}).filter(isNotNullOrUndefined);
|
package/dist/transform.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../src/transform.ts"],"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,QAAQ,EAAE,QAAQ;SACnB,CAAA;IACH,CAAC,CAAC,CAAA;IAEF,IAAI,MAAM,CAAC,OAAO;QAChB,OAAO,CAAC,KAAK,CAAC,kDAAkD,CAAC,CAAA;IACnE,OAAO,gBAAgB,CAAA;AACzB,CAAC,CAAA;AA1FY,QAAA,SAAS,aA0FrB;AAED,kBAAe,EAAE,SAAS,EAAT,iBAAS,EAAE,CAAA;AAE5B,SAAS,oBAAoB,CAAI,MAAiB;IAChD,OAAO,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,SAAS,CAAA;AAChD,CAAC;AACD,SAAS,qBAAqB,CAAC,CAAmD;IAChF,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,SAAS,IAAI,CAAC,IAAI,IAAI;QACjD,OAAO,KAAK,CAAA;IACd,OAAQ,CAAa,CAAC,IAAI,IAAI,cAAI,CAAC,mBAAmB,IAAK,CAAa,CAAC,IAAI,IAAI,cAAI,CAAC,oBAAoB,CAAA;AAC5G,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,14 +1,37 @@
|
|
|
1
1
|
import type { FragmentDefinitionNode, OperationDefinitionNode } from 'graphql';
|
|
2
|
+
import type { CmsIntegrationApiOptions } from '@remkoj/optimizely-cms-api';
|
|
3
|
+
import type { ClientPresetConfig as ClientPresetOptions } from '@graphql-codegen/client-preset';
|
|
4
|
+
export type PresetOptions = ClientPresetOptions & PluginOptions & TransformOptions;
|
|
5
|
+
export type PluginOptions = {
|
|
6
|
+
functions?: string[];
|
|
7
|
+
prettyPrintQuery?: boolean;
|
|
8
|
+
clientPath?: string;
|
|
9
|
+
};
|
|
2
10
|
export type TransformOptions = {
|
|
3
11
|
/**
|
|
4
12
|
* Configure fragment injection targets and filters as a set of injection
|
|
5
13
|
* rules.
|
|
6
14
|
*/
|
|
7
15
|
injections?: Injection[];
|
|
16
|
+
/**
|
|
17
|
+
* Define whether the injection process should cleanup targeted fragments
|
|
18
|
+
* from the affected queries & fragments. Defaults to "true".
|
|
19
|
+
*
|
|
20
|
+
* Possible options:
|
|
21
|
+
* - `true`: Clean the targeted fragment spreads and proceed to remove the following fragment spreads: BlockData, PageData
|
|
22
|
+
* - `false`: Do not perform any cleaning
|
|
23
|
+
* - string[]: Remove the listed fragment spreads after processing
|
|
24
|
+
*/
|
|
25
|
+
cleanup?: boolean | string[];
|
|
8
26
|
/**
|
|
9
27
|
* Enable verbose output
|
|
10
28
|
*/
|
|
11
29
|
verbose?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Override the keys to login to Optimizely CMS to fully auto-generate
|
|
32
|
+
* fragments during the compilation process.
|
|
33
|
+
*/
|
|
34
|
+
cmsClient?: CmsIntegrationApiOptions;
|
|
12
35
|
/**
|
|
13
36
|
* Disables the recursive validation of GraphQL-Codegen and updates the
|
|
14
37
|
* rules to ensure that the code is properly generated.
|