@graphql-tools/wrap 9.2.15 → 9.2.16
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.
|
@@ -8,15 +8,9 @@ class MapLeafValues {
|
|
|
8
8
|
this.outputValueTransformer = outputValueTransformer;
|
|
9
9
|
this.resultVisitorMap = Object.create(null);
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
throw new Error(`The MapLeafValues transform's "transformRequest" and "transformResult" methods cannot be used without first calling "transformSchema".`);
|
|
15
|
-
}
|
|
16
|
-
return typeInfo;
|
|
17
|
-
}
|
|
18
|
-
transformSchema(schema, _subschemaConfig) {
|
|
19
|
-
const typeMap = schema.getTypeMap();
|
|
11
|
+
transformSchema(originalWrappingSchema, _subschemaConfig) {
|
|
12
|
+
this.originalWrappingSchema = originalWrappingSchema;
|
|
13
|
+
const typeMap = originalWrappingSchema.getTypeMap();
|
|
20
14
|
for (const typeName in typeMap) {
|
|
21
15
|
const type = typeMap[typeName];
|
|
22
16
|
if (!typeName.startsWith('__')) {
|
|
@@ -25,8 +19,8 @@ class MapLeafValues {
|
|
|
25
19
|
}
|
|
26
20
|
}
|
|
27
21
|
}
|
|
28
|
-
this.typeInfo = new graphql_1.TypeInfo(
|
|
29
|
-
return
|
|
22
|
+
this.typeInfo = new graphql_1.TypeInfo(originalWrappingSchema);
|
|
23
|
+
return originalWrappingSchema;
|
|
30
24
|
}
|
|
31
25
|
transformRequest(originalRequest, _delegationContext, transformationContext) {
|
|
32
26
|
var _a;
|
|
@@ -46,19 +40,27 @@ class MapLeafValues {
|
|
|
46
40
|
transformationContext.transformedRequest = transformedRequest;
|
|
47
41
|
return transformedRequest;
|
|
48
42
|
}
|
|
49
|
-
transformResult(originalResult,
|
|
50
|
-
|
|
51
|
-
|
|
43
|
+
transformResult(originalResult, _delegationContext, transformationContext) {
|
|
44
|
+
if (!this.originalWrappingSchema) {
|
|
45
|
+
throw new Error(`The MapLeafValues transform's "transformRequest" and "transformResult" methods cannot be used without first calling "transformSchema".`);
|
|
46
|
+
}
|
|
47
|
+
return (0, utils_1.visitResult)(originalResult, transformationContext.transformedRequest, this.originalWrappingSchema, this.resultVisitorMap);
|
|
52
48
|
}
|
|
53
49
|
transformOperations(operations, variableValues) {
|
|
50
|
+
if (this.typeInfo == null) {
|
|
51
|
+
throw new Error(`The MapLeafValues transform's "transformRequest" and "transformResult" methods cannot be used without first calling "transformSchema".`);
|
|
52
|
+
}
|
|
54
53
|
return operations.map((operation) => {
|
|
55
|
-
return (0, graphql_1.visit)(operation, (0, graphql_1.visitWithTypeInfo)(this.
|
|
54
|
+
return (0, graphql_1.visit)(operation, (0, graphql_1.visitWithTypeInfo)(this.typeInfo, {
|
|
56
55
|
[graphql_1.Kind.FIELD]: node => this.transformFieldNode(node, variableValues),
|
|
57
56
|
}));
|
|
58
57
|
});
|
|
59
58
|
}
|
|
60
59
|
transformFieldNode(field, variableValues) {
|
|
61
|
-
|
|
60
|
+
if (this.typeInfo == null) {
|
|
61
|
+
throw new Error(`The MapLeafValues transform's "transformRequest" and "transformResult" methods cannot be used without first calling "transformSchema".`);
|
|
62
|
+
}
|
|
63
|
+
const targetField = this.typeInfo.getFieldDef();
|
|
62
64
|
if (!targetField) {
|
|
63
65
|
return;
|
|
64
66
|
}
|
|
@@ -6,15 +6,9 @@ export default class MapLeafValues {
|
|
|
6
6
|
this.outputValueTransformer = outputValueTransformer;
|
|
7
7
|
this.resultVisitorMap = Object.create(null);
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
throw new Error(`The MapLeafValues transform's "transformRequest" and "transformResult" methods cannot be used without first calling "transformSchema".`);
|
|
13
|
-
}
|
|
14
|
-
return typeInfo;
|
|
15
|
-
}
|
|
16
|
-
transformSchema(schema, _subschemaConfig) {
|
|
17
|
-
const typeMap = schema.getTypeMap();
|
|
9
|
+
transformSchema(originalWrappingSchema, _subschemaConfig) {
|
|
10
|
+
this.originalWrappingSchema = originalWrappingSchema;
|
|
11
|
+
const typeMap = originalWrappingSchema.getTypeMap();
|
|
18
12
|
for (const typeName in typeMap) {
|
|
19
13
|
const type = typeMap[typeName];
|
|
20
14
|
if (!typeName.startsWith('__')) {
|
|
@@ -23,8 +17,8 @@ export default class MapLeafValues {
|
|
|
23
17
|
}
|
|
24
18
|
}
|
|
25
19
|
}
|
|
26
|
-
this.typeInfo = new TypeInfo(
|
|
27
|
-
return
|
|
20
|
+
this.typeInfo = new TypeInfo(originalWrappingSchema);
|
|
21
|
+
return originalWrappingSchema;
|
|
28
22
|
}
|
|
29
23
|
transformRequest(originalRequest, _delegationContext, transformationContext) {
|
|
30
24
|
var _a;
|
|
@@ -44,19 +38,27 @@ export default class MapLeafValues {
|
|
|
44
38
|
transformationContext.transformedRequest = transformedRequest;
|
|
45
39
|
return transformedRequest;
|
|
46
40
|
}
|
|
47
|
-
transformResult(originalResult,
|
|
48
|
-
|
|
49
|
-
|
|
41
|
+
transformResult(originalResult, _delegationContext, transformationContext) {
|
|
42
|
+
if (!this.originalWrappingSchema) {
|
|
43
|
+
throw new Error(`The MapLeafValues transform's "transformRequest" and "transformResult" methods cannot be used without first calling "transformSchema".`);
|
|
44
|
+
}
|
|
45
|
+
return visitResult(originalResult, transformationContext.transformedRequest, this.originalWrappingSchema, this.resultVisitorMap);
|
|
50
46
|
}
|
|
51
47
|
transformOperations(operations, variableValues) {
|
|
48
|
+
if (this.typeInfo == null) {
|
|
49
|
+
throw new Error(`The MapLeafValues transform's "transformRequest" and "transformResult" methods cannot be used without first calling "transformSchema".`);
|
|
50
|
+
}
|
|
52
51
|
return operations.map((operation) => {
|
|
53
|
-
return visit(operation, visitWithTypeInfo(this.
|
|
52
|
+
return visit(operation, visitWithTypeInfo(this.typeInfo, {
|
|
54
53
|
[Kind.FIELD]: node => this.transformFieldNode(node, variableValues),
|
|
55
54
|
}));
|
|
56
55
|
});
|
|
57
56
|
}
|
|
58
57
|
transformFieldNode(field, variableValues) {
|
|
59
|
-
|
|
58
|
+
if (this.typeInfo == null) {
|
|
59
|
+
throw new Error(`The MapLeafValues transform's "transformRequest" and "transformResult" methods cannot be used without first calling "transformSchema".`);
|
|
60
|
+
}
|
|
61
|
+
const targetField = this.typeInfo.getFieldDef();
|
|
60
62
|
if (!targetField) {
|
|
61
63
|
return;
|
|
62
64
|
}
|
package/package.json
CHANGED
|
@@ -9,12 +9,12 @@ export default class MapLeafValues<TContext = Record<string, any>> implements Tr
|
|
|
9
9
|
private readonly inputValueTransformer;
|
|
10
10
|
private readonly outputValueTransformer;
|
|
11
11
|
private readonly resultVisitorMap;
|
|
12
|
-
private typeInfo
|
|
12
|
+
private typeInfo?;
|
|
13
13
|
constructor(inputValueTransformer: LeafValueTransformer, outputValueTransformer: LeafValueTransformer);
|
|
14
|
-
private
|
|
15
|
-
transformSchema(
|
|
14
|
+
private originalWrappingSchema?;
|
|
15
|
+
transformSchema(originalWrappingSchema: GraphQLSchema, _subschemaConfig: SubschemaConfig<any, any, any, TContext>): GraphQLSchema;
|
|
16
16
|
transformRequest(originalRequest: ExecutionRequest, _delegationContext: DelegationContext<TContext>, transformationContext: MapLeafValuesTransformationContext): ExecutionRequest;
|
|
17
|
-
transformResult(originalResult: ExecutionResult,
|
|
17
|
+
transformResult(originalResult: ExecutionResult, _delegationContext: DelegationContext<TContext>, transformationContext: MapLeafValuesTransformationContext): ExecutionResult;
|
|
18
18
|
private transformOperations;
|
|
19
19
|
private transformFieldNode;
|
|
20
20
|
}
|
|
@@ -9,12 +9,12 @@ export default class MapLeafValues<TContext = Record<string, any>> implements Tr
|
|
|
9
9
|
private readonly inputValueTransformer;
|
|
10
10
|
private readonly outputValueTransformer;
|
|
11
11
|
private readonly resultVisitorMap;
|
|
12
|
-
private typeInfo
|
|
12
|
+
private typeInfo?;
|
|
13
13
|
constructor(inputValueTransformer: LeafValueTransformer, outputValueTransformer: LeafValueTransformer);
|
|
14
|
-
private
|
|
15
|
-
transformSchema(
|
|
14
|
+
private originalWrappingSchema?;
|
|
15
|
+
transformSchema(originalWrappingSchema: GraphQLSchema, _subschemaConfig: SubschemaConfig<any, any, any, TContext>): GraphQLSchema;
|
|
16
16
|
transformRequest(originalRequest: ExecutionRequest, _delegationContext: DelegationContext<TContext>, transformationContext: MapLeafValuesTransformationContext): ExecutionRequest;
|
|
17
|
-
transformResult(originalResult: ExecutionResult,
|
|
17
|
+
transformResult(originalResult: ExecutionResult, _delegationContext: DelegationContext<TContext>, transformationContext: MapLeafValuesTransformationContext): ExecutionResult;
|
|
18
18
|
private transformOperations;
|
|
19
19
|
private transformFieldNode;
|
|
20
20
|
}
|