@graphql-tools/wrap 8.4.1 → 8.4.3-alpha-dae587b2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +68 -0
- package/index.mjs +68 -1
- package/package.json +4 -4
- package/transforms/RenameObjectFieldArguments.d.ts +15 -0
- 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);
|
|
@@ -1729,6 +1796,7 @@ exports.RemoveObjectFieldsWithDeprecation = RemoveObjectFieldsWithDeprecation;
|
|
|
1729
1796
|
exports.RemoveObjectFieldsWithDirective = RemoveObjectFieldsWithDirective;
|
|
1730
1797
|
exports.RenameInputObjectFields = RenameInputObjectFields;
|
|
1731
1798
|
exports.RenameInterfaceFields = RenameInterfaceFields;
|
|
1799
|
+
exports.RenameObjectFieldArguments = RenameObjectFieldArguments;
|
|
1732
1800
|
exports.RenameObjectFields = RenameObjectFields;
|
|
1733
1801
|
exports.RenameRootFields = RenameRootFields;
|
|
1734
1802
|
exports.RenameRootTypes = RenameRootTypes;
|
package/index.mjs
CHANGED
|
@@ -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);
|
|
@@ -1708,4 +1775,4 @@ function introspectSchema(executor, context, options) {
|
|
|
1708
1775
|
.resolve();
|
|
1709
1776
|
}
|
|
1710
1777
|
|
|
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 };
|
|
1778
|
+
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.3-alpha-dae587b2.0",
|
|
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.
|
|
11
|
-
"@graphql-tools/schema": "^8.3.
|
|
12
|
-
"@graphql-tools/utils": "^8.
|
|
10
|
+
"@graphql-tools/delegate": "^8.5.1",
|
|
11
|
+
"@graphql-tools/schema": "^8.3.2",
|
|
12
|
+
"@graphql-tools/utils": "^8.6.2",
|
|
13
13
|
"tslib": "~2.3.0",
|
|
14
14
|
"value-or-promise": "1.0.11"
|
|
15
15
|
},
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { GraphQLSchema } from 'graphql';
|
|
2
|
+
import { ExecutionRequest } from '@graphql-tools/utils';
|
|
3
|
+
import { Transform, DelegationContext, SubschemaConfig } from '@graphql-tools/delegate';
|
|
4
|
+
declare type RenamerFunction = (typeName: string, fieldName: string, argName: string) => string;
|
|
5
|
+
interface RenameObjectFieldArgumentsTransformationContext extends Record<string, any> {
|
|
6
|
+
}
|
|
7
|
+
export default class RenameObjectFieldArguments<TContext = Record<string, any>> implements Transform<RenameObjectFieldArgumentsTransformationContext, TContext> {
|
|
8
|
+
private readonly renamer;
|
|
9
|
+
private readonly transformer;
|
|
10
|
+
private reverseMap;
|
|
11
|
+
constructor(renamer: RenamerFunction);
|
|
12
|
+
transformSchema(originalWrappingSchema: GraphQLSchema, subschemaConfig: SubschemaConfig<any, any, any, TContext>, transformedSchema?: GraphQLSchema): GraphQLSchema;
|
|
13
|
+
transformRequest(originalRequest: ExecutionRequest, delegationContext: DelegationContext<TContext>, transformationContext: RenameObjectFieldArgumentsTransformationContext): ExecutionRequest;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
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';
|