@graphql-mesh/transform-filter-schema 1.0.0-alpha-3fc47d119.0 → 1.0.0-alpha-20230420181317-a95037648
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/cjs/bareFilter.js +78 -0
- package/cjs/index.js +17 -0
- package/cjs/package.json +1 -0
- package/cjs/wrapFilter.js +80 -0
- package/esm/bareFilter.js +74 -0
- package/esm/index.js +14 -0
- package/esm/wrapFilter.js +76 -0
- package/package.json +27 -20
- package/typings/bareFilter.d.ts +13 -0
- package/typings/index.d.cts +10 -0
- package/{index.d.ts → typings/index.d.ts} +2 -2
- package/typings/wrapFilter.d.cts +13 -0
- package/{wrapFilter.d.ts → typings/wrapFilter.d.ts} +4 -4
- package/index.js +0 -160
- package/index.mjs +0 -156
- /package/{bareFilter.d.ts → typings/bareFilter.d.cts} +0 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const minimatch_1 = tslib_1.__importDefault(require("minimatch"));
|
|
5
|
+
const utils_1 = require("@graphql-tools/utils");
|
|
6
|
+
class BareFilter {
|
|
7
|
+
constructor({ config: { filters } }) {
|
|
8
|
+
this.noWrap = true;
|
|
9
|
+
this.typeGlobs = [];
|
|
10
|
+
this.fieldsMap = new Map();
|
|
11
|
+
this.argsMap = new Map();
|
|
12
|
+
for (const filter of filters) {
|
|
13
|
+
const [typeName, fieldNameOrGlob, argsGlob] = filter.split('.');
|
|
14
|
+
// TODO: deprecate this in next major release as dscussed in #1605
|
|
15
|
+
if (!fieldNameOrGlob) {
|
|
16
|
+
this.typeGlobs.push(typeName);
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
const rawGlob = argsGlob || fieldNameOrGlob;
|
|
20
|
+
const fixedGlob = rawGlob.includes('{') && !rawGlob.includes(',')
|
|
21
|
+
? rawGlob.replace('{', '').replace('}', '')
|
|
22
|
+
: rawGlob;
|
|
23
|
+
const polishedGlob = fixedGlob.split(', ').join(',').trim();
|
|
24
|
+
if (typeName === 'Type') {
|
|
25
|
+
this.typeGlobs.push(polishedGlob);
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
const mapName = argsGlob ? 'argsMap' : 'fieldsMap';
|
|
29
|
+
const mapKey = argsGlob ? `${typeName}.${fieldNameOrGlob}` : typeName;
|
|
30
|
+
const currentRules = this[mapName].get(mapKey) || [];
|
|
31
|
+
this[mapName].set(mapKey, [...currentRules, polishedGlob]);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
matchInArray(rulesArray, value) {
|
|
35
|
+
for (const rule of rulesArray) {
|
|
36
|
+
const ruleMatcher = new minimatch_1.default.Minimatch(rule);
|
|
37
|
+
if (!ruleMatcher.match(value))
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
transformSchema(schema) {
|
|
43
|
+
const transformedSchema = (0, utils_1.mapSchema)(schema, {
|
|
44
|
+
...(this.typeGlobs.length && {
|
|
45
|
+
[utils_1.MapperKind.TYPE]: type => this.matchInArray(this.typeGlobs, type.toString()),
|
|
46
|
+
}),
|
|
47
|
+
...((this.fieldsMap.size || this.argsMap.size) && {
|
|
48
|
+
[utils_1.MapperKind.COMPOSITE_FIELD]: (fieldConfig, fieldName, typeName) => {
|
|
49
|
+
const fieldRules = this.fieldsMap.get(typeName);
|
|
50
|
+
const wildcardArgRules = this.argsMap.get(`${typeName}.*`) || [];
|
|
51
|
+
const fieldArgRules = this.argsMap.get(`${typeName}.${fieldName}`) || [];
|
|
52
|
+
const argRules = wildcardArgRules.concat(fieldArgRules);
|
|
53
|
+
const hasFieldRules = Boolean(fieldRules && fieldRules.length);
|
|
54
|
+
const hasArgRules = Boolean(argRules && argRules.length);
|
|
55
|
+
if (hasFieldRules && this.matchInArray(fieldRules, fieldName) === null)
|
|
56
|
+
return null;
|
|
57
|
+
if (!hasArgRules)
|
|
58
|
+
return undefined;
|
|
59
|
+
const fieldArgs = Object.entries(fieldConfig.args).reduce((args, [argName, argConfig]) => this.matchInArray(argRules, argName) === null
|
|
60
|
+
? args
|
|
61
|
+
: { ...args, [argName]: argConfig }, {});
|
|
62
|
+
return { ...fieldConfig, args: fieldArgs };
|
|
63
|
+
},
|
|
64
|
+
}),
|
|
65
|
+
...(this.fieldsMap.size && {
|
|
66
|
+
[utils_1.MapperKind.INPUT_OBJECT_FIELD]: (_, fieldName, typeName) => {
|
|
67
|
+
const fieldRules = this.fieldsMap.get(typeName);
|
|
68
|
+
const hasFieldRules = Boolean(fieldRules && fieldRules.length);
|
|
69
|
+
if (hasFieldRules && this.matchInArray(fieldRules, fieldName) === null)
|
|
70
|
+
return null;
|
|
71
|
+
return undefined;
|
|
72
|
+
},
|
|
73
|
+
}),
|
|
74
|
+
});
|
|
75
|
+
return transformedSchema;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.default = BareFilter;
|
package/cjs/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const bareFilter_js_1 = tslib_1.__importDefault(require("./bareFilter.js"));
|
|
5
|
+
const wrapFilter_js_1 = tslib_1.__importDefault(require("./wrapFilter.js"));
|
|
6
|
+
exports.default = (function FilterTransform(options) {
|
|
7
|
+
if (Array.isArray(options.config)) {
|
|
8
|
+
return new wrapFilter_js_1.default({
|
|
9
|
+
...options,
|
|
10
|
+
config: {
|
|
11
|
+
mode: 'wrap',
|
|
12
|
+
filters: options.config,
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return options.config.mode === 'bare' ? new bareFilter_js_1.default(options) : new wrapFilter_js_1.default(options);
|
|
17
|
+
});
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const minimatch_1 = tslib_1.__importDefault(require("minimatch"));
|
|
5
|
+
const utils_1 = require("@graphql-mesh/utils");
|
|
6
|
+
const wrap_1 = require("@graphql-tools/wrap");
|
|
7
|
+
class WrapFilter {
|
|
8
|
+
constructor({ config: { filters } }) {
|
|
9
|
+
this.transforms = [];
|
|
10
|
+
for (const filter of filters) {
|
|
11
|
+
const [typeName, fieldNameOrGlob, argsGlob] = filter.split('.');
|
|
12
|
+
const typeMatcher = new minimatch_1.default.Minimatch(typeName);
|
|
13
|
+
// TODO: deprecate this in next major release as dscussed in #1605
|
|
14
|
+
if (!fieldNameOrGlob) {
|
|
15
|
+
this.transforms.push(new wrap_1.FilterTypes(type => {
|
|
16
|
+
return typeMatcher.match(type.name);
|
|
17
|
+
}));
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
let fixedFieldGlob = argsGlob || fieldNameOrGlob;
|
|
21
|
+
if (fixedFieldGlob.includes('{') && !fixedFieldGlob.includes(',')) {
|
|
22
|
+
fixedFieldGlob = fieldNameOrGlob.replace('{', '').replace('}', '');
|
|
23
|
+
}
|
|
24
|
+
fixedFieldGlob = fixedFieldGlob.split(', ').join(',');
|
|
25
|
+
const globalTypeMatcher = new minimatch_1.default.Minimatch(fixedFieldGlob.trim());
|
|
26
|
+
if (typeName === 'Type') {
|
|
27
|
+
this.transforms.push(new wrap_1.FilterTypes(type => {
|
|
28
|
+
return globalTypeMatcher.match(type.name);
|
|
29
|
+
}));
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (argsGlob) {
|
|
33
|
+
const fieldMatcher = new minimatch_1.default.Minimatch(fieldNameOrGlob);
|
|
34
|
+
this.transforms.push(new wrap_1.TransformCompositeFields((fieldTypeName, fieldName, fieldConfig) => {
|
|
35
|
+
if (typeMatcher.match(fieldTypeName) && fieldMatcher.match(fieldName)) {
|
|
36
|
+
const fieldArgs = Object.entries(fieldConfig.args).reduce((args, [argName, argConfig]) => !globalTypeMatcher.match(argName) ? args : { ...args, [argName]: argConfig }, {});
|
|
37
|
+
return { ...fieldConfig, args: fieldArgs };
|
|
38
|
+
}
|
|
39
|
+
return undefined;
|
|
40
|
+
}));
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
// If the glob is not for Types nor Args, finally we register Fields filters
|
|
44
|
+
this.transforms.push(new wrap_1.FilterRootFields((rootTypeName, rootFieldName) => {
|
|
45
|
+
if (typeMatcher.match(rootTypeName)) {
|
|
46
|
+
return globalTypeMatcher.match(rootFieldName);
|
|
47
|
+
}
|
|
48
|
+
return true;
|
|
49
|
+
}));
|
|
50
|
+
this.transforms.push(new wrap_1.FilterObjectFields((objectTypeName, objectFieldName) => {
|
|
51
|
+
if (typeMatcher.match(objectTypeName)) {
|
|
52
|
+
return globalTypeMatcher.match(objectFieldName);
|
|
53
|
+
}
|
|
54
|
+
return true;
|
|
55
|
+
}));
|
|
56
|
+
this.transforms.push(new wrap_1.FilterInputObjectFields((inputObjectTypeName, inputObjectFieldName) => {
|
|
57
|
+
if (typeMatcher.match(inputObjectTypeName)) {
|
|
58
|
+
return globalTypeMatcher.match(inputObjectFieldName);
|
|
59
|
+
}
|
|
60
|
+
return true;
|
|
61
|
+
}));
|
|
62
|
+
this.transforms.push(new wrap_1.FilterInterfaceFields((interfaceTypeName, interfaceFieldName) => {
|
|
63
|
+
if (typeMatcher.match(interfaceTypeName)) {
|
|
64
|
+
return globalTypeMatcher.match(interfaceFieldName);
|
|
65
|
+
}
|
|
66
|
+
return true;
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
transformSchema(originalWrappingSchema, subschemaConfig, transformedSchema) {
|
|
71
|
+
return (0, utils_1.applySchemaTransforms)(originalWrappingSchema, subschemaConfig, transformedSchema, this.transforms);
|
|
72
|
+
}
|
|
73
|
+
transformRequest(originalRequest, delegationContext, transformationContext) {
|
|
74
|
+
return (0, utils_1.applyRequestTransforms)(originalRequest, delegationContext, transformationContext, this.transforms);
|
|
75
|
+
}
|
|
76
|
+
transformResult(originalResult, delegationContext, transformationContext) {
|
|
77
|
+
return (0, utils_1.applyResultTransforms)(originalResult, delegationContext, transformationContext, this.transforms);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.default = WrapFilter;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import minimatch from 'minimatch';
|
|
2
|
+
import { MapperKind, mapSchema } from '@graphql-tools/utils';
|
|
3
|
+
export default class BareFilter {
|
|
4
|
+
constructor({ config: { filters } }) {
|
|
5
|
+
this.noWrap = true;
|
|
6
|
+
this.typeGlobs = [];
|
|
7
|
+
this.fieldsMap = new Map();
|
|
8
|
+
this.argsMap = new Map();
|
|
9
|
+
for (const filter of filters) {
|
|
10
|
+
const [typeName, fieldNameOrGlob, argsGlob] = filter.split('.');
|
|
11
|
+
// TODO: deprecate this in next major release as dscussed in #1605
|
|
12
|
+
if (!fieldNameOrGlob) {
|
|
13
|
+
this.typeGlobs.push(typeName);
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
const rawGlob = argsGlob || fieldNameOrGlob;
|
|
17
|
+
const fixedGlob = rawGlob.includes('{') && !rawGlob.includes(',')
|
|
18
|
+
? rawGlob.replace('{', '').replace('}', '')
|
|
19
|
+
: rawGlob;
|
|
20
|
+
const polishedGlob = fixedGlob.split(', ').join(',').trim();
|
|
21
|
+
if (typeName === 'Type') {
|
|
22
|
+
this.typeGlobs.push(polishedGlob);
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
const mapName = argsGlob ? 'argsMap' : 'fieldsMap';
|
|
26
|
+
const mapKey = argsGlob ? `${typeName}.${fieldNameOrGlob}` : typeName;
|
|
27
|
+
const currentRules = this[mapName].get(mapKey) || [];
|
|
28
|
+
this[mapName].set(mapKey, [...currentRules, polishedGlob]);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
matchInArray(rulesArray, value) {
|
|
32
|
+
for (const rule of rulesArray) {
|
|
33
|
+
const ruleMatcher = new minimatch.Minimatch(rule);
|
|
34
|
+
if (!ruleMatcher.match(value))
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
transformSchema(schema) {
|
|
40
|
+
const transformedSchema = mapSchema(schema, {
|
|
41
|
+
...(this.typeGlobs.length && {
|
|
42
|
+
[MapperKind.TYPE]: type => this.matchInArray(this.typeGlobs, type.toString()),
|
|
43
|
+
}),
|
|
44
|
+
...((this.fieldsMap.size || this.argsMap.size) && {
|
|
45
|
+
[MapperKind.COMPOSITE_FIELD]: (fieldConfig, fieldName, typeName) => {
|
|
46
|
+
const fieldRules = this.fieldsMap.get(typeName);
|
|
47
|
+
const wildcardArgRules = this.argsMap.get(`${typeName}.*`) || [];
|
|
48
|
+
const fieldArgRules = this.argsMap.get(`${typeName}.${fieldName}`) || [];
|
|
49
|
+
const argRules = wildcardArgRules.concat(fieldArgRules);
|
|
50
|
+
const hasFieldRules = Boolean(fieldRules && fieldRules.length);
|
|
51
|
+
const hasArgRules = Boolean(argRules && argRules.length);
|
|
52
|
+
if (hasFieldRules && this.matchInArray(fieldRules, fieldName) === null)
|
|
53
|
+
return null;
|
|
54
|
+
if (!hasArgRules)
|
|
55
|
+
return undefined;
|
|
56
|
+
const fieldArgs = Object.entries(fieldConfig.args).reduce((args, [argName, argConfig]) => this.matchInArray(argRules, argName) === null
|
|
57
|
+
? args
|
|
58
|
+
: { ...args, [argName]: argConfig }, {});
|
|
59
|
+
return { ...fieldConfig, args: fieldArgs };
|
|
60
|
+
},
|
|
61
|
+
}),
|
|
62
|
+
...(this.fieldsMap.size && {
|
|
63
|
+
[MapperKind.INPUT_OBJECT_FIELD]: (_, fieldName, typeName) => {
|
|
64
|
+
const fieldRules = this.fieldsMap.get(typeName);
|
|
65
|
+
const hasFieldRules = Boolean(fieldRules && fieldRules.length);
|
|
66
|
+
if (hasFieldRules && this.matchInArray(fieldRules, fieldName) === null)
|
|
67
|
+
return null;
|
|
68
|
+
return undefined;
|
|
69
|
+
},
|
|
70
|
+
}),
|
|
71
|
+
});
|
|
72
|
+
return transformedSchema;
|
|
73
|
+
}
|
|
74
|
+
}
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import BareFilter from './bareFilter.js';
|
|
2
|
+
import WrapFilter from './wrapFilter.js';
|
|
3
|
+
export default (function FilterTransform(options) {
|
|
4
|
+
if (Array.isArray(options.config)) {
|
|
5
|
+
return new WrapFilter({
|
|
6
|
+
...options,
|
|
7
|
+
config: {
|
|
8
|
+
mode: 'wrap',
|
|
9
|
+
filters: options.config,
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
return options.config.mode === 'bare' ? new BareFilter(options) : new WrapFilter(options);
|
|
14
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import minimatch from 'minimatch';
|
|
2
|
+
import { applyRequestTransforms, applyResultTransforms, applySchemaTransforms, } from '@graphql-mesh/utils';
|
|
3
|
+
import { FilterInputObjectFields, FilterInterfaceFields, FilterObjectFields, FilterRootFields, FilterTypes, TransformCompositeFields, } from '@graphql-tools/wrap';
|
|
4
|
+
export default class WrapFilter {
|
|
5
|
+
constructor({ config: { filters } }) {
|
|
6
|
+
this.transforms = [];
|
|
7
|
+
for (const filter of filters) {
|
|
8
|
+
const [typeName, fieldNameOrGlob, argsGlob] = filter.split('.');
|
|
9
|
+
const typeMatcher = new minimatch.Minimatch(typeName);
|
|
10
|
+
// TODO: deprecate this in next major release as dscussed in #1605
|
|
11
|
+
if (!fieldNameOrGlob) {
|
|
12
|
+
this.transforms.push(new FilterTypes(type => {
|
|
13
|
+
return typeMatcher.match(type.name);
|
|
14
|
+
}));
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
let fixedFieldGlob = argsGlob || fieldNameOrGlob;
|
|
18
|
+
if (fixedFieldGlob.includes('{') && !fixedFieldGlob.includes(',')) {
|
|
19
|
+
fixedFieldGlob = fieldNameOrGlob.replace('{', '').replace('}', '');
|
|
20
|
+
}
|
|
21
|
+
fixedFieldGlob = fixedFieldGlob.split(', ').join(',');
|
|
22
|
+
const globalTypeMatcher = new minimatch.Minimatch(fixedFieldGlob.trim());
|
|
23
|
+
if (typeName === 'Type') {
|
|
24
|
+
this.transforms.push(new FilterTypes(type => {
|
|
25
|
+
return globalTypeMatcher.match(type.name);
|
|
26
|
+
}));
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (argsGlob) {
|
|
30
|
+
const fieldMatcher = new minimatch.Minimatch(fieldNameOrGlob);
|
|
31
|
+
this.transforms.push(new TransformCompositeFields((fieldTypeName, fieldName, fieldConfig) => {
|
|
32
|
+
if (typeMatcher.match(fieldTypeName) && fieldMatcher.match(fieldName)) {
|
|
33
|
+
const fieldArgs = Object.entries(fieldConfig.args).reduce((args, [argName, argConfig]) => !globalTypeMatcher.match(argName) ? args : { ...args, [argName]: argConfig }, {});
|
|
34
|
+
return { ...fieldConfig, args: fieldArgs };
|
|
35
|
+
}
|
|
36
|
+
return undefined;
|
|
37
|
+
}));
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
// If the glob is not for Types nor Args, finally we register Fields filters
|
|
41
|
+
this.transforms.push(new FilterRootFields((rootTypeName, rootFieldName) => {
|
|
42
|
+
if (typeMatcher.match(rootTypeName)) {
|
|
43
|
+
return globalTypeMatcher.match(rootFieldName);
|
|
44
|
+
}
|
|
45
|
+
return true;
|
|
46
|
+
}));
|
|
47
|
+
this.transforms.push(new FilterObjectFields((objectTypeName, objectFieldName) => {
|
|
48
|
+
if (typeMatcher.match(objectTypeName)) {
|
|
49
|
+
return globalTypeMatcher.match(objectFieldName);
|
|
50
|
+
}
|
|
51
|
+
return true;
|
|
52
|
+
}));
|
|
53
|
+
this.transforms.push(new FilterInputObjectFields((inputObjectTypeName, inputObjectFieldName) => {
|
|
54
|
+
if (typeMatcher.match(inputObjectTypeName)) {
|
|
55
|
+
return globalTypeMatcher.match(inputObjectFieldName);
|
|
56
|
+
}
|
|
57
|
+
return true;
|
|
58
|
+
}));
|
|
59
|
+
this.transforms.push(new FilterInterfaceFields((interfaceTypeName, interfaceFieldName) => {
|
|
60
|
+
if (typeMatcher.match(interfaceTypeName)) {
|
|
61
|
+
return globalTypeMatcher.match(interfaceFieldName);
|
|
62
|
+
}
|
|
63
|
+
return true;
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
transformSchema(originalWrappingSchema, subschemaConfig, transformedSchema) {
|
|
68
|
+
return applySchemaTransforms(originalWrappingSchema, subschemaConfig, transformedSchema, this.transforms);
|
|
69
|
+
}
|
|
70
|
+
transformRequest(originalRequest, delegationContext, transformationContext) {
|
|
71
|
+
return applyRequestTransforms(originalRequest, delegationContext, transformationContext, this.transforms);
|
|
72
|
+
}
|
|
73
|
+
transformResult(originalResult, delegationContext, transformationContext) {
|
|
74
|
+
return applyResultTransforms(originalResult, delegationContext, transformationContext, this.transforms);
|
|
75
|
+
}
|
|
76
|
+
}
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-mesh/transform-filter-schema",
|
|
3
|
-
"version": "1.0.0-alpha-
|
|
3
|
+
"version": "1.0.0-alpha-20230420181317-a95037648",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@graphql-mesh/types": "0.
|
|
7
|
-
"@graphql-mesh/utils": "1.0.0-alpha-
|
|
8
|
-
"graphql": "
|
|
6
|
+
"@graphql-mesh/types": "1.0.0-alpha-20230420181317-a95037648",
|
|
7
|
+
"@graphql-mesh/utils": "1.0.0-alpha-20230420181317-a95037648",
|
|
8
|
+
"@graphql-tools/utils": "^9.2.1",
|
|
9
|
+
"graphql": "*",
|
|
10
|
+
"tslib": "^2.4.0"
|
|
9
11
|
},
|
|
10
12
|
"dependencies": {
|
|
11
|
-
"@graphql-tools/delegate": "
|
|
12
|
-
"@graphql-tools/
|
|
13
|
-
"
|
|
14
|
-
"minimatch": "5.1.0",
|
|
15
|
-
"tslib": "^2.4.0"
|
|
13
|
+
"@graphql-tools/delegate": "9.0.32",
|
|
14
|
+
"@graphql-tools/wrap": "9.4.2",
|
|
15
|
+
"minimatch": "8.0.4"
|
|
16
16
|
},
|
|
17
17
|
"repository": {
|
|
18
18
|
"type": "git",
|
|
@@ -20,21 +20,28 @@
|
|
|
20
20
|
"directory": "packages/transforms/filter-schema"
|
|
21
21
|
},
|
|
22
22
|
"license": "MIT",
|
|
23
|
-
"main": "index.js",
|
|
24
|
-
"module": "index.
|
|
25
|
-
"typings": "index.d.ts",
|
|
23
|
+
"main": "cjs/index.js",
|
|
24
|
+
"module": "esm/index.js",
|
|
25
|
+
"typings": "typings/index.d.ts",
|
|
26
26
|
"typescript": {
|
|
27
|
-
"definition": "index.d.ts"
|
|
27
|
+
"definition": "typings/index.d.ts"
|
|
28
28
|
},
|
|
29
|
+
"type": "module",
|
|
29
30
|
"exports": {
|
|
30
31
|
".": {
|
|
31
|
-
"require":
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
|
|
32
|
+
"require": {
|
|
33
|
+
"types": "./typings/index.d.cts",
|
|
34
|
+
"default": "./cjs/index.js"
|
|
35
|
+
},
|
|
36
|
+
"import": {
|
|
37
|
+
"types": "./typings/index.d.ts",
|
|
38
|
+
"default": "./esm/index.js"
|
|
39
|
+
},
|
|
40
|
+
"default": {
|
|
41
|
+
"types": "./typings/index.d.ts",
|
|
42
|
+
"default": "./esm/index.js"
|
|
43
|
+
}
|
|
37
44
|
},
|
|
38
45
|
"./package.json": "./package.json"
|
|
39
46
|
}
|
|
40
|
-
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { GraphQLSchema } from 'graphql';
|
|
2
|
+
import { MeshTransform, YamlConfig } from '@graphql-mesh/types';
|
|
3
|
+
export default class BareFilter implements MeshTransform {
|
|
4
|
+
noWrap: boolean;
|
|
5
|
+
typeGlobs: string[];
|
|
6
|
+
fieldsMap: Map<string, string[]>;
|
|
7
|
+
argsMap: Map<string, string[]>;
|
|
8
|
+
constructor({ config: { filters } }: {
|
|
9
|
+
config: YamlConfig.FilterSchemaTransform;
|
|
10
|
+
});
|
|
11
|
+
matchInArray(rulesArray: string[], value: string): null | undefined;
|
|
12
|
+
transformSchema(schema: GraphQLSchema): GraphQLSchema;
|
|
13
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { YamlConfig } from '@graphql-mesh/types';
|
|
2
|
+
import BareFilter from './bareFilter.cjs';
|
|
3
|
+
import WrapFilter from './wrapFilter.cjs';
|
|
4
|
+
interface FilterTransformConstructor {
|
|
5
|
+
new (options: {
|
|
6
|
+
config: YamlConfig.FilterSchemaTransform;
|
|
7
|
+
}): BareFilter | WrapFilter;
|
|
8
|
+
}
|
|
9
|
+
declare const _default: FilterTransformConstructor;
|
|
10
|
+
export default _default;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { YamlConfig } from '@graphql-mesh/types';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import BareFilter from './bareFilter.js';
|
|
3
|
+
import WrapFilter from './wrapFilter.js';
|
|
4
4
|
interface FilterTransformConstructor {
|
|
5
5
|
new (options: {
|
|
6
6
|
config: YamlConfig.FilterSchemaTransform;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { GraphQLSchema } from 'graphql';
|
|
2
|
+
import { YamlConfig } from '@graphql-mesh/types';
|
|
3
|
+
import { DelegationContext, SubschemaConfig, Transform } from '@graphql-tools/delegate';
|
|
4
|
+
import { ExecutionRequest, ExecutionResult } from '@graphql-tools/utils';
|
|
5
|
+
export default class WrapFilter implements Transform {
|
|
6
|
+
private transforms;
|
|
7
|
+
constructor({ config: { filters } }: {
|
|
8
|
+
config: YamlConfig.FilterSchemaTransform;
|
|
9
|
+
});
|
|
10
|
+
transformSchema(originalWrappingSchema: GraphQLSchema, subschemaConfig: SubschemaConfig, transformedSchema?: GraphQLSchema): GraphQLSchema;
|
|
11
|
+
transformRequest(originalRequest: ExecutionRequest, delegationContext: DelegationContext, transformationContext: Record<string, any>): ExecutionRequest<any, any, any, Record<string, any>, any>;
|
|
12
|
+
transformResult(originalResult: ExecutionResult, delegationContext: DelegationContext, transformationContext: any): ExecutionResult<any, any>;
|
|
13
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
import { GraphQLSchema } from 'graphql';
|
|
1
2
|
import { YamlConfig } from '@graphql-mesh/types';
|
|
2
3
|
import { DelegationContext, SubschemaConfig, Transform } from '@graphql-tools/delegate';
|
|
3
|
-
import {
|
|
4
|
-
import { GraphQLSchema } from 'graphql';
|
|
4
|
+
import { ExecutionRequest, ExecutionResult } from '@graphql-tools/utils';
|
|
5
5
|
export default class WrapFilter implements Transform {
|
|
6
6
|
private transforms;
|
|
7
7
|
constructor({ config: { filters } }: {
|
|
8
8
|
config: YamlConfig.FilterSchemaTransform;
|
|
9
9
|
});
|
|
10
10
|
transformSchema(originalWrappingSchema: GraphQLSchema, subschemaConfig: SubschemaConfig, transformedSchema?: GraphQLSchema): GraphQLSchema;
|
|
11
|
-
transformRequest(originalRequest: ExecutionRequest, delegationContext: DelegationContext, transformationContext: Record<string, any>): ExecutionRequest<
|
|
12
|
-
transformResult(originalResult: ExecutionResult, delegationContext: DelegationContext, transformationContext: any): ExecutionResult<
|
|
11
|
+
transformRequest(originalRequest: ExecutionRequest, delegationContext: DelegationContext, transformationContext: Record<string, any>): ExecutionRequest<any, any, any, Record<string, any>, any>;
|
|
12
|
+
transformResult(originalResult: ExecutionResult, delegationContext: DelegationContext, transformationContext: any): ExecutionResult<any, any>;
|
|
13
13
|
}
|
package/index.js
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
4
|
-
|
|
5
|
-
const utils = require('@graphql-mesh/utils');
|
|
6
|
-
const wrap = require('@graphql-tools/wrap');
|
|
7
|
-
const minimatch = _interopDefault(require('minimatch'));
|
|
8
|
-
const utils$1 = require('@graphql-tools/utils');
|
|
9
|
-
|
|
10
|
-
class WrapFilter {
|
|
11
|
-
constructor({ config: { filters } }) {
|
|
12
|
-
this.transforms = [];
|
|
13
|
-
for (const filter of filters) {
|
|
14
|
-
const [typeName, fieldNameOrGlob, argsGlob] = filter.split('.');
|
|
15
|
-
const typeMatcher = new minimatch.Minimatch(typeName);
|
|
16
|
-
// TODO: deprecate this in next major release as dscussed in #1605
|
|
17
|
-
if (!fieldNameOrGlob) {
|
|
18
|
-
this.transforms.push(new wrap.FilterTypes(type => {
|
|
19
|
-
return typeMatcher.match(type.name);
|
|
20
|
-
}));
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
let fixedFieldGlob = argsGlob || fieldNameOrGlob;
|
|
24
|
-
if (fixedFieldGlob.includes('{') && !fixedFieldGlob.includes(',')) {
|
|
25
|
-
fixedFieldGlob = fieldNameOrGlob.replace('{', '').replace('}', '');
|
|
26
|
-
}
|
|
27
|
-
fixedFieldGlob = fixedFieldGlob.split(', ').join(',');
|
|
28
|
-
const globalTypeMatcher = new minimatch.Minimatch(fixedFieldGlob.trim());
|
|
29
|
-
if (typeName === 'Type') {
|
|
30
|
-
this.transforms.push(new wrap.FilterTypes(type => {
|
|
31
|
-
return globalTypeMatcher.match(type.name);
|
|
32
|
-
}));
|
|
33
|
-
continue;
|
|
34
|
-
}
|
|
35
|
-
if (argsGlob) {
|
|
36
|
-
const fieldMatcher = new minimatch.Minimatch(fieldNameOrGlob);
|
|
37
|
-
this.transforms.push(new wrap.TransformCompositeFields((fieldTypeName, fieldName, fieldConfig) => {
|
|
38
|
-
if (typeMatcher.match(fieldTypeName) && fieldMatcher.match(fieldName)) {
|
|
39
|
-
const fieldArgs = Object.entries(fieldConfig.args).reduce((args, [argName, argConfig]) => !globalTypeMatcher.match(argName) ? args : { ...args, [argName]: argConfig }, {});
|
|
40
|
-
return { ...fieldConfig, args: fieldArgs };
|
|
41
|
-
}
|
|
42
|
-
return undefined;
|
|
43
|
-
}));
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
// If the glob is not for Types nor Args, finally we register Fields filters
|
|
47
|
-
this.transforms.push(new wrap.FilterRootFields((rootTypeName, rootFieldName) => {
|
|
48
|
-
if (typeMatcher.match(rootTypeName)) {
|
|
49
|
-
return globalTypeMatcher.match(rootFieldName);
|
|
50
|
-
}
|
|
51
|
-
return true;
|
|
52
|
-
}));
|
|
53
|
-
this.transforms.push(new wrap.FilterObjectFields((objectTypeName, objectFieldName) => {
|
|
54
|
-
if (typeMatcher.match(objectTypeName)) {
|
|
55
|
-
return globalTypeMatcher.match(objectFieldName);
|
|
56
|
-
}
|
|
57
|
-
return true;
|
|
58
|
-
}));
|
|
59
|
-
this.transforms.push(new wrap.FilterInputObjectFields((inputObjectTypeName, inputObjectFieldName) => {
|
|
60
|
-
if (typeMatcher.match(inputObjectTypeName)) {
|
|
61
|
-
return globalTypeMatcher.match(inputObjectFieldName);
|
|
62
|
-
}
|
|
63
|
-
return true;
|
|
64
|
-
}));
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
transformSchema(originalWrappingSchema, subschemaConfig, transformedSchema) {
|
|
68
|
-
return utils.applySchemaTransforms(originalWrappingSchema, subschemaConfig, transformedSchema, this.transforms);
|
|
69
|
-
}
|
|
70
|
-
transformRequest(originalRequest, delegationContext, transformationContext) {
|
|
71
|
-
return utils.applyRequestTransforms(originalRequest, delegationContext, transformationContext, this.transforms);
|
|
72
|
-
}
|
|
73
|
-
transformResult(originalResult, delegationContext, transformationContext) {
|
|
74
|
-
return utils.applyResultTransforms(originalResult, delegationContext, transformationContext, this.transforms);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
class BareFilter {
|
|
79
|
-
constructor({ config: { filters } }) {
|
|
80
|
-
this.noWrap = true;
|
|
81
|
-
this.typeGlobs = [];
|
|
82
|
-
this.fieldsMap = new Map();
|
|
83
|
-
this.argsMap = new Map();
|
|
84
|
-
for (const filter of filters) {
|
|
85
|
-
const [typeName, fieldNameOrGlob, argsGlob] = filter.split('.');
|
|
86
|
-
// TODO: deprecate this in next major release as dscussed in #1605
|
|
87
|
-
if (!fieldNameOrGlob) {
|
|
88
|
-
this.typeGlobs.push(typeName);
|
|
89
|
-
continue;
|
|
90
|
-
}
|
|
91
|
-
const rawGlob = argsGlob || fieldNameOrGlob;
|
|
92
|
-
const fixedGlob = rawGlob.includes('{') && !rawGlob.includes(',') ? rawGlob.replace('{', '').replace('}', '') : rawGlob;
|
|
93
|
-
const polishedGlob = fixedGlob.split(', ').join(',').trim();
|
|
94
|
-
if (typeName === 'Type') {
|
|
95
|
-
this.typeGlobs.push(polishedGlob);
|
|
96
|
-
continue;
|
|
97
|
-
}
|
|
98
|
-
const mapName = argsGlob ? 'argsMap' : 'fieldsMap';
|
|
99
|
-
const mapKey = argsGlob ? `${typeName}.${fieldNameOrGlob}` : typeName;
|
|
100
|
-
const currentRules = this[mapName].get(mapKey) || [];
|
|
101
|
-
this[mapName].set(mapKey, [...currentRules, polishedGlob]);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
matchInArray(rulesArray, value) {
|
|
105
|
-
for (const rule of rulesArray) {
|
|
106
|
-
const ruleMatcher = new minimatch.Minimatch(rule);
|
|
107
|
-
if (!ruleMatcher.match(value))
|
|
108
|
-
return null;
|
|
109
|
-
}
|
|
110
|
-
return undefined;
|
|
111
|
-
}
|
|
112
|
-
transformSchema(schema) {
|
|
113
|
-
const transformedSchema = utils$1.mapSchema(schema, {
|
|
114
|
-
...(this.typeGlobs.length && {
|
|
115
|
-
[utils$1.MapperKind.TYPE]: type => this.matchInArray(this.typeGlobs, type.toString()),
|
|
116
|
-
}),
|
|
117
|
-
...((this.fieldsMap.size || this.argsMap.size) && {
|
|
118
|
-
[utils$1.MapperKind.COMPOSITE_FIELD]: (fieldConfig, fieldName, typeName) => {
|
|
119
|
-
const fieldRules = this.fieldsMap.get(typeName);
|
|
120
|
-
const wildcardArgRules = this.argsMap.get(`${typeName}.*`) || [];
|
|
121
|
-
const fieldArgRules = this.argsMap.get(`${typeName}.${fieldName}`) || [];
|
|
122
|
-
const argRules = wildcardArgRules.concat(fieldArgRules);
|
|
123
|
-
const hasFieldRules = Boolean(fieldRules && fieldRules.length);
|
|
124
|
-
const hasArgRules = Boolean(argRules && argRules.length);
|
|
125
|
-
if (hasFieldRules && this.matchInArray(fieldRules, fieldName) === null)
|
|
126
|
-
return null;
|
|
127
|
-
if (!hasArgRules)
|
|
128
|
-
return undefined;
|
|
129
|
-
const fieldArgs = Object.entries(fieldConfig.args).reduce((args, [argName, argConfig]) => this.matchInArray(argRules, argName) === null ? args : { ...args, [argName]: argConfig }, {});
|
|
130
|
-
return { ...fieldConfig, args: fieldArgs };
|
|
131
|
-
},
|
|
132
|
-
}),
|
|
133
|
-
...(this.fieldsMap.size && {
|
|
134
|
-
[utils$1.MapperKind.INPUT_OBJECT_FIELD]: (_, fieldName, typeName) => {
|
|
135
|
-
const fieldRules = this.fieldsMap.get(typeName);
|
|
136
|
-
const hasFieldRules = Boolean(fieldRules && fieldRules.length);
|
|
137
|
-
if (hasFieldRules && this.matchInArray(fieldRules, fieldName) === null)
|
|
138
|
-
return null;
|
|
139
|
-
return undefined;
|
|
140
|
-
},
|
|
141
|
-
}),
|
|
142
|
-
});
|
|
143
|
-
return transformedSchema;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
const FilterTransform = (function FilterTransform(options) {
|
|
148
|
-
if (Array.isArray(options.config)) {
|
|
149
|
-
return new WrapFilter({
|
|
150
|
-
...options,
|
|
151
|
-
config: {
|
|
152
|
-
mode: 'wrap',
|
|
153
|
-
filters: options.config,
|
|
154
|
-
},
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
return options.config.mode === 'bare' ? new BareFilter(options) : new WrapFilter(options);
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
module.exports = FilterTransform;
|
package/index.mjs
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { applySchemaTransforms, applyRequestTransforms, applyResultTransforms } from '@graphql-mesh/utils';
|
|
2
|
-
import { FilterTypes, TransformCompositeFields, FilterRootFields, FilterObjectFields, FilterInputObjectFields } from '@graphql-tools/wrap';
|
|
3
|
-
import minimatch from 'minimatch';
|
|
4
|
-
import { mapSchema, MapperKind } from '@graphql-tools/utils';
|
|
5
|
-
|
|
6
|
-
class WrapFilter {
|
|
7
|
-
constructor({ config: { filters } }) {
|
|
8
|
-
this.transforms = [];
|
|
9
|
-
for (const filter of filters) {
|
|
10
|
-
const [typeName, fieldNameOrGlob, argsGlob] = filter.split('.');
|
|
11
|
-
const typeMatcher = new minimatch.Minimatch(typeName);
|
|
12
|
-
// TODO: deprecate this in next major release as dscussed in #1605
|
|
13
|
-
if (!fieldNameOrGlob) {
|
|
14
|
-
this.transforms.push(new FilterTypes(type => {
|
|
15
|
-
return typeMatcher.match(type.name);
|
|
16
|
-
}));
|
|
17
|
-
continue;
|
|
18
|
-
}
|
|
19
|
-
let fixedFieldGlob = argsGlob || fieldNameOrGlob;
|
|
20
|
-
if (fixedFieldGlob.includes('{') && !fixedFieldGlob.includes(',')) {
|
|
21
|
-
fixedFieldGlob = fieldNameOrGlob.replace('{', '').replace('}', '');
|
|
22
|
-
}
|
|
23
|
-
fixedFieldGlob = fixedFieldGlob.split(', ').join(',');
|
|
24
|
-
const globalTypeMatcher = new minimatch.Minimatch(fixedFieldGlob.trim());
|
|
25
|
-
if (typeName === 'Type') {
|
|
26
|
-
this.transforms.push(new FilterTypes(type => {
|
|
27
|
-
return globalTypeMatcher.match(type.name);
|
|
28
|
-
}));
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
if (argsGlob) {
|
|
32
|
-
const fieldMatcher = new minimatch.Minimatch(fieldNameOrGlob);
|
|
33
|
-
this.transforms.push(new TransformCompositeFields((fieldTypeName, fieldName, fieldConfig) => {
|
|
34
|
-
if (typeMatcher.match(fieldTypeName) && fieldMatcher.match(fieldName)) {
|
|
35
|
-
const fieldArgs = Object.entries(fieldConfig.args).reduce((args, [argName, argConfig]) => !globalTypeMatcher.match(argName) ? args : { ...args, [argName]: argConfig }, {});
|
|
36
|
-
return { ...fieldConfig, args: fieldArgs };
|
|
37
|
-
}
|
|
38
|
-
return undefined;
|
|
39
|
-
}));
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
// If the glob is not for Types nor Args, finally we register Fields filters
|
|
43
|
-
this.transforms.push(new FilterRootFields((rootTypeName, rootFieldName) => {
|
|
44
|
-
if (typeMatcher.match(rootTypeName)) {
|
|
45
|
-
return globalTypeMatcher.match(rootFieldName);
|
|
46
|
-
}
|
|
47
|
-
return true;
|
|
48
|
-
}));
|
|
49
|
-
this.transforms.push(new FilterObjectFields((objectTypeName, objectFieldName) => {
|
|
50
|
-
if (typeMatcher.match(objectTypeName)) {
|
|
51
|
-
return globalTypeMatcher.match(objectFieldName);
|
|
52
|
-
}
|
|
53
|
-
return true;
|
|
54
|
-
}));
|
|
55
|
-
this.transforms.push(new FilterInputObjectFields((inputObjectTypeName, inputObjectFieldName) => {
|
|
56
|
-
if (typeMatcher.match(inputObjectTypeName)) {
|
|
57
|
-
return globalTypeMatcher.match(inputObjectFieldName);
|
|
58
|
-
}
|
|
59
|
-
return true;
|
|
60
|
-
}));
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
transformSchema(originalWrappingSchema, subschemaConfig, transformedSchema) {
|
|
64
|
-
return applySchemaTransforms(originalWrappingSchema, subschemaConfig, transformedSchema, this.transforms);
|
|
65
|
-
}
|
|
66
|
-
transformRequest(originalRequest, delegationContext, transformationContext) {
|
|
67
|
-
return applyRequestTransforms(originalRequest, delegationContext, transformationContext, this.transforms);
|
|
68
|
-
}
|
|
69
|
-
transformResult(originalResult, delegationContext, transformationContext) {
|
|
70
|
-
return applyResultTransforms(originalResult, delegationContext, transformationContext, this.transforms);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
class BareFilter {
|
|
75
|
-
constructor({ config: { filters } }) {
|
|
76
|
-
this.noWrap = true;
|
|
77
|
-
this.typeGlobs = [];
|
|
78
|
-
this.fieldsMap = new Map();
|
|
79
|
-
this.argsMap = new Map();
|
|
80
|
-
for (const filter of filters) {
|
|
81
|
-
const [typeName, fieldNameOrGlob, argsGlob] = filter.split('.');
|
|
82
|
-
// TODO: deprecate this in next major release as dscussed in #1605
|
|
83
|
-
if (!fieldNameOrGlob) {
|
|
84
|
-
this.typeGlobs.push(typeName);
|
|
85
|
-
continue;
|
|
86
|
-
}
|
|
87
|
-
const rawGlob = argsGlob || fieldNameOrGlob;
|
|
88
|
-
const fixedGlob = rawGlob.includes('{') && !rawGlob.includes(',') ? rawGlob.replace('{', '').replace('}', '') : rawGlob;
|
|
89
|
-
const polishedGlob = fixedGlob.split(', ').join(',').trim();
|
|
90
|
-
if (typeName === 'Type') {
|
|
91
|
-
this.typeGlobs.push(polishedGlob);
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
const mapName = argsGlob ? 'argsMap' : 'fieldsMap';
|
|
95
|
-
const mapKey = argsGlob ? `${typeName}.${fieldNameOrGlob}` : typeName;
|
|
96
|
-
const currentRules = this[mapName].get(mapKey) || [];
|
|
97
|
-
this[mapName].set(mapKey, [...currentRules, polishedGlob]);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
matchInArray(rulesArray, value) {
|
|
101
|
-
for (const rule of rulesArray) {
|
|
102
|
-
const ruleMatcher = new minimatch.Minimatch(rule);
|
|
103
|
-
if (!ruleMatcher.match(value))
|
|
104
|
-
return null;
|
|
105
|
-
}
|
|
106
|
-
return undefined;
|
|
107
|
-
}
|
|
108
|
-
transformSchema(schema) {
|
|
109
|
-
const transformedSchema = mapSchema(schema, {
|
|
110
|
-
...(this.typeGlobs.length && {
|
|
111
|
-
[MapperKind.TYPE]: type => this.matchInArray(this.typeGlobs, type.toString()),
|
|
112
|
-
}),
|
|
113
|
-
...((this.fieldsMap.size || this.argsMap.size) && {
|
|
114
|
-
[MapperKind.COMPOSITE_FIELD]: (fieldConfig, fieldName, typeName) => {
|
|
115
|
-
const fieldRules = this.fieldsMap.get(typeName);
|
|
116
|
-
const wildcardArgRules = this.argsMap.get(`${typeName}.*`) || [];
|
|
117
|
-
const fieldArgRules = this.argsMap.get(`${typeName}.${fieldName}`) || [];
|
|
118
|
-
const argRules = wildcardArgRules.concat(fieldArgRules);
|
|
119
|
-
const hasFieldRules = Boolean(fieldRules && fieldRules.length);
|
|
120
|
-
const hasArgRules = Boolean(argRules && argRules.length);
|
|
121
|
-
if (hasFieldRules && this.matchInArray(fieldRules, fieldName) === null)
|
|
122
|
-
return null;
|
|
123
|
-
if (!hasArgRules)
|
|
124
|
-
return undefined;
|
|
125
|
-
const fieldArgs = Object.entries(fieldConfig.args).reduce((args, [argName, argConfig]) => this.matchInArray(argRules, argName) === null ? args : { ...args, [argName]: argConfig }, {});
|
|
126
|
-
return { ...fieldConfig, args: fieldArgs };
|
|
127
|
-
},
|
|
128
|
-
}),
|
|
129
|
-
...(this.fieldsMap.size && {
|
|
130
|
-
[MapperKind.INPUT_OBJECT_FIELD]: (_, fieldName, typeName) => {
|
|
131
|
-
const fieldRules = this.fieldsMap.get(typeName);
|
|
132
|
-
const hasFieldRules = Boolean(fieldRules && fieldRules.length);
|
|
133
|
-
if (hasFieldRules && this.matchInArray(fieldRules, fieldName) === null)
|
|
134
|
-
return null;
|
|
135
|
-
return undefined;
|
|
136
|
-
},
|
|
137
|
-
}),
|
|
138
|
-
});
|
|
139
|
-
return transformedSchema;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const FilterTransform = (function FilterTransform(options) {
|
|
144
|
-
if (Array.isArray(options.config)) {
|
|
145
|
-
return new WrapFilter({
|
|
146
|
-
...options,
|
|
147
|
-
config: {
|
|
148
|
-
mode: 'wrap',
|
|
149
|
-
filters: options.config,
|
|
150
|
-
},
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
return options.config.mode === 'bare' ? new BareFilter(options) : new WrapFilter(options);
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
export default FilterTransform;
|
|
File without changes
|