@remkoj/optimizely-graph-functions 1.0.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 +13 -0
- package/README.md +99 -0
- package/dist/documents.d.ts +9 -0
- package/dist/documents.js +173 -0
- package/dist/documents.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +112 -0
- package/dist/index.js.map +1 -0
- package/dist/preset.d.ts +7 -0
- package/dist/preset.js +50 -0
- package/dist/preset.js.map +1 -0
- package/dist/src/documents.d.ts +9 -0
- package/dist/src/documents.js +173 -0
- package/dist/src/documents.js.map +1 -0
- package/dist/src/index.d.ts +30 -0
- package/dist/src/index.js +138 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/preset.d.ts +7 -0
- package/dist/src/preset.js +79 -0
- package/dist/src/preset.js.map +1 -0
- package/dist/src/transform.d.ts +11 -0
- package/dist/src/transform.js +136 -0
- package/dist/src/transform.js.map +1 -0
- package/dist/src/types.d.ts +21 -0
- package/dist/src/types.js +3 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/utils.d.ts +8 -0
- package/dist/src/utils.js +38 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/transform.d.ts +11 -0
- package/dist/transform.js +125 -0
- package/dist/transform.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types.d.ts +21 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +8 -0
- package/dist/utils.js +38 -0
- package/dist/utils.js.map +1 -0
- package/package.json +62 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2024 Remko Jantzen
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# Optimizely GraphQL Codegen Plugin
|
|
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
|
+
|
|
4
|
+
## Install package
|
|
5
|
+
This package is provided as part of the example site mono-repository and thus doesn't need to be installed separately.
|
|
6
|
+
|
|
7
|
+
## Configure package
|
|
8
|
+
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:
|
|
9
|
+
|
|
10
|
+
```typescript
|
|
11
|
+
import type { CodegenConfig } from '@graphql-codegen/cli'
|
|
12
|
+
import getSchemaInfo from '@remkoj/optimizely-graph-client/codegen'
|
|
13
|
+
import OptimizelyGraphPreset, {type PresetOptions as OptimizelyGraphPresetOptions} from '@remkoj/optimizely-graph-functions/preset'
|
|
14
|
+
|
|
15
|
+
// This example assumes the configuration can be read from the environment variables, make sure .env files (if you use them) are processed prior to invoking getSchemaInfo()
|
|
16
|
+
|
|
17
|
+
// Create the configuration itself
|
|
18
|
+
const config: CodegenConfig = {
|
|
19
|
+
schema: getSchemaInfo(),
|
|
20
|
+
documents: [
|
|
21
|
+
// Add local GQL files
|
|
22
|
+
'src/**/*.graphql',
|
|
23
|
+
|
|
24
|
+
// Add Definitions from components
|
|
25
|
+
'src/**/!(*.d).{ts,tsx}'
|
|
26
|
+
],
|
|
27
|
+
generates: {
|
|
28
|
+
'./gql/': {
|
|
29
|
+
preset: OptimizelyGraphPreset,
|
|
30
|
+
presetConfig: {
|
|
31
|
+
gqlTagName: 'gql',
|
|
32
|
+
injections: [
|
|
33
|
+
{
|
|
34
|
+
// Add from all pages, except colocated blocks
|
|
35
|
+
into: "PageData",
|
|
36
|
+
pathRegex: "src\/components\/page.*(?<!block\.tsx)$"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
// Add from all blocks, included blocks colocated with pages
|
|
40
|
+
into: "BlockData",
|
|
41
|
+
pathRegex: "src\/components\/(block.*|page.*block.[tj]s[x]{0,1})$"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
// Add from all blocks
|
|
45
|
+
into: "BlockData",
|
|
46
|
+
pathRegex: "src\/components\/block"
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
} as OptimizelyGraphPresetOptions
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
ignoreNoDocuments: false
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export default config
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Usage
|
|
59
|
+
After running the code generation, you can use the following API's (assuming the folder where the generated files are stored is available at '@gql'):
|
|
60
|
+
|
|
61
|
+
### Option 1: Direct methods
|
|
62
|
+
```typescript
|
|
63
|
+
import { getContentById, getContentByPath } from '@gql'
|
|
64
|
+
|
|
65
|
+
const client = /* fetch your client */
|
|
66
|
+
|
|
67
|
+
const contentFromId = await getContentById(client, { guidValue: '00000000-0000-0000-0000-000000000000', locale: 'en' })
|
|
68
|
+
const contentFromPath = await getContentByPath(client, { path: '/en' })
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Option 2: Enhanced Client
|
|
72
|
+
```typescript
|
|
73
|
+
import { OptimizelyGraphClient, Schema } from '@gql'
|
|
74
|
+
|
|
75
|
+
const client = new OptimizelyGraphClient({
|
|
76
|
+
single_key: "your single key here"
|
|
77
|
+
})
|
|
78
|
+
const contentId = '00000000-0000-0000-0000-000000000000'
|
|
79
|
+
const locale = Schema.Locales.En
|
|
80
|
+
|
|
81
|
+
const contentItem = await client.getContentById({ guidValue: contentId, locale })
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Query Fragments
|
|
85
|
+
The preset automatically injects the following fragments into your list of documents when generating the code. This allows optimization of the generated query size and normalize output so it can be used by the `CmsContent` and `CmsContentArea` components (Which are available in the `@remkoj/optimizely-dxp-react` package).
|
|
86
|
+
|
|
87
|
+
The following GraphQL Fragments are available:
|
|
88
|
+
|
|
89
|
+
| Name | Description |
|
|
90
|
+
| --- | --- |
|
|
91
|
+
| ContentLink | Get the fields needed from a ContentLink field, so it can be used to look up content |
|
|
92
|
+
| ContentLinkSearch | Get the fields needed from a ContentLink field, so it can be used to look up content, within a searchable context |
|
|
93
|
+
| IContentData | The fields on an IContent item needed by the `CmsContent` component to reliably determine the content type and load it's data
|
|
94
|
+
| ContentAreaItemData | Retrieve the items within a *searchable* ContentArea on a **Page** component, so that the content can be rendered by the `CmsContentArea` component
|
|
95
|
+
| BlockContentAreaItemData | Retrieve the items within a *non-searchable* ContentArea on a **Block** component, so that the content can be rendered by the `CmsContentArea` component |
|
|
96
|
+
| BlockContentAreaItemSearchData | Retrieve the items within a *searchable* ContentArea on a **Block** component, so that the content can be rendered by the `CmsContentArea` component |
|
|
97
|
+
| LinkItemData | |
|
|
98
|
+
| ImageData | |
|
|
99
|
+
| ImageDataSearch | |
|
|
@@ -0,0 +1,9 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,173 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
export declare const validate: PluginValidateFn<PluginOptions>;
|
|
9
|
+
export declare const plugin: PluginFunction<PluginOptions>;
|
|
10
|
+
declare const _default: CodegenPlugin<PluginOptions>;
|
|
11
|
+
export default _default;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.plugin = exports.validate = exports.pickPluginOptions = void 0;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
function pickPluginOptions(options) {
|
|
7
|
+
return {
|
|
8
|
+
functions: options.functions ?? ['getContentByPath', 'getContentById'],
|
|
9
|
+
prettyPrintQuery: options.prettyPrintQuery ?? false,
|
|
10
|
+
clientPath: options.clientPath ?? "./graphql"
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
exports.pickPluginOptions = pickPluginOptions;
|
|
14
|
+
const validate = (schema, document, config, outputFile, allPlugins, pluginContext) => {
|
|
15
|
+
if (config.functions) {
|
|
16
|
+
if (!Array.isArray(config.functions))
|
|
17
|
+
throw new Error("If provided functions must be an array");
|
|
18
|
+
if (config.functions.some(x => typeof (x) != 'string' || x.length == 0))
|
|
19
|
+
throw new Error("If provided functions must only contain non-empty strings");
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
exports.validate = validate;
|
|
23
|
+
const plugin = async (schema, documents, config, info) => {
|
|
24
|
+
const functions = config.functions || [];
|
|
25
|
+
if (functions.length == 0)
|
|
26
|
+
return "// NO FUNCTIONS TO BE EXPORTED";
|
|
27
|
+
const docs = (0, graphql_1.concatAST)(documents.map(x => x.document).filter(utils_1.isNotNullOrUndefined));
|
|
28
|
+
const output = functions.map(fn => {
|
|
29
|
+
try {
|
|
30
|
+
const queryNode = (0, graphql_1.getOperationAST)(docs, fn);
|
|
31
|
+
if (!(queryNode && queryNode.operation == graphql_1.OperationTypeNode.QUERY))
|
|
32
|
+
return [`export async function ${fn}() { throw new Error('No query named ${fn} defined')}`];
|
|
33
|
+
const fragments = resolveSpreads(queryNode, docs);
|
|
34
|
+
const fnTypeName = fn.charAt(0).toUpperCase() + fn.slice(1);
|
|
35
|
+
const varsType = `Types.${fnTypeName}QueryVariables`;
|
|
36
|
+
const returnType = `Types.${fnTypeName}Query`;
|
|
37
|
+
const query = [queryNode, ...fragments].map(node => (0, graphql_1.print)(node)).join("\n\n");
|
|
38
|
+
const functionBody = [];
|
|
39
|
+
functionBody.push(`export function ${fn}(client: GraphQLClient, variables: ${varsType}) : Promise<${returnType}>`);
|
|
40
|
+
functionBody.push('{');
|
|
41
|
+
functionBody.push(` const query = gql\`${config.prettyPrintQuery ? query : query.replace(/\s+/g, ' ').trim()}\``);
|
|
42
|
+
functionBody.push(` return client.request<${returnType}, ${varsType}>(query, variables)`);
|
|
43
|
+
functionBody.push('}');
|
|
44
|
+
return functionBody;
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
return [`export async function ${fn}() { throw new Error('Function generation error')}`];
|
|
48
|
+
}
|
|
49
|
+
}).flat();
|
|
50
|
+
const prepend = [];
|
|
51
|
+
const append = [];
|
|
52
|
+
prepend.push('import { gql, type GraphQLClient } from \'graphql-request\'');
|
|
53
|
+
prepend.push('import { ContentGraphClient as BaseGraphClient } from \'@remkoj/optimizely-graph-client\'');
|
|
54
|
+
prepend.push(`import type * as Types from './graphql'`);
|
|
55
|
+
prepend.push("\n");
|
|
56
|
+
append.push("\n\n");
|
|
57
|
+
append.push(generateClientClass(functions));
|
|
58
|
+
return { prepend, content: output.join("\n"), append };
|
|
59
|
+
};
|
|
60
|
+
exports.plugin = plugin;
|
|
61
|
+
function resolveSpreads(definition, document, availableFragments = []) {
|
|
62
|
+
const spreadNames = [];
|
|
63
|
+
(0, graphql_1.visit)(definition, {
|
|
64
|
+
"FragmentSpread": {
|
|
65
|
+
leave(node) {
|
|
66
|
+
if (!availableFragments.includes(node.name.value))
|
|
67
|
+
spreadNames.push(node.name.value);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
const fragments = [];
|
|
72
|
+
(0, graphql_1.visit)(document, {
|
|
73
|
+
FragmentDefinition: {
|
|
74
|
+
leave(node) {
|
|
75
|
+
if (spreadNames.includes(node.name.value))
|
|
76
|
+
fragments.push(node);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
const dependencies = [];
|
|
81
|
+
const availableFragmentNames = [...availableFragments, ...fragments.map(x => x.name.value)];
|
|
82
|
+
fragments.forEach(fragment => {
|
|
83
|
+
const resolvedSpreads = [...availableFragmentNames, ...dependencies.map(x => x.name.value)];
|
|
84
|
+
const fragmentDependencies = resolveSpreads(fragment, document, resolvedSpreads);
|
|
85
|
+
dependencies.push(...fragmentDependencies);
|
|
86
|
+
});
|
|
87
|
+
return [...fragments, ...dependencies];
|
|
88
|
+
}
|
|
89
|
+
function generateClientClass(functions) {
|
|
90
|
+
return `/**
|
|
91
|
+
* Function client for Optimizely Graph, exposing both the raw request method,
|
|
92
|
+
* as well as the high level convenience methods to read content from
|
|
93
|
+
* Optimizely Graph. The actual format for each of the Content Items returned
|
|
94
|
+
* by these convenience methods is defined by the GraphQL Fragments within the
|
|
95
|
+
* application codebase.
|
|
96
|
+
*/
|
|
97
|
+
export class OptimizelyGraphClient extends BaseGraphClient {
|
|
98
|
+
|
|
99
|
+
${functions.map(fn => {
|
|
100
|
+
const fnTypeName = fn.charAt(0).toUpperCase() + fn.slice(1);
|
|
101
|
+
const fnNamespace = "Types";
|
|
102
|
+
const varsType = `${fnNamespace}.${fnTypeName}QueryVariables`;
|
|
103
|
+
const returnType = `${fnNamespace}.${fnTypeName}Query`;
|
|
104
|
+
return ` public ${fn}(variables: ${varsType}) : Promise<${returnType}>
|
|
105
|
+
{
|
|
106
|
+
return ${fn}(this, variables)
|
|
107
|
+
}`;
|
|
108
|
+
}).join('\n\n')}
|
|
109
|
+
}`;
|
|
110
|
+
}
|
|
111
|
+
exports.default = { validate: exports.validate, plugin: exports.plugin };
|
|
112
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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;AAYM,MAAM,QAAQ,GAAoC,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,EAAE;IAEzH,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;QACnB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC;YAChC,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAA;QAE7D,IAAI,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,OAAM,CAAC,CAAC,CAAC,IAAI,QAAQ,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC;YAClE,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAA;IACpF,CAAC;AACL,CAAC,CAAA;AATY,QAAA,QAAQ,YASpB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5C,OAAO;;;;;;;;;EASR,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;QAClB,MAAM,UAAU,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;QAC3D,MAAM,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.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Types } from '@graphql-codegen/plugin-helpers';
|
|
2
|
+
import { type ClientPresetConfig as ClientPresetOptions } from '@graphql-codegen/client-preset';
|
|
3
|
+
import { type PluginOptions } from './index';
|
|
4
|
+
import { type TransformOptions } from './transform';
|
|
5
|
+
export type PresetOptions = ClientPresetOptions & PluginOptions & TransformOptions;
|
|
6
|
+
export declare const preset: Types.OutputPreset<PresetOptions>;
|
|
7
|
+
export default preset;
|
package/dist/preset.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.preset = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const documents_1 = require("./documents");
|
|
6
|
+
const client_preset_1 = require("@graphql-codegen/client-preset");
|
|
7
|
+
const index_1 = tslib_1.__importStar(require("./index"));
|
|
8
|
+
const transform_1 = tslib_1.__importStar(require("./transform"));
|
|
9
|
+
exports.preset = {
|
|
10
|
+
prepareDocuments: async (outputFilePath, outputSpecificDocuments) => {
|
|
11
|
+
const documents = client_preset_1.preset.prepareDocuments ? await client_preset_1.preset.prepareDocuments(outputFilePath, outputSpecificDocuments) : [...outputSpecificDocuments, `!${outputFilePath}`];
|
|
12
|
+
documents.push([...documents_1.fragments, ...documents_1.queries].join("\n"));
|
|
13
|
+
return documents;
|
|
14
|
+
},
|
|
15
|
+
buildGeneratesSection: async (options) => {
|
|
16
|
+
options.documentTransforms = [
|
|
17
|
+
{
|
|
18
|
+
name: 'optly-transform',
|
|
19
|
+
transformObject: transform_1.default,
|
|
20
|
+
config: (0, transform_1.pickTransformOptions)(options.presetConfig)
|
|
21
|
+
}
|
|
22
|
+
];
|
|
23
|
+
const section = await client_preset_1.preset.buildGeneratesSection(options);
|
|
24
|
+
section.push({
|
|
25
|
+
filename: `${options.baseOutputDir}functions.ts`,
|
|
26
|
+
pluginMap: {
|
|
27
|
+
['optly-functions']: index_1.default
|
|
28
|
+
},
|
|
29
|
+
plugins: [
|
|
30
|
+
{
|
|
31
|
+
['optly-functions']: {}
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
schema: options.schema,
|
|
35
|
+
config: (0, index_1.pickPluginOptions)(options.presetConfig),
|
|
36
|
+
documents: options.documents,
|
|
37
|
+
documentTransforms: options.documentTransforms
|
|
38
|
+
});
|
|
39
|
+
section.forEach((fileConfig, idx) => {
|
|
40
|
+
if (fileConfig.filename.endsWith("index.ts")) {
|
|
41
|
+
const currentContent = section[idx].plugins[0]?.add?.content;
|
|
42
|
+
if (currentContent)
|
|
43
|
+
section[idx].plugins[0].add.content = `export * as Schema from "./graphql";\n${currentContent}\nexport * from "./functions";`;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
return section;
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
exports.default = exports.preset;
|
|
50
|
+
//# sourceMappingURL=preset.js.map
|
|
@@ -0,0 +1 @@
|
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C5B,kBAAkB,EAAE,OAAO,CAAC,kBAAkB;SACjD,CAAC,CAAA;QAGF,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"}
|
|
@@ -0,0 +1,9 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,173 @@
|
|
|
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
|