@graphql-tools/wrap 8.4.3-alpha-7150a353.0 → 8.4.5
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/index.js +70 -12
- package/index.mjs +71 -14
- package/package.json +3 -3
- package/transforms/index.d.ts +1 -0
package/index.js
CHANGED
|
@@ -507,6 +507,73 @@ class RenameObjectFields {
|
|
|
507
507
|
}
|
|
508
508
|
}
|
|
509
509
|
|
|
510
|
+
class RenameObjectFieldArguments {
|
|
511
|
+
constructor(renamer) {
|
|
512
|
+
this.renamer = renamer;
|
|
513
|
+
this.transformer = new TransformObjectFields((typeName, fieldName, fieldConfig) => {
|
|
514
|
+
const argsConfig = Object.fromEntries(Object.entries(fieldConfig.args || []).map(([argName, conf]) => {
|
|
515
|
+
const newName = renamer(typeName, fieldName, argName);
|
|
516
|
+
if (newName !== undefined && newName !== argName) {
|
|
517
|
+
if (newName != null) {
|
|
518
|
+
return [newName, conf];
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
return [argName, conf];
|
|
522
|
+
}));
|
|
523
|
+
return [fieldName, { ...fieldConfig, args: argsConfig }];
|
|
524
|
+
}, (typeName, fieldName, inputFieldNode) => {
|
|
525
|
+
if (!(typeName in this.reverseMap)) {
|
|
526
|
+
return inputFieldNode;
|
|
527
|
+
}
|
|
528
|
+
if (!(fieldName in this.reverseMap[typeName])) {
|
|
529
|
+
return inputFieldNode;
|
|
530
|
+
}
|
|
531
|
+
const fieldNameMap = this.reverseMap[typeName][fieldName];
|
|
532
|
+
return {
|
|
533
|
+
...inputFieldNode,
|
|
534
|
+
arguments: (inputFieldNode.arguments || []).map(argNode => {
|
|
535
|
+
return argNode.name.value in fieldNameMap
|
|
536
|
+
? {
|
|
537
|
+
...argNode,
|
|
538
|
+
name: {
|
|
539
|
+
...argNode.name,
|
|
540
|
+
value: fieldNameMap[argNode.name.value],
|
|
541
|
+
},
|
|
542
|
+
}
|
|
543
|
+
: argNode;
|
|
544
|
+
}),
|
|
545
|
+
};
|
|
546
|
+
});
|
|
547
|
+
this.reverseMap = Object.create(null);
|
|
548
|
+
}
|
|
549
|
+
transformSchema(originalWrappingSchema, subschemaConfig, transformedSchema) {
|
|
550
|
+
utils.mapSchema(originalWrappingSchema, {
|
|
551
|
+
[utils.MapperKind.OBJECT_FIELD]: (fieldConfig, fieldName, typeName) => {
|
|
552
|
+
Object.entries(fieldConfig.args || {}).forEach(([argName]) => {
|
|
553
|
+
const newName = this.renamer(typeName, fieldName, argName);
|
|
554
|
+
if (newName !== undefined && newName !== fieldName) {
|
|
555
|
+
if (this.reverseMap[typeName] == null) {
|
|
556
|
+
this.reverseMap[typeName] = Object.create(null);
|
|
557
|
+
}
|
|
558
|
+
if (this.reverseMap[typeName][fieldName] == null) {
|
|
559
|
+
this.reverseMap[typeName][fieldName] = Object.create(null);
|
|
560
|
+
}
|
|
561
|
+
this.reverseMap[typeName][fieldName][newName] = argName;
|
|
562
|
+
}
|
|
563
|
+
});
|
|
564
|
+
return undefined;
|
|
565
|
+
},
|
|
566
|
+
[utils.MapperKind.ROOT_OBJECT]() {
|
|
567
|
+
return undefined;
|
|
568
|
+
},
|
|
569
|
+
});
|
|
570
|
+
return this.transformer.transformSchema(originalWrappingSchema, subschemaConfig, transformedSchema);
|
|
571
|
+
}
|
|
572
|
+
transformRequest(originalRequest, delegationContext, transformationContext) {
|
|
573
|
+
return this.transformer.transformRequest(originalRequest, delegationContext, transformationContext);
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
|
|
510
577
|
class FilterObjectFields {
|
|
511
578
|
constructor(filter) {
|
|
512
579
|
this.transformer = new TransformObjectFields((typeName, fieldName, fieldConfig) => filter(typeName, fieldName, fieldConfig) ? undefined : null);
|
|
@@ -1678,21 +1745,11 @@ class ExtractField {
|
|
|
1678
1745
|
}
|
|
1679
1746
|
|
|
1680
1747
|
function getSchemaFromIntrospection(introspectionResult, options) {
|
|
1681
|
-
var _a
|
|
1748
|
+
var _a;
|
|
1682
1749
|
if ((_a = introspectionResult === null || introspectionResult === void 0 ? void 0 : introspectionResult.data) === null || _a === void 0 ? void 0 : _a.__schema) {
|
|
1683
1750
|
return graphql.buildClientSchema(introspectionResult.data, options);
|
|
1684
1751
|
}
|
|
1685
|
-
|
|
1686
|
-
if (introspectionResult.errors.length > 1) {
|
|
1687
|
-
const combinedError = new utils.AggregateError(introspectionResult.errors, 'Could not obtain introspection result');
|
|
1688
|
-
throw combinedError;
|
|
1689
|
-
}
|
|
1690
|
-
const error = introspectionResult.errors[0];
|
|
1691
|
-
throw error.originalError || error;
|
|
1692
|
-
}
|
|
1693
|
-
else {
|
|
1694
|
-
throw new Error('Could not obtain introspection result, received: ' + JSON.stringify(introspectionResult));
|
|
1695
|
-
}
|
|
1752
|
+
throw new Error('Could not obtain introspection result, received: ' + JSON.stringify(introspectionResult));
|
|
1696
1753
|
}
|
|
1697
1754
|
function introspectSchema(executor, context, options) {
|
|
1698
1755
|
const parsedIntrospectionQuery = graphql.parse(graphql.getIntrospectionQuery(options), options);
|
|
@@ -1729,6 +1786,7 @@ exports.RemoveObjectFieldsWithDeprecation = RemoveObjectFieldsWithDeprecation;
|
|
|
1729
1786
|
exports.RemoveObjectFieldsWithDirective = RemoveObjectFieldsWithDirective;
|
|
1730
1787
|
exports.RenameInputObjectFields = RenameInputObjectFields;
|
|
1731
1788
|
exports.RenameInterfaceFields = RenameInterfaceFields;
|
|
1789
|
+
exports.RenameObjectFieldArguments = RenameObjectFieldArguments;
|
|
1732
1790
|
exports.RenameObjectFields = RenameObjectFields;
|
|
1733
1791
|
exports.RenameRootFields = RenameRootFields;
|
|
1734
1792
|
exports.RenameRootTypes = RenameRootTypes;
|
package/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GraphQLObjectType, GraphQLInterfaceType, GraphQLUnionType, isSpecifiedScalarType, isScalarType, visit, Kind, TypeInfo, visitWithTypeInfo, isObjectType, isInterfaceType, typeFromAST, isInputType, isLeafType, valueFromAST, getNullableType, BREAK, parse, getIntrospectionQuery, buildClientSchema } from 'graphql';
|
|
2
|
-
import { getRootTypeMap, getResponseKeyFromInfo, mapSchema, MapperKind, renameType, visitData, transformInputValue, visitResult, createVariableNameGenerator, updateArgument, relocatedError, getArgumentValues, valueMatchesCriteria, getDirectives, pruneSchema, selectObjectFields, appendObjectFields, modifyObjectFields, removeObjectFields, isAsyncIterable
|
|
2
|
+
import { getRootTypeMap, getResponseKeyFromInfo, mapSchema, MapperKind, renameType, visitData, transformInputValue, visitResult, createVariableNameGenerator, updateArgument, relocatedError, getArgumentValues, valueMatchesCriteria, getDirectives, pruneSchema, selectObjectFields, appendObjectFields, modifyObjectFields, removeObjectFields, isAsyncIterable } from '@graphql-tools/utils';
|
|
3
3
|
import { applySchemaTransforms, delegateToSchema, isExternalObject, getUnpathedErrors, getSubschema, resolveExternalValue, defaultMergedResolver } from '@graphql-tools/delegate';
|
|
4
4
|
import { ValueOrPromise } from 'value-or-promise';
|
|
5
5
|
|
|
@@ -503,6 +503,73 @@ class RenameObjectFields {
|
|
|
503
503
|
}
|
|
504
504
|
}
|
|
505
505
|
|
|
506
|
+
class RenameObjectFieldArguments {
|
|
507
|
+
constructor(renamer) {
|
|
508
|
+
this.renamer = renamer;
|
|
509
|
+
this.transformer = new TransformObjectFields((typeName, fieldName, fieldConfig) => {
|
|
510
|
+
const argsConfig = Object.fromEntries(Object.entries(fieldConfig.args || []).map(([argName, conf]) => {
|
|
511
|
+
const newName = renamer(typeName, fieldName, argName);
|
|
512
|
+
if (newName !== undefined && newName !== argName) {
|
|
513
|
+
if (newName != null) {
|
|
514
|
+
return [newName, conf];
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
return [argName, conf];
|
|
518
|
+
}));
|
|
519
|
+
return [fieldName, { ...fieldConfig, args: argsConfig }];
|
|
520
|
+
}, (typeName, fieldName, inputFieldNode) => {
|
|
521
|
+
if (!(typeName in this.reverseMap)) {
|
|
522
|
+
return inputFieldNode;
|
|
523
|
+
}
|
|
524
|
+
if (!(fieldName in this.reverseMap[typeName])) {
|
|
525
|
+
return inputFieldNode;
|
|
526
|
+
}
|
|
527
|
+
const fieldNameMap = this.reverseMap[typeName][fieldName];
|
|
528
|
+
return {
|
|
529
|
+
...inputFieldNode,
|
|
530
|
+
arguments: (inputFieldNode.arguments || []).map(argNode => {
|
|
531
|
+
return argNode.name.value in fieldNameMap
|
|
532
|
+
? {
|
|
533
|
+
...argNode,
|
|
534
|
+
name: {
|
|
535
|
+
...argNode.name,
|
|
536
|
+
value: fieldNameMap[argNode.name.value],
|
|
537
|
+
},
|
|
538
|
+
}
|
|
539
|
+
: argNode;
|
|
540
|
+
}),
|
|
541
|
+
};
|
|
542
|
+
});
|
|
543
|
+
this.reverseMap = Object.create(null);
|
|
544
|
+
}
|
|
545
|
+
transformSchema(originalWrappingSchema, subschemaConfig, transformedSchema) {
|
|
546
|
+
mapSchema(originalWrappingSchema, {
|
|
547
|
+
[MapperKind.OBJECT_FIELD]: (fieldConfig, fieldName, typeName) => {
|
|
548
|
+
Object.entries(fieldConfig.args || {}).forEach(([argName]) => {
|
|
549
|
+
const newName = this.renamer(typeName, fieldName, argName);
|
|
550
|
+
if (newName !== undefined && newName !== fieldName) {
|
|
551
|
+
if (this.reverseMap[typeName] == null) {
|
|
552
|
+
this.reverseMap[typeName] = Object.create(null);
|
|
553
|
+
}
|
|
554
|
+
if (this.reverseMap[typeName][fieldName] == null) {
|
|
555
|
+
this.reverseMap[typeName][fieldName] = Object.create(null);
|
|
556
|
+
}
|
|
557
|
+
this.reverseMap[typeName][fieldName][newName] = argName;
|
|
558
|
+
}
|
|
559
|
+
});
|
|
560
|
+
return undefined;
|
|
561
|
+
},
|
|
562
|
+
[MapperKind.ROOT_OBJECT]() {
|
|
563
|
+
return undefined;
|
|
564
|
+
},
|
|
565
|
+
});
|
|
566
|
+
return this.transformer.transformSchema(originalWrappingSchema, subschemaConfig, transformedSchema);
|
|
567
|
+
}
|
|
568
|
+
transformRequest(originalRequest, delegationContext, transformationContext) {
|
|
569
|
+
return this.transformer.transformRequest(originalRequest, delegationContext, transformationContext);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
|
|
506
573
|
class FilterObjectFields {
|
|
507
574
|
constructor(filter) {
|
|
508
575
|
this.transformer = new TransformObjectFields((typeName, fieldName, fieldConfig) => filter(typeName, fieldName, fieldConfig) ? undefined : null);
|
|
@@ -1674,21 +1741,11 @@ class ExtractField {
|
|
|
1674
1741
|
}
|
|
1675
1742
|
|
|
1676
1743
|
function getSchemaFromIntrospection(introspectionResult, options) {
|
|
1677
|
-
var _a
|
|
1744
|
+
var _a;
|
|
1678
1745
|
if ((_a = introspectionResult === null || introspectionResult === void 0 ? void 0 : introspectionResult.data) === null || _a === void 0 ? void 0 : _a.__schema) {
|
|
1679
1746
|
return buildClientSchema(introspectionResult.data, options);
|
|
1680
1747
|
}
|
|
1681
|
-
|
|
1682
|
-
if (introspectionResult.errors.length > 1) {
|
|
1683
|
-
const combinedError = new AggregateError(introspectionResult.errors, 'Could not obtain introspection result');
|
|
1684
|
-
throw combinedError;
|
|
1685
|
-
}
|
|
1686
|
-
const error = introspectionResult.errors[0];
|
|
1687
|
-
throw error.originalError || error;
|
|
1688
|
-
}
|
|
1689
|
-
else {
|
|
1690
|
-
throw new Error('Could not obtain introspection result, received: ' + JSON.stringify(introspectionResult));
|
|
1691
|
-
}
|
|
1748
|
+
throw new Error('Could not obtain introspection result, received: ' + JSON.stringify(introspectionResult));
|
|
1692
1749
|
}
|
|
1693
1750
|
function introspectSchema(executor, context, options) {
|
|
1694
1751
|
const parsedIntrospectionQuery = parse(getIntrospectionQuery(options), options);
|
|
@@ -1708,4 +1765,4 @@ function introspectSchema(executor, context, options) {
|
|
|
1708
1765
|
.resolve();
|
|
1709
1766
|
}
|
|
1710
1767
|
|
|
1711
|
-
export { ExtractField, FilterInputObjectFields, FilterInterfaceFields, FilterObjectFieldDirectives, FilterObjectFields, FilterRootFields, FilterTypes, HoistField, MapFields, MapLeafValues, PruneTypes as PruneSchema, RemoveObjectFieldDeprecations, RemoveObjectFieldDirectives, RemoveObjectFieldsWithDeprecation, RemoveObjectFieldsWithDirective, RenameInputObjectFields, RenameInterfaceFields, RenameObjectFields, RenameRootFields, RenameRootTypes, RenameTypes, TransformCompositeFields, TransformEnumValues, TransformInputObjectFields, TransformInterfaceFields, TransformObjectFields, TransformQuery, TransformRootFields, WrapFields, WrapQuery, WrapType, defaultCreateProxyingResolver, generateProxyingResolvers, introspectSchema, wrapSchema };
|
|
1768
|
+
export { ExtractField, FilterInputObjectFields, FilterInterfaceFields, FilterObjectFieldDirectives, FilterObjectFields, FilterRootFields, FilterTypes, HoistField, MapFields, MapLeafValues, PruneTypes as PruneSchema, RemoveObjectFieldDeprecations, RemoveObjectFieldDirectives, RemoveObjectFieldsWithDeprecation, RemoveObjectFieldsWithDirective, RenameInputObjectFields, RenameInterfaceFields, RenameObjectFieldArguments, RenameObjectFields, RenameRootFields, RenameRootTypes, RenameTypes, TransformCompositeFields, TransformEnumValues, TransformInputObjectFields, TransformInterfaceFields, TransformObjectFields, TransformQuery, TransformRootFields, WrapFields, WrapQuery, WrapType, defaultCreateProxyingResolver, generateProxyingResolvers, introspectSchema, wrapSchema };
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-tools/wrap",
|
|
3
|
-
"version": "8.4.
|
|
3
|
+
"version": "8.4.5",
|
|
4
4
|
"description": "A set of utils for faster development of GraphQL tools",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"peerDependencies": {
|
|
7
7
|
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@graphql-tools/delegate": "^8.5.
|
|
10
|
+
"@graphql-tools/delegate": "^8.5.3",
|
|
11
11
|
"@graphql-tools/schema": "^8.3.2",
|
|
12
|
-
"@graphql-tools/utils": "^8.6.
|
|
12
|
+
"@graphql-tools/utils": "^8.6.3",
|
|
13
13
|
"tslib": "~2.3.0",
|
|
14
14
|
"value-or-promise": "1.0.11"
|
|
15
15
|
},
|
package/transforms/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export { default as RenameRootFields } from './RenameRootFields';
|
|
|
7
7
|
export { default as FilterRootFields } from './FilterRootFields';
|
|
8
8
|
export { default as TransformObjectFields } from './TransformObjectFields';
|
|
9
9
|
export { default as RenameObjectFields } from './RenameObjectFields';
|
|
10
|
+
export { default as RenameObjectFieldArguments } from './RenameObjectFieldArguments';
|
|
10
11
|
export { default as FilterObjectFields } from './FilterObjectFields';
|
|
11
12
|
export { default as TransformInterfaceFields } from './TransformInterfaceFields';
|
|
12
13
|
export { default as RenameInterfaceFields } from './RenameInterfaceFields';
|