@axinom/mosaic-graphql-codegen-plugins 0.9.0 → 0.10.0-rc.4
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/generate-bulk-edit-ui-config/generate-bulk-edit-ui-config.js +24 -1
- package/dist/generate-bulk-edit-ui-config/model.d.ts +7 -0
- package/package.json +2 -2
- package/src/generate-bulk-edit-ui-config/generate-bulk-edit-ui-config.ts +41 -6
- package/src/generate-bulk-edit-ui-config/model.ts +7 -0
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.plugin = void 0;
|
|
4
4
|
const change_case_all_1 = require("change-case-all");
|
|
5
|
+
const graphql_1 = require("graphql");
|
|
5
6
|
const plugin = (schema, _documents, config) => {
|
|
6
7
|
const addKey = config.addKey || 'relatedEntitiesToAdd';
|
|
7
8
|
const removeKey = config.removeKey || 'relatedEntitiesToRemove';
|
|
@@ -40,8 +41,15 @@ const plugin = (schema, _documents, config) => {
|
|
|
40
41
|
formFieldsConfig = resolveClearValues(typesMap[clearArg.type.toString()].getFields(), formFieldsConfig, removeKey);
|
|
41
42
|
}
|
|
42
43
|
}
|
|
44
|
+
// Collect the names of enum-backed fields on the filter input type, so the
|
|
45
|
+
// mutation generator can emit their values as bare GraphQL enum literals
|
|
46
|
+
// (e.g. `status: { in: [ACTIVE] }`) instead of quoted strings.
|
|
47
|
+
const filterArg = mutation.args.find((a) => a.name === filterKey);
|
|
48
|
+
const filterEnumFields = filterArg
|
|
49
|
+
? resolveFilterEnumFields((0, graphql_1.getNamedType)(filterArg.type))
|
|
50
|
+
: [];
|
|
43
51
|
if (Object.keys(formFieldsConfig).length > 0) {
|
|
44
|
-
return `export const ${(0, change_case_all_1.pascalCase)(mutationName)}FormFieldsConfig = { mutation: '${mutationName}', keys: { add: '${addKey}', remove: '${removeKey}', clear: '${clearKey}', set: '${setKey}', filter: '${filterKey}' }, fields: ${JSON.stringify(formFieldsConfig, null, 2)}};`;
|
|
52
|
+
return `export const ${(0, change_case_all_1.pascalCase)(mutationName)}FormFieldsConfig = { mutation: '${mutationName}', keys: { add: '${addKey}', remove: '${removeKey}', clear: '${clearKey}', set: '${setKey}', filter: '${filterKey}' }, filterEnumFields: ${JSON.stringify(filterEnumFields)}, fields: ${JSON.stringify(formFieldsConfig, null, 2)}};`;
|
|
45
53
|
}
|
|
46
54
|
});
|
|
47
55
|
return ['/** Bulk Edit Configurations **/', ...configs]
|
|
@@ -85,6 +93,21 @@ function resolveFields(fields, action, postfix = '') {
|
|
|
85
93
|
});
|
|
86
94
|
return resultingFields;
|
|
87
95
|
}
|
|
96
|
+
// Returns the names of the filter fields whose condition type is backed by an
|
|
97
|
+
// enum (e.g. `status` -> `UserStatusFilter` -> `in: [UserStatus]`). Logical
|
|
98
|
+
// fields (`and`/`or`/`not`) and relation filters resolve to filter input types
|
|
99
|
+
// that have no direct enum member, so they are naturally excluded.
|
|
100
|
+
function resolveFilterEnumFields(filterType) {
|
|
101
|
+
if (!(0, graphql_1.isInputObjectType)(filterType)) {
|
|
102
|
+
return [];
|
|
103
|
+
}
|
|
104
|
+
const fields = filterType.getFields();
|
|
105
|
+
return Object.keys(fields).filter((fieldName) => {
|
|
106
|
+
const conditionType = (0, graphql_1.getNamedType)(fields[fieldName].type);
|
|
107
|
+
return ((0, graphql_1.isInputObjectType)(conditionType) &&
|
|
108
|
+
Object.values(conditionType.getFields()).some((member) => (0, graphql_1.isEnumType)((0, graphql_1.getNamedType)(member.type))));
|
|
109
|
+
});
|
|
110
|
+
}
|
|
88
111
|
// If relatedEntitiesToClear contains a field make the clearable field true on the corresponding relatedEntitiesToRemove field.
|
|
89
112
|
function resolveClearValues(fields, fieldMap, action) {
|
|
90
113
|
const resultingFields = Object.assign({}, fieldMap);
|
|
@@ -20,5 +20,12 @@ export interface BulkEditConfig {
|
|
|
20
20
|
set: string;
|
|
21
21
|
filter: string;
|
|
22
22
|
};
|
|
23
|
+
/**
|
|
24
|
+
* Names of the filter fields whose values are backed by a GraphQL enum.
|
|
25
|
+
* Their values are wrapped so they are emitted as bare enum literals
|
|
26
|
+
* (e.g. `status: { in: [ACTIVE] }`) rather than quoted strings when the
|
|
27
|
+
* filter is inlined into the generated mutation document.
|
|
28
|
+
*/
|
|
29
|
+
filterEnumFields?: string[];
|
|
23
30
|
fields: BulkEditFieldConfigMap;
|
|
24
31
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axinom/mosaic-graphql-codegen-plugins",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0-rc.4",
|
|
4
4
|
"description": "Library of graphql-codegen plugins for Mosaic workflows",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "tsc -w",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"publishConfig": {
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "1286a116f2e06be15726a9094b19987c56d3bc49"
|
|
49
49
|
}
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
import { PluginFunction } from '@graphql-codegen/plugin-helpers';
|
|
3
3
|
import { capitalCase, pascalCase } from 'change-case-all';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
getNamedType,
|
|
6
|
+
GraphQLFieldMap,
|
|
7
|
+
GraphQLInputObjectType,
|
|
8
|
+
GraphQLList,
|
|
9
|
+
GraphQLObjectType,
|
|
10
|
+
isEnumType,
|
|
11
|
+
isInputObjectType,
|
|
12
|
+
} from 'graphql';
|
|
5
13
|
import { BulkEditFieldConfigMap } from './model';
|
|
6
14
|
|
|
7
15
|
export interface BulkEditPluginConfig {
|
|
@@ -87,14 +95,20 @@ export const plugin: PluginFunction<Partial<BulkEditPluginConfig>> = (
|
|
|
87
95
|
}
|
|
88
96
|
}
|
|
89
97
|
|
|
98
|
+
// Collect the names of enum-backed fields on the filter input type, so the
|
|
99
|
+
// mutation generator can emit their values as bare GraphQL enum literals
|
|
100
|
+
// (e.g. `status: { in: [ACTIVE] }`) instead of quoted strings.
|
|
101
|
+
const filterArg = mutation.args.find((a) => a.name === filterKey);
|
|
102
|
+
const filterEnumFields = filterArg
|
|
103
|
+
? resolveFilterEnumFields(getNamedType(filterArg.type))
|
|
104
|
+
: [];
|
|
105
|
+
|
|
90
106
|
if (Object.keys(formFieldsConfig).length > 0) {
|
|
91
107
|
return `export const ${pascalCase(
|
|
92
108
|
mutationName,
|
|
93
|
-
)}FormFieldsConfig = { mutation: '${mutationName}', keys: { add: '${addKey}', remove: '${removeKey}', clear: '${clearKey}', set: '${setKey}', filter: '${filterKey}' },
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
2,
|
|
97
|
-
)}};`;
|
|
109
|
+
)}FormFieldsConfig = { mutation: '${mutationName}', keys: { add: '${addKey}', remove: '${removeKey}', clear: '${clearKey}', set: '${setKey}', filter: '${filterKey}' }, filterEnumFields: ${JSON.stringify(
|
|
110
|
+
filterEnumFields,
|
|
111
|
+
)}, fields: ${JSON.stringify(formFieldsConfig, null, 2)}};`;
|
|
98
112
|
}
|
|
99
113
|
});
|
|
100
114
|
|
|
@@ -152,6 +166,27 @@ function resolveFields(
|
|
|
152
166
|
return resultingFields;
|
|
153
167
|
}
|
|
154
168
|
|
|
169
|
+
// Returns the names of the filter fields whose condition type is backed by an
|
|
170
|
+
// enum (e.g. `status` -> `UserStatusFilter` -> `in: [UserStatus]`). Logical
|
|
171
|
+
// fields (`and`/`or`/`not`) and relation filters resolve to filter input types
|
|
172
|
+
// that have no direct enum member, so they are naturally excluded.
|
|
173
|
+
function resolveFilterEnumFields(filterType: unknown): string[] {
|
|
174
|
+
if (!isInputObjectType(filterType)) {
|
|
175
|
+
return [];
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const fields = (filterType as GraphQLInputObjectType).getFields();
|
|
179
|
+
return Object.keys(fields).filter((fieldName) => {
|
|
180
|
+
const conditionType = getNamedType(fields[fieldName].type);
|
|
181
|
+
return (
|
|
182
|
+
isInputObjectType(conditionType) &&
|
|
183
|
+
Object.values(conditionType.getFields()).some((member) =>
|
|
184
|
+
isEnumType(getNamedType(member.type)),
|
|
185
|
+
)
|
|
186
|
+
);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
|
|
155
190
|
// If relatedEntitiesToClear contains a field make the clearable field true on the corresponding relatedEntitiesToRemove field.
|
|
156
191
|
function resolveClearValues(
|
|
157
192
|
fields: GraphQLFieldMap<any, any>,
|
|
@@ -21,5 +21,12 @@ export interface BulkEditConfig {
|
|
|
21
21
|
set: string;
|
|
22
22
|
filter: string;
|
|
23
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* Names of the filter fields whose values are backed by a GraphQL enum.
|
|
26
|
+
* Their values are wrapped so they are emitted as bare enum literals
|
|
27
|
+
* (e.g. `status: { in: [ACTIVE] }`) rather than quoted strings when the
|
|
28
|
+
* filter is inlined into the generated mutation document.
|
|
29
|
+
*/
|
|
30
|
+
filterEnumFields?: string[];
|
|
24
31
|
fields: BulkEditFieldConfigMap;
|
|
25
32
|
}
|