@remkoj/optimizely-graph-functions 4.0.0 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -1
- package/dist/patch.d.ts +1 -0
- package/dist/patch.js +43 -0
- package/dist/patch.js.map +1 -0
- package/package.json +14 -10
package/README.md
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
# Optimizely GraphQL Codegen Plugin
|
|
2
2
|
GraphQL Codegen plugin and preset which generate both the GraphQL type definitions and a few convenienece methods for useage with [Optimizely Graph Client](../optimizely-graph-client/README.md).
|
|
3
3
|
|
|
4
|
+
> [!WARNING]
|
|
5
|
+
> **Version 4.1** Requires a new build of the patched Visitor Plugin Common package from GraphQL Codegen. See instructions below on updating/installing this patched version.
|
|
6
|
+
|
|
4
7
|
## Install package
|
|
5
8
|
To install using Yarn, use the following command:
|
|
6
9
|
|
|
7
10
|
```bash
|
|
8
11
|
yarn add --dev @remkoj/optimizely-graph-functions
|
|
12
|
+
yarn patch-codegen
|
|
9
13
|
```
|
|
10
14
|
|
|
15
|
+
Some updates will include a newer version of the patched Visitor Plugin Common package from GraphQL Codegen. After applying the update to this package, rerun `yarn patch-codegen` to download and apply the latest version.
|
|
16
|
+
|
|
11
17
|
## Configure package
|
|
12
18
|
Create a codegen.ts within your application root folder (e.g. apps/frontend/codegen.ts within the example site). Within the codegen.ts create the following configuration:
|
|
13
19
|
|
|
@@ -87,7 +93,7 @@ The presetConfig of the `OptimizelyGraphPreset` is an extension of the configura
|
|
|
87
93
|
|
|
88
94
|
| Configuration option | Usage |
|
|
89
95
|
| --- | --- |
|
|
90
|
-
| recursion | Set to `true` to automatically generate recursive queries to iterate down the result.<br><br>The default logic of GraphQL Codegen contains an infite loop when disabling the recursion check. To patch this, a custom resolution must be added to the root `package.json`. This resolution must set the resolution for `@graphql-codegen/visitor-plugin-common` to the patched file [provided within this repository](../../dependencies/graphql-codegen-visitor-plugin-common-v5.
|
|
96
|
+
| recursion | Set to `true` to automatically generate recursive queries to iterate down the result.<br><br>The default logic of GraphQL Codegen contains an infite loop when disabling the recursion check. To patch this, a custom resolution must be added to the root `package.json`. This resolution must set the resolution for `@graphql-codegen/visitor-plugin-common` to the patched file [provided within this repository](../../dependencies/graphql-codegen-visitor-plugin-common-v5.6.0-patched.tgz)<br/><br/>A Convenience script: `yarn patch-codegen` is available to apply these transformations automatically |
|
|
91
97
|
| injections | A set of rules to define how individual fragments will be used to construct the master queries. Each rule has the following options: <br/>- `into`: The name of the Fragment to inject into<br/>- `pathRegex`: The regular expression to be applied ot the file name to see if the fragment should be included with the `into` Fragment<br/>- `nameRegex`: The regular expression to be applied to the name of the Fragment
|
|
92
98
|
| documents | The standard rules for preset specific documents, however there are four standard documents available:<br/>- `opti-cms:/queries/13` (included by default)<br/>- `opti-cms:/queries/12`<br/>- `opti-cms:/fragments/13` (included by default)<br/>- `opti-cms:/fragments/12`<br/>*The defaults are only applied when there's no document starting with `opti-cms:` defined*
|
|
93
99
|
| functions | The list of GraphQL Functions that should be made available in the `functions.ts` file. When specified, this overrides the default list.<br/>*Default value: `['getContentType','getContentByPath','getContentById']`*
|
package/dist/patch.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/patch.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const posix_1 = __importDefault(require("node:path/posix"));
|
|
9
|
+
const node_stream_1 = require("node:stream");
|
|
10
|
+
const promises_1 = require("node:stream/promises");
|
|
11
|
+
const downloadLink = "https://github.com/remkoj/optimizely-dxp-clients/raw/refs/heads/main/dependencies/graphql-codegen-visitor-plugin-common-v5.6.0-patched.tgz";
|
|
12
|
+
const downloadFile = "graphql-codegen-visitor-plugin-common-v5.6.0-patched.tgz";
|
|
13
|
+
const downloadPath = "./packages";
|
|
14
|
+
const packageJsonPath = node_path_1.default.join(process.cwd(), 'package.json');
|
|
15
|
+
if (!node_fs_1.default.existsSync(packageJsonPath)) {
|
|
16
|
+
process.exit(0);
|
|
17
|
+
}
|
|
18
|
+
const packageData = JSON.parse(node_fs_1.default.readFileSync(packageJsonPath).toString());
|
|
19
|
+
const packageName = packageData.name ?? node_path_1.default.basename(process.cwd());
|
|
20
|
+
console.log("🚀 [Optimizely Graph Functions] Enabling recursive query support for project: " + packageName);
|
|
21
|
+
const downloadDir = node_path_1.default.normalize(node_path_1.default.join(process.cwd(), downloadPath));
|
|
22
|
+
fetch(downloadLink).then(response => {
|
|
23
|
+
if (!response.ok || !response.body)
|
|
24
|
+
return;
|
|
25
|
+
node_fs_1.default.mkdirSync(downloadDir, { recursive: true });
|
|
26
|
+
const downloadTarget = node_path_1.default.join(downloadDir, downloadFile);
|
|
27
|
+
console.log("🚀 [Optimizely Graph Functions] Downloading patched visitor-plugin-common from GitHub");
|
|
28
|
+
(0, promises_1.finished)(node_stream_1.Readable.fromWeb(response.body).pipe(node_fs_1.default.createWriteStream(downloadTarget, { flags: 'w' }))).then(() => {
|
|
29
|
+
console.log("🚀 [Optimizely Graph Functions] Downloaded patched visitor-plugin-common");
|
|
30
|
+
packageData.resolutions = packageData.resolutions || {};
|
|
31
|
+
const importPath = 'file:./' + posix_1.default.normalize(posix_1.default.join(downloadPath, downloadFile));
|
|
32
|
+
if (packageData.resolutions["@graphql-codegen/visitor-plugin-common"] != importPath) {
|
|
33
|
+
packageData.resolutions["@graphql-codegen/visitor-plugin-common"] = importPath;
|
|
34
|
+
const updatedPackageData = JSON.stringify(packageData, undefined, 2);
|
|
35
|
+
node_fs_1.default.writeFileSync(packageJsonPath, updatedPackageData, { flag: 'w' });
|
|
36
|
+
console.log("🚀 [Optimizely Graph Functions] Applied resolution to project " + packageName);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
console.log("🚀 [Optimizely Graph Functions] Resolution already exists " + packageName);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
//# sourceMappingURL=patch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patch.js","sourceRoot":"","sources":["../src/patch.ts"],"names":[],"mappings":";;;;;AAAA,sDAAwB;AACxB,0DAA4B;AAC5B,4DAAmC;AACnC,6CAAsC;AACtC,mDAA+C;AAE/C,MAAM,YAAY,GAAG,4IAA4I,CAAA;AACjK,MAAM,YAAY,GAAG,0DAA0D,CAAA;AAC/E,MAAM,YAAY,GAAG,YAAY,CAAA;AAEjC,MAAM,eAAe,GAAG,mBAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,CAAC,CAAA;AAChE,IAAI,CAAC,iBAAE,CAAC,UAAU,CAAC,eAAe,CAAC,EACnC,CAAC;IACG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACnB,CAAC;AAED,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,iBAAE,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAA;AAC3E,MAAM,WAAW,GAAG,WAAW,CAAC,IAAI,IAAI,mBAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAA;AAEpE,OAAO,CAAC,GAAG,CAAC,gFAAgF,GAAC,WAAW,CAAC,CAAA;AAEzG,MAAM,WAAW,GAAG,mBAAI,CAAC,SAAS,CAAC,mBAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,YAAY,CAAC,CAAC,CAAA;AAC1E,KAAK,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;IAChC,IA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,CAAC;IACL,CAAC,CAAC,CAAA;AACN,CAAC,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remkoj/optimizely-graph-functions",
|
|
3
3
|
"license": "Apache-2.0",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.2.0",
|
|
5
5
|
"repository": "https://github.com/remkoj/optimizely-dxp-clients.git",
|
|
6
6
|
"author": "Remko Jantzen <693172+remkoj@users.noreply.github.com>",
|
|
7
7
|
"homepage": "https://github.com/remkoj/optimizely-dxp-clients",
|
|
8
8
|
"files": [
|
|
9
9
|
"./dist"
|
|
10
10
|
],
|
|
11
|
+
"bin": {
|
|
12
|
+
"patch-codegen": "./dist/patch.js"
|
|
13
|
+
},
|
|
11
14
|
"type": "commonjs",
|
|
12
15
|
"main": "./dist/index.js",
|
|
13
16
|
"exports": {
|
|
@@ -38,11 +41,11 @@
|
|
|
38
41
|
}
|
|
39
42
|
},
|
|
40
43
|
"devDependencies": {
|
|
41
|
-
"@types/node": "^22.10.
|
|
42
|
-
"graphql": "^16.
|
|
44
|
+
"@types/node": "^22.10.7",
|
|
45
|
+
"graphql": "^16.10.0",
|
|
43
46
|
"graphql-request": "^6.1.0",
|
|
44
47
|
"graphql-tag": "^2.12.6",
|
|
45
|
-
"typescript": "^5.7.
|
|
48
|
+
"typescript": "^5.7.3"
|
|
46
49
|
},
|
|
47
50
|
"dependencies": {
|
|
48
51
|
"@graphql-codegen/add": "^5.0.3",
|
|
@@ -57,13 +60,14 @@
|
|
|
57
60
|
"clean": "tsc --build --clean",
|
|
58
61
|
"prepare": "tsc --build",
|
|
59
62
|
"recompile": "tsc --build --clean && tsc --build --force",
|
|
60
|
-
"watch": "yarn tsc --watch"
|
|
63
|
+
"watch": "yarn tsc --watch",
|
|
64
|
+
"test-patch": "node ./dist/patch.js"
|
|
61
65
|
},
|
|
62
66
|
"peerDependencies": {
|
|
63
|
-
"@graphql-typed-document-node/core": "
|
|
64
|
-
"@remkoj/optimizely-graph-client": "4
|
|
65
|
-
"graphql": "
|
|
66
|
-
"graphql-request": "^6
|
|
67
|
-
"graphql-tag": "
|
|
67
|
+
"@graphql-typed-document-node/core": "^3",
|
|
68
|
+
"@remkoj/optimizely-graph-client": "^4",
|
|
69
|
+
"graphql": "^16",
|
|
70
|
+
"graphql-request": "^6",
|
|
71
|
+
"graphql-tag": "^2"
|
|
68
72
|
}
|
|
69
73
|
}
|