@graphql-tools/wrap 10.0.0 → 10.0.1-alpha-20230907143500-4c6712a4
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/generateProxyingResolvers.js +1 -1
- package/cjs/transforms/HoistField.js +2 -2
- package/cjs/transforms/MoveRootField.js +2 -1
- package/cjs/transforms/RemoveObjectFieldDeprecations.js +2 -1
- package/cjs/transforms/RemoveObjectFieldsWithDirective.js +2 -1
- package/cjs/transforms/TransformCompositeFields.js +2 -1
- package/cjs/transforms/TransformQuery.js +3 -1
- package/cjs/transforms/WrapFields.js +32 -13
- package/cjs/wrapSchema.js +1 -1
- package/esm/generateProxyingResolvers.js +1 -1
- package/esm/index.js +1 -1
- package/esm/introspect.js +2 -2
- package/esm/transforms/ExtractField.js +1 -1
- package/esm/transforms/FilterTypes.js +1 -1
- package/esm/transforms/HoistField.js +4 -4
- package/esm/transforms/MapLeafValues.js +2 -2
- package/esm/transforms/MoveRootField.js +4 -3
- package/esm/transforms/RemoveObjectFieldDeprecations.js +2 -1
- package/esm/transforms/RemoveObjectFieldsWithDirective.js +2 -1
- package/esm/transforms/RenameInputObjectFields.js +1 -1
- package/esm/transforms/RenameObjectFieldArguments.js +1 -1
- package/esm/transforms/RenameRootTypes.js +2 -2
- package/esm/transforms/RenameTypes.js +2 -2
- package/esm/transforms/TransformCompositeFields.js +4 -3
- package/esm/transforms/TransformInputObjectFields.js +2 -2
- package/esm/transforms/TransformQuery.js +4 -2
- package/esm/transforms/WrapFields.js +34 -15
- package/esm/transforms/WrapQuery.js +1 -1
- package/esm/wrapSchema.js +2 -2
- package/package.json +2 -2
- package/typings/generateProxyingResolvers.d.cts +1 -1
- package/typings/generateProxyingResolvers.d.ts +1 -1
- package/typings/index.d.cts +1 -1
- package/typings/index.d.ts +1 -1
- package/typings/introspect.d.cts +2 -2
- package/typings/introspect.d.ts +2 -2
- package/typings/transforms/ExtractField.d.cts +1 -1
- package/typings/transforms/ExtractField.d.ts +1 -1
- package/typings/transforms/FilterInputObjectFields.d.cts +1 -1
- package/typings/transforms/FilterInputObjectFields.d.ts +1 -1
- package/typings/transforms/FilterInterfaceFields.d.cts +1 -1
- package/typings/transforms/FilterInterfaceFields.d.ts +1 -1
- package/typings/transforms/FilterObjectFields.d.cts +1 -1
- package/typings/transforms/FilterObjectFields.d.ts +1 -1
- package/typings/transforms/FilterRootFields.d.cts +1 -1
- package/typings/transforms/FilterRootFields.d.ts +1 -1
- package/typings/transforms/FilterTypes.d.cts +1 -1
- package/typings/transforms/FilterTypes.d.ts +1 -1
- package/typings/transforms/HoistField.d.cts +2 -2
- package/typings/transforms/HoistField.d.ts +2 -2
- package/typings/transforms/MapFields.d.cts +3 -3
- package/typings/transforms/MapFields.d.ts +3 -3
- package/typings/transforms/MapLeafValues.d.cts +1 -1
- package/typings/transforms/MapLeafValues.d.ts +1 -1
- package/typings/transforms/MoveRootField.d.cts +1 -1
- package/typings/transforms/MoveRootField.d.ts +1 -1
- package/typings/transforms/PruneSchema.d.cts +1 -1
- package/typings/transforms/PruneSchema.d.ts +1 -1
- package/typings/transforms/RenameInputObjectFields.d.cts +2 -2
- package/typings/transforms/RenameInputObjectFields.d.ts +2 -2
- package/typings/transforms/RenameInterfaceFields.d.cts +2 -2
- package/typings/transforms/RenameInterfaceFields.d.ts +2 -2
- package/typings/transforms/RenameObjectFieldArguments.d.cts +1 -1
- package/typings/transforms/RenameObjectFieldArguments.d.ts +1 -1
- package/typings/transforms/RenameObjectFields.d.cts +2 -2
- package/typings/transforms/RenameObjectFields.d.ts +2 -2
- package/typings/transforms/RenameRootFields.d.cts +2 -2
- package/typings/transforms/RenameRootFields.d.ts +2 -2
- package/typings/transforms/RenameRootTypes.d.cts +1 -1
- package/typings/transforms/RenameRootTypes.d.ts +1 -1
- package/typings/transforms/RenameTypes.d.cts +1 -1
- package/typings/transforms/RenameTypes.d.ts +1 -1
- package/typings/transforms/TransformCompositeFields.d.cts +2 -2
- package/typings/transforms/TransformCompositeFields.d.ts +2 -2
- package/typings/transforms/TransformEnumValues.d.cts +1 -1
- package/typings/transforms/TransformEnumValues.d.ts +1 -1
- package/typings/transforms/TransformInputObjectFields.d.cts +2 -2
- package/typings/transforms/TransformInputObjectFields.d.ts +2 -2
- package/typings/transforms/TransformInterfaceFields.d.cts +2 -2
- package/typings/transforms/TransformInterfaceFields.d.ts +2 -2
- package/typings/transforms/TransformObjectFields.d.cts +2 -2
- package/typings/transforms/TransformObjectFields.d.ts +2 -2
- package/typings/transforms/TransformQuery.d.cts +2 -2
- package/typings/transforms/TransformQuery.d.ts +2 -2
- package/typings/transforms/TransformRootFields.d.cts +2 -2
- package/typings/transforms/TransformRootFields.d.ts +2 -2
- package/typings/transforms/WrapFields.d.cts +1 -1
- package/typings/transforms/WrapFields.d.ts +1 -1
- package/typings/transforms/WrapQuery.d.cts +1 -1
- package/typings/transforms/WrapQuery.d.ts +1 -1
- package/typings/transforms/WrapType.d.cts +1 -1
- package/typings/transforms/WrapType.d.ts +1 -1
- package/typings/types.d.cts +1 -1
- package/typings/types.d.ts +1 -1
- package/typings/wrapSchema.d.cts +1 -1
- package/typings/wrapSchema.d.ts +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.defaultCreateProxyingResolver = exports.generateProxyingResolvers = void 0;
|
|
4
|
-
const utils_1 = require("@graphql-tools/utils");
|
|
5
4
|
const delegate_1 = require("@graphql-tools/delegate");
|
|
5
|
+
const utils_1 = require("@graphql-tools/utils");
|
|
6
6
|
function generateProxyingResolvers(subschemaConfig) {
|
|
7
7
|
const targetSchema = subschemaConfig.schema;
|
|
8
8
|
const createProxyingResolver = subschemaConfig.createProxyingResolver ?? defaultCreateProxyingResolver;
|
|
@@ -3,15 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.unwrapValue = exports.renameFieldNode = exports.wrapFieldNode = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const graphql_1 = require("graphql");
|
|
6
|
-
const utils_1 = require("@graphql-tools/utils");
|
|
7
6
|
const delegate_1 = require("@graphql-tools/delegate");
|
|
7
|
+
const utils_1 = require("@graphql-tools/utils");
|
|
8
8
|
const generateProxyingResolvers_js_1 = require("../generateProxyingResolvers.js");
|
|
9
9
|
const MapFields_js_1 = tslib_1.__importDefault(require("./MapFields.js"));
|
|
10
10
|
class HoistField {
|
|
11
11
|
constructor(typeName, pathConfig, newFieldName, alias = '__gqtlw__') {
|
|
12
12
|
this.typeName = typeName;
|
|
13
13
|
this.newFieldName = newFieldName;
|
|
14
|
-
const path = pathConfig.map(segment =>
|
|
14
|
+
const path = pathConfig.map(segment => typeof segment === 'string' ? segment : segment.fieldName);
|
|
15
15
|
this.argFilters = pathConfig.map((segment, index) => {
|
|
16
16
|
if (typeof segment === 'string' || segment.argFilter == null) {
|
|
17
17
|
return index === pathConfig.length - 1 ? () => true : () => false;
|
|
@@ -89,7 +89,8 @@ class MoveRootField {
|
|
|
89
89
|
if (result.data?.__typename) {
|
|
90
90
|
const newOperation = this.to[delegationContext.operation][delegationContext.fieldName];
|
|
91
91
|
if (newOperation && newOperation !== delegationContext.operation) {
|
|
92
|
-
result.data.__typename = (0, utils_1.getDefinedRootType)(delegationContext.targetSchema, newOperation)
|
|
92
|
+
result.data.__typename = (0, utils_1.getDefinedRootType)(delegationContext.targetSchema, newOperation)
|
|
93
|
+
?.name;
|
|
93
94
|
}
|
|
94
95
|
}
|
|
95
96
|
return result;
|
|
@@ -11,7 +11,8 @@ class RemoveObjectFieldDeprecations {
|
|
|
11
11
|
return !(dirName === 'deprecated' && (0, utils_1.valueMatchesCriteria)(dirValue, args));
|
|
12
12
|
});
|
|
13
13
|
this.removeDeprecations = new TransformObjectFields_js_1.default((_typeName, _fieldName, fieldConfig) => {
|
|
14
|
-
if (fieldConfig.deprecationReason &&
|
|
14
|
+
if (fieldConfig.deprecationReason &&
|
|
15
|
+
(0, utils_1.valueMatchesCriteria)(fieldConfig.deprecationReason, reason)) {
|
|
15
16
|
fieldConfig = { ...fieldConfig };
|
|
16
17
|
delete fieldConfig.deprecationReason;
|
|
17
18
|
}
|
|
@@ -11,7 +11,8 @@ class RemoveObjectFieldsWithDirective {
|
|
|
11
11
|
transformSchema(originalWrappingSchema, subschemaConfig) {
|
|
12
12
|
const transformer = new FilterObjectFields_js_1.default((_typeName, _fieldName, fieldConfig) => {
|
|
13
13
|
const directives = (0, utils_1.getDirectives)(originalWrappingSchema, fieldConfig);
|
|
14
|
-
return !directives.some(directive => (0, utils_1.valueMatchesCriteria)(directive.name, this.directiveName) &&
|
|
14
|
+
return !directives.some(directive => (0, utils_1.valueMatchesCriteria)(directive.name, this.directiveName) &&
|
|
15
|
+
(0, utils_1.valueMatchesCriteria)(directive.args, this.args));
|
|
15
16
|
});
|
|
16
17
|
return transformer.transformSchema(originalWrappingSchema, subschemaConfig);
|
|
17
18
|
}
|
|
@@ -100,7 +100,8 @@ class TransformCompositeFields {
|
|
|
100
100
|
}
|
|
101
101
|
else {
|
|
102
102
|
transformedSelection = this.fieldNodeTransformer(parentTypeName, newName, selection, fragments, transformationContext);
|
|
103
|
-
transformedSelection =
|
|
103
|
+
transformedSelection =
|
|
104
|
+
transformedSelection === undefined ? selection : transformedSelection;
|
|
104
105
|
}
|
|
105
106
|
if (transformedSelection == null) {
|
|
106
107
|
continue;
|
|
@@ -81,7 +81,9 @@ class TransformQuery {
|
|
|
81
81
|
}
|
|
82
82
|
index++;
|
|
83
83
|
}
|
|
84
|
-
const newPath = match
|
|
84
|
+
const newPath = match
|
|
85
|
+
? path.slice(0, index).concat(this.errorPathTransformer(path.slice(index)))
|
|
86
|
+
: path;
|
|
85
87
|
return (0, utils_1.relocatedError)(error, newPath);
|
|
86
88
|
});
|
|
87
89
|
}
|
|
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.dehoistValue = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const graphql_1 = require("graphql");
|
|
6
|
-
const utils_1 = require("@graphql-tools/utils");
|
|
7
6
|
const delegate_1 = require("@graphql-tools/delegate");
|
|
8
|
-
const
|
|
7
|
+
const utils_1 = require("@graphql-tools/utils");
|
|
9
8
|
const generateProxyingResolvers_js_1 = require("../generateProxyingResolvers.js");
|
|
9
|
+
const MapFields_js_1 = tslib_1.__importDefault(require("./MapFields.js"));
|
|
10
10
|
class WrapFields {
|
|
11
11
|
constructor(outerTypeName, wrappingFieldNames, wrappingTypeNames, fieldNames, prefix = 'gqtld') {
|
|
12
12
|
this.outerTypeName = outerTypeName;
|
|
@@ -61,27 +61,44 @@ class WrapFields {
|
|
|
61
61
|
wrappingTypeName = nextWrappingTypeName;
|
|
62
62
|
wrappingFieldName = this.wrappingFieldNames[wrapIndex];
|
|
63
63
|
}
|
|
64
|
-
const
|
|
65
|
-
|
|
64
|
+
const targetSchema = subschemaConfig.schema;
|
|
65
|
+
let wrappingOperation;
|
|
66
|
+
switch (this.outerTypeName) {
|
|
67
|
+
case targetSchema.getQueryType()?.name:
|
|
68
|
+
wrappingOperation = 'query';
|
|
69
|
+
break;
|
|
70
|
+
case targetSchema.getMutationType()?.name:
|
|
71
|
+
wrappingOperation = 'mutation';
|
|
72
|
+
break;
|
|
73
|
+
case targetSchema.getSubscriptionType()?.name:
|
|
74
|
+
wrappingOperation = 'subscription';
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
66
77
|
let resolve;
|
|
67
|
-
if (
|
|
68
|
-
const targetSchema = subschemaConfig.schema;
|
|
69
|
-
const operation = this.outerTypeName === targetSchema.getQueryType()?.name ? 'query' : 'mutation';
|
|
78
|
+
if (wrappingOperation) {
|
|
70
79
|
const createProxyingResolver = subschemaConfig.createProxyingResolver ?? generateProxyingResolvers_js_1.defaultCreateProxyingResolver;
|
|
71
80
|
resolve = createProxyingResolver({
|
|
72
81
|
subschemaConfig,
|
|
73
|
-
operation:
|
|
82
|
+
operation: wrappingOperation,
|
|
74
83
|
fieldName: wrappingFieldName,
|
|
75
84
|
});
|
|
76
85
|
}
|
|
77
86
|
else {
|
|
78
87
|
resolve = delegate_1.defaultMergedResolver;
|
|
79
88
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
89
|
+
const wrappingType = new graphql_1.GraphQLNonNull(newSchema.getType(wrappingTypeName));
|
|
90
|
+
const newFieldConfig = wrappingOperation === 'subscription'
|
|
91
|
+
? {
|
|
92
|
+
type: wrappingType,
|
|
93
|
+
subscribe: resolve,
|
|
94
|
+
resolve: (payload) => payload,
|
|
95
|
+
}
|
|
96
|
+
: {
|
|
97
|
+
type: wrappingType,
|
|
83
98
|
resolve,
|
|
84
|
-
}
|
|
99
|
+
};
|
|
100
|
+
[newSchema] = (0, utils_1.modifyObjectFields)(newSchema, this.outerTypeName, fieldName => !!newTargetFieldConfigMap[fieldName], {
|
|
101
|
+
[wrappingFieldName]: newFieldConfig,
|
|
85
102
|
});
|
|
86
103
|
return this.transformer.transformSchema(newSchema, subschemaConfig);
|
|
87
104
|
}
|
|
@@ -159,7 +176,9 @@ function hoistFieldNodes({ fieldNode, fieldNames, path, fragments, transformatio
|
|
|
159
176
|
const indexingAlias = `__${prefix}${nextIndex}__`;
|
|
160
177
|
transformationContext.paths[indexingAlias] = {
|
|
161
178
|
pathToField: wrappingPath.concat([alias]),
|
|
162
|
-
alias: possibleFieldNode.alias != null
|
|
179
|
+
alias: possibleFieldNode.alias != null
|
|
180
|
+
? possibleFieldNode.alias.value
|
|
181
|
+
: possibleFieldNode.name.value,
|
|
163
182
|
};
|
|
164
183
|
newFieldNodes.push(aliasFieldNode(possibleFieldNode, indexingAlias));
|
|
165
184
|
}
|
package/cjs/wrapSchema.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.wrapSchema = void 0;
|
|
4
4
|
const graphql_1 = require("graphql");
|
|
5
|
-
const utils_1 = require("@graphql-tools/utils");
|
|
6
5
|
const delegate_1 = require("@graphql-tools/delegate");
|
|
6
|
+
const utils_1 = require("@graphql-tools/utils");
|
|
7
7
|
const generateProxyingResolvers_js_1 = require("./generateProxyingResolvers.js");
|
|
8
8
|
exports.wrapSchema = (0, utils_1.memoize1)(function wrapSchema(subschemaConfig) {
|
|
9
9
|
const targetSchema = subschemaConfig.schema;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { delegateToSchema, getSubschema, getUnpathedErrors, isExternalObject, resolveExternalValue, } from '@graphql-tools/delegate';
|
|
1
2
|
import { getResponseKeyFromInfo, getRootTypeMap } from '@graphql-tools/utils';
|
|
2
|
-
import { delegateToSchema, getSubschema, resolveExternalValue, isExternalObject, getUnpathedErrors, } from '@graphql-tools/delegate';
|
|
3
3
|
export function generateProxyingResolvers(subschemaConfig) {
|
|
4
4
|
const targetSchema = subschemaConfig.schema;
|
|
5
5
|
const createProxyingResolver = subschemaConfig.createProxyingResolver ?? defaultCreateProxyingResolver;
|
package/esm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from './wrapSchema.js';
|
|
2
|
-
export { defaultCreateProxyingResolver, generateProxyingResolvers } from './generateProxyingResolvers.js';
|
|
2
|
+
export { defaultCreateProxyingResolver, generateProxyingResolvers, } from './generateProxyingResolvers.js';
|
|
3
3
|
export * from './transforms/index.js';
|
|
4
4
|
export * from './types.js';
|
|
5
5
|
export * from './introspect.js';
|
package/esm/introspect.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { buildClientSchema, getIntrospectionQuery, parse, } from 'graphql';
|
|
2
2
|
import { ValueOrPromise } from 'value-or-promise';
|
|
3
|
-
import {
|
|
3
|
+
import { createGraphQLError, inspect, isAsyncIterable, } from '@graphql-tools/utils';
|
|
4
4
|
function getSchemaFromIntrospection(introspectionResult, options) {
|
|
5
5
|
if (introspectionResult?.data?.__schema) {
|
|
6
6
|
return buildClientSchema(introspectionResult.data, options);
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { getNullableType,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { getNamedType, getNullableType, GraphQLList, isListType, Kind, } from 'graphql';
|
|
2
|
+
import { defaultMergedResolver, } from '@graphql-tools/delegate';
|
|
3
|
+
import { appendObjectFields, relocatedError, removeObjectFields, } from '@graphql-tools/utils';
|
|
4
4
|
import { defaultCreateProxyingResolver } from '../generateProxyingResolvers.js';
|
|
5
5
|
import MapFields from './MapFields.js';
|
|
6
6
|
export default class HoistField {
|
|
7
7
|
constructor(typeName, pathConfig, newFieldName, alias = '__gqtlw__') {
|
|
8
8
|
this.typeName = typeName;
|
|
9
9
|
this.newFieldName = newFieldName;
|
|
10
|
-
const path = pathConfig.map(segment =>
|
|
10
|
+
const path = pathConfig.map(segment => typeof segment === 'string' ? segment : segment.fieldName);
|
|
11
11
|
this.argFilters = pathConfig.map((segment, index) => {
|
|
12
12
|
if (typeof segment === 'string' || segment.argFilter == null) {
|
|
13
13
|
return index === pathConfig.length - 1 ? () => true : () => false;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { astFromValue, isLeafType, Kind, TypeInfo, valueFromAST, valueFromASTUntyped, visit, visitWithTypeInfo, } from 'graphql';
|
|
2
|
+
import { transformInputValue, visitResult, } from '@graphql-tools/utils';
|
|
3
3
|
export default class MapLeafValues {
|
|
4
4
|
constructor(inputValueTransformer, outputValueTransformer) {
|
|
5
5
|
this.inputValueTransformer = inputValueTransformer;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { GraphQLObjectType, GraphQLSchema, Kind, visit } from 'graphql';
|
|
2
|
-
import {
|
|
1
|
+
import { GraphQLObjectType, GraphQLSchema, Kind, visit, } from 'graphql';
|
|
2
|
+
import { getDefinedRootType, getRootTypeMap, MapperKind, mapSchema, } from '@graphql-tools/utils';
|
|
3
3
|
const defaultRootTypeNames = {
|
|
4
4
|
query: 'Query',
|
|
5
5
|
mutation: 'Mutation',
|
|
@@ -86,7 +86,8 @@ export class MoveRootField {
|
|
|
86
86
|
if (result.data?.__typename) {
|
|
87
87
|
const newOperation = this.to[delegationContext.operation][delegationContext.fieldName];
|
|
88
88
|
if (newOperation && newOperation !== delegationContext.operation) {
|
|
89
|
-
result.data.__typename = getDefinedRootType(delegationContext.targetSchema, newOperation)
|
|
89
|
+
result.data.__typename = getDefinedRootType(delegationContext.targetSchema, newOperation)
|
|
90
|
+
?.name;
|
|
90
91
|
}
|
|
91
92
|
}
|
|
92
93
|
return result;
|
|
@@ -8,7 +8,8 @@ export default class RemoveObjectFieldDeprecations {
|
|
|
8
8
|
return !(dirName === 'deprecated' && valueMatchesCriteria(dirValue, args));
|
|
9
9
|
});
|
|
10
10
|
this.removeDeprecations = new TransformObjectFields((_typeName, _fieldName, fieldConfig) => {
|
|
11
|
-
if (fieldConfig.deprecationReason &&
|
|
11
|
+
if (fieldConfig.deprecationReason &&
|
|
12
|
+
valueMatchesCriteria(fieldConfig.deprecationReason, reason)) {
|
|
12
13
|
fieldConfig = { ...fieldConfig };
|
|
13
14
|
delete fieldConfig.deprecationReason;
|
|
14
15
|
}
|
|
@@ -8,7 +8,8 @@ export default class RemoveObjectFieldsWithDirective {
|
|
|
8
8
|
transformSchema(originalWrappingSchema, subschemaConfig) {
|
|
9
9
|
const transformer = new FilterObjectFields((_typeName, _fieldName, fieldConfig) => {
|
|
10
10
|
const directives = getDirectives(originalWrappingSchema, fieldConfig);
|
|
11
|
-
return !directives.some(directive => valueMatchesCriteria(directive.name, this.directiveName) &&
|
|
11
|
+
return !directives.some(directive => valueMatchesCriteria(directive.name, this.directiveName) &&
|
|
12
|
+
valueMatchesCriteria(directive.args, this.args));
|
|
12
13
|
});
|
|
13
14
|
return transformer.transformSchema(originalWrappingSchema, subschemaConfig);
|
|
14
15
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MapperKind, mapSchema } from '@graphql-tools/utils';
|
|
2
2
|
import TransformInputObjectFields from './TransformInputObjectFields.js';
|
|
3
3
|
export default class RenameInputObjectFields {
|
|
4
4
|
constructor(renamer) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { MapperKind, mapSchema, renameType, visitData } from '@graphql-tools/utils';
|
|
1
|
+
import { Kind, visit } from 'graphql';
|
|
2
|
+
import { MapperKind, mapSchema, renameType, visitData, } from '@graphql-tools/utils';
|
|
3
3
|
export default class RenameRootTypes {
|
|
4
4
|
constructor(renamer) {
|
|
5
5
|
this.renamer = renamer;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { MapperKind, mapSchema,
|
|
1
|
+
import { isScalarType, isSpecifiedScalarType, Kind, visit, } from 'graphql';
|
|
2
|
+
import { MapperKind, mapSchema, renameType, visitData, } from '@graphql-tools/utils';
|
|
3
3
|
export default class RenameTypes {
|
|
4
4
|
constructor(renamer, options) {
|
|
5
5
|
this.renamer = renamer;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { TypeInfo, visit, visitWithTypeInfo,
|
|
2
|
-
import { MapperKind, mapSchema, visitData } from '@graphql-tools/utils';
|
|
1
|
+
import { Kind, TypeInfo, visit, visitWithTypeInfo, } from 'graphql';
|
|
2
|
+
import { MapperKind, mapSchema, visitData, } from '@graphql-tools/utils';
|
|
3
3
|
export default class TransformCompositeFields {
|
|
4
4
|
constructor(fieldTransformer, fieldNodeTransformer, dataTransformer, errorsTransformer) {
|
|
5
5
|
this.fieldTransformer = fieldTransformer;
|
|
@@ -98,7 +98,8 @@ export default class TransformCompositeFields {
|
|
|
98
98
|
}
|
|
99
99
|
else {
|
|
100
100
|
transformedSelection = this.fieldNodeTransformer(parentTypeName, newName, selection, fragments, transformationContext);
|
|
101
|
-
transformedSelection =
|
|
101
|
+
transformedSelection =
|
|
102
|
+
transformedSelection === undefined ? selection : transformedSelection;
|
|
102
103
|
}
|
|
103
104
|
if (transformedSelection == null) {
|
|
104
105
|
continue;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getDefinedRootType, MapperKind, mapSchema, transformInputValue } from '@graphql-tools/utils';
|
|
1
|
+
import { getNamedType, isInputType, Kind, typeFromAST, TypeInfo, visit, visitWithTypeInfo, } from 'graphql';
|
|
2
|
+
import { getDefinedRootType, MapperKind, mapSchema, transformInputValue, } from '@graphql-tools/utils';
|
|
3
3
|
export default class TransformInputObjectFields {
|
|
4
4
|
constructor(inputFieldTransformer, inputFieldNodeTransformer, inputObjectNodeTransformer) {
|
|
5
5
|
this.inputFieldTransformer = inputFieldTransformer;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Kind, visit } from 'graphql';
|
|
2
2
|
import { relocatedError } from '@graphql-tools/utils';
|
|
3
3
|
export default class TransformQuery {
|
|
4
4
|
constructor({ path, queryTransformer, resultTransformer = result => result, errorPathTransformer = errorPath => [...errorPath], fragments = {}, }) {
|
|
@@ -79,7 +79,9 @@ export default class TransformQuery {
|
|
|
79
79
|
}
|
|
80
80
|
index++;
|
|
81
81
|
}
|
|
82
|
-
const newPath = match
|
|
82
|
+
const newPath = match
|
|
83
|
+
? path.slice(0, index).concat(this.errorPathTransformer(path.slice(index)))
|
|
84
|
+
: path;
|
|
83
85
|
return relocatedError(error, newPath);
|
|
84
86
|
});
|
|
85
87
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import MapFields from './MapFields.js';
|
|
1
|
+
import { GraphQLNonNull, Kind, } from 'graphql';
|
|
2
|
+
import { defaultMergedResolver, } from '@graphql-tools/delegate';
|
|
3
|
+
import { appendObjectFields, modifyObjectFields, relocatedError, selectObjectFields, } from '@graphql-tools/utils';
|
|
5
4
|
import { defaultCreateProxyingResolver } from '../generateProxyingResolvers.js';
|
|
5
|
+
import MapFields from './MapFields.js';
|
|
6
6
|
export default class WrapFields {
|
|
7
7
|
constructor(outerTypeName, wrappingFieldNames, wrappingTypeNames, fieldNames, prefix = 'gqtld') {
|
|
8
8
|
this.outerTypeName = outerTypeName;
|
|
@@ -57,27 +57,44 @@ export default class WrapFields {
|
|
|
57
57
|
wrappingTypeName = nextWrappingTypeName;
|
|
58
58
|
wrappingFieldName = this.wrappingFieldNames[wrapIndex];
|
|
59
59
|
}
|
|
60
|
-
const
|
|
61
|
-
|
|
60
|
+
const targetSchema = subschemaConfig.schema;
|
|
61
|
+
let wrappingOperation;
|
|
62
|
+
switch (this.outerTypeName) {
|
|
63
|
+
case targetSchema.getQueryType()?.name:
|
|
64
|
+
wrappingOperation = 'query';
|
|
65
|
+
break;
|
|
66
|
+
case targetSchema.getMutationType()?.name:
|
|
67
|
+
wrappingOperation = 'mutation';
|
|
68
|
+
break;
|
|
69
|
+
case targetSchema.getSubscriptionType()?.name:
|
|
70
|
+
wrappingOperation = 'subscription';
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
62
73
|
let resolve;
|
|
63
|
-
if (
|
|
64
|
-
const targetSchema = subschemaConfig.schema;
|
|
65
|
-
const operation = this.outerTypeName === targetSchema.getQueryType()?.name ? 'query' : 'mutation';
|
|
74
|
+
if (wrappingOperation) {
|
|
66
75
|
const createProxyingResolver = subschemaConfig.createProxyingResolver ?? defaultCreateProxyingResolver;
|
|
67
76
|
resolve = createProxyingResolver({
|
|
68
77
|
subschemaConfig,
|
|
69
|
-
operation:
|
|
78
|
+
operation: wrappingOperation,
|
|
70
79
|
fieldName: wrappingFieldName,
|
|
71
80
|
});
|
|
72
81
|
}
|
|
73
82
|
else {
|
|
74
83
|
resolve = defaultMergedResolver;
|
|
75
84
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
85
|
+
const wrappingType = new GraphQLNonNull(newSchema.getType(wrappingTypeName));
|
|
86
|
+
const newFieldConfig = wrappingOperation === 'subscription'
|
|
87
|
+
? {
|
|
88
|
+
type: wrappingType,
|
|
89
|
+
subscribe: resolve,
|
|
90
|
+
resolve: (payload) => payload,
|
|
91
|
+
}
|
|
92
|
+
: {
|
|
93
|
+
type: wrappingType,
|
|
79
94
|
resolve,
|
|
80
|
-
}
|
|
95
|
+
};
|
|
96
|
+
[newSchema] = modifyObjectFields(newSchema, this.outerTypeName, fieldName => !!newTargetFieldConfigMap[fieldName], {
|
|
97
|
+
[wrappingFieldName]: newFieldConfig,
|
|
81
98
|
});
|
|
82
99
|
return this.transformer.transformSchema(newSchema, subschemaConfig);
|
|
83
100
|
}
|
|
@@ -154,7 +171,9 @@ function hoistFieldNodes({ fieldNode, fieldNames, path, fragments, transformatio
|
|
|
154
171
|
const indexingAlias = `__${prefix}${nextIndex}__`;
|
|
155
172
|
transformationContext.paths[indexingAlias] = {
|
|
156
173
|
pathToField: wrappingPath.concat([alias]),
|
|
157
|
-
alias: possibleFieldNode.alias != null
|
|
174
|
+
alias: possibleFieldNode.alias != null
|
|
175
|
+
? possibleFieldNode.alias.value
|
|
176
|
+
: possibleFieldNode.name.value,
|
|
158
177
|
};
|
|
159
178
|
newFieldNodes.push(aliasFieldNode(possibleFieldNode, indexingAlias));
|
|
160
179
|
}
|
package/esm/wrapSchema.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GraphQLInterfaceType, GraphQLObjectType, GraphQLUnionType, } from 'graphql';
|
|
2
|
+
import { applySchemaTransforms, defaultMergedResolver, } from '@graphql-tools/delegate';
|
|
2
3
|
import { MapperKind, mapSchema, memoize1 } from '@graphql-tools/utils';
|
|
3
|
-
import { defaultMergedResolver, applySchemaTransforms } from '@graphql-tools/delegate';
|
|
4
4
|
import { generateProxyingResolvers } from './generateProxyingResolvers.js';
|
|
5
5
|
export const wrapSchema = memoize1(function wrapSchema(subschemaConfig) {
|
|
6
6
|
const targetSchema = subschemaConfig.schema;
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-tools/wrap",
|
|
3
|
-
"version": "10.0.
|
|
3
|
+
"version": "10.0.1-alpha-20230907143500-4c6712a4",
|
|
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 || ^17.0.0"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@graphql-tools/delegate": "
|
|
10
|
+
"@graphql-tools/delegate": "10.0.3-alpha-20230907143500-4c6712a4",
|
|
11
11
|
"@graphql-tools/schema": "^10.0.0",
|
|
12
12
|
"@graphql-tools/utils": "^10.0.0",
|
|
13
13
|
"tslib": "^2.4.0",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { GraphQLFieldResolver } from 'graphql';
|
|
2
|
-
import {
|
|
2
|
+
import { ICreateProxyingResolverOptions, SubschemaConfig } from '@graphql-tools/delegate';
|
|
3
3
|
export declare function generateProxyingResolvers<TContext extends Record<string, any>>(subschemaConfig: SubschemaConfig<any, any, any, TContext>): Record<string, Record<string, GraphQLFieldResolver<any, any>>>;
|
|
4
4
|
export declare function defaultCreateProxyingResolver<TContext extends Record<string, any>>({ subschemaConfig, operation, }: ICreateProxyingResolverOptions<TContext>): GraphQLFieldResolver<any, any>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { GraphQLFieldResolver } from 'graphql';
|
|
2
|
-
import {
|
|
2
|
+
import { ICreateProxyingResolverOptions, SubschemaConfig } from '@graphql-tools/delegate';
|
|
3
3
|
export declare function generateProxyingResolvers<TContext extends Record<string, any>>(subschemaConfig: SubschemaConfig<any, any, any, TContext>): Record<string, Record<string, GraphQLFieldResolver<any, any>>>;
|
|
4
4
|
export declare function defaultCreateProxyingResolver<TContext extends Record<string, any>>({ subschemaConfig, operation, }: ICreateProxyingResolverOptions<TContext>): GraphQLFieldResolver<any, any>;
|
package/typings/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from './wrapSchema.cjs';
|
|
2
|
-
export { defaultCreateProxyingResolver, generateProxyingResolvers } from './generateProxyingResolvers.cjs';
|
|
2
|
+
export { defaultCreateProxyingResolver, generateProxyingResolvers, } from './generateProxyingResolvers.cjs';
|
|
3
3
|
export * from './transforms/index.cjs';
|
|
4
4
|
export * from './types.cjs';
|
|
5
5
|
export * from './introspect.cjs';
|
package/typings/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from './wrapSchema.js';
|
|
2
|
-
export { defaultCreateProxyingResolver, generateProxyingResolvers } from './generateProxyingResolvers.js';
|
|
2
|
+
export { defaultCreateProxyingResolver, generateProxyingResolvers, } from './generateProxyingResolvers.js';
|
|
3
3
|
export * from './transforms/index.js';
|
|
4
4
|
export * from './types.js';
|
|
5
5
|
export * from './introspect.js';
|
package/typings/introspect.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AsyncExecutor, Executor,
|
|
1
|
+
import { buildClientSchema, GraphQLSchema, IntrospectionOptions, ParseOptions } from 'graphql';
|
|
2
|
+
import { AsyncExecutor, Executor, MaybePromise, SyncExecutor } from '@graphql-tools/utils';
|
|
3
3
|
export type SchemaFromExecutorOptions = Partial<IntrospectionOptions> & Parameters<typeof buildClientSchema>[1] & ParseOptions;
|
|
4
4
|
export declare function schemaFromExecutor(executor: SyncExecutor, context?: Record<string, any>, options?: SchemaFromExecutorOptions): GraphQLSchema;
|
|
5
5
|
export declare function schemaFromExecutor(executor: AsyncExecutor, context?: Record<string, any>, options?: SchemaFromExecutorOptions): Promise<GraphQLSchema>;
|
package/typings/introspect.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AsyncExecutor, Executor,
|
|
1
|
+
import { buildClientSchema, GraphQLSchema, IntrospectionOptions, ParseOptions } from 'graphql';
|
|
2
|
+
import { AsyncExecutor, Executor, MaybePromise, SyncExecutor } from '@graphql-tools/utils';
|
|
3
3
|
export type SchemaFromExecutorOptions = Partial<IntrospectionOptions> & Parameters<typeof buildClientSchema>[1] & ParseOptions;
|
|
4
4
|
export declare function schemaFromExecutor(executor: SyncExecutor, context?: Record<string, any>, options?: SchemaFromExecutorOptions): GraphQLSchema;
|
|
5
5
|
export declare function schemaFromExecutor(executor: AsyncExecutor, context?: Record<string, any>, options?: SchemaFromExecutorOptions): Promise<GraphQLSchema>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { DelegationContext, Transform } from '@graphql-tools/delegate';
|
|
1
2
|
import { ExecutionRequest } from '@graphql-tools/utils';
|
|
2
|
-
import { Transform, DelegationContext } from '@graphql-tools/delegate';
|
|
3
3
|
interface ExtractFieldTransformationContext extends Record<string, any> {
|
|
4
4
|
}
|
|
5
5
|
export default class ExtractField<TContext = Record<string, any>> implements Transform<ExtractFieldTransformationContext, TContext> {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { DelegationContext, Transform } from '@graphql-tools/delegate';
|
|
1
2
|
import { ExecutionRequest } from '@graphql-tools/utils';
|
|
2
|
-
import { Transform, DelegationContext } from '@graphql-tools/delegate';
|
|
3
3
|
interface ExtractFieldTransformationContext extends Record<string, any> {
|
|
4
4
|
}
|
|
5
5
|
export default class ExtractField<TContext = Record<string, any>> implements Transform<ExtractFieldTransformationContext, TContext> {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GraphQLSchema } from 'graphql';
|
|
2
|
+
import { DelegationContext, SubschemaConfig, Transform } from '@graphql-tools/delegate';
|
|
2
3
|
import { ExecutionRequest, InputFieldFilter } from '@graphql-tools/utils';
|
|
3
|
-
import { Transform, DelegationContext, SubschemaConfig } from '@graphql-tools/delegate';
|
|
4
4
|
import { InputObjectNodeTransformer } from '../types.cjs';
|
|
5
5
|
interface FilterInputObjectFieldsTransformationContext extends Record<string, any> {
|
|
6
6
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GraphQLSchema } from 'graphql';
|
|
2
|
+
import { DelegationContext, SubschemaConfig, Transform } from '@graphql-tools/delegate';
|
|
2
3
|
import { ExecutionRequest, InputFieldFilter } from '@graphql-tools/utils';
|
|
3
|
-
import { Transform, DelegationContext, SubschemaConfig } from '@graphql-tools/delegate';
|
|
4
4
|
import { InputObjectNodeTransformer } from '../types.js';
|
|
5
5
|
interface FilterInputObjectFieldsTransformationContext extends Record<string, any> {
|
|
6
6
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GraphQLSchema } from 'graphql';
|
|
2
|
-
import { FieldFilter } from '@graphql-tools/utils';
|
|
3
2
|
import { SubschemaConfig, Transform } from '@graphql-tools/delegate';
|
|
3
|
+
import { FieldFilter } from '@graphql-tools/utils';
|
|
4
4
|
interface FilterInterfaceFieldsTransformationContext extends Record<string, any> {
|
|
5
5
|
}
|
|
6
6
|
export default class FilterInterfaceFields<TContext = Record<string, any>> implements Transform<FilterInterfaceFieldsTransformationContext, TContext> {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GraphQLSchema } from 'graphql';
|
|
2
|
-
import { FieldFilter } from '@graphql-tools/utils';
|
|
3
2
|
import { SubschemaConfig, Transform } from '@graphql-tools/delegate';
|
|
3
|
+
import { FieldFilter } from '@graphql-tools/utils';
|
|
4
4
|
interface FilterInterfaceFieldsTransformationContext extends Record<string, any> {
|
|
5
5
|
}
|
|
6
6
|
export default class FilterInterfaceFields<TContext = Record<string, any>> implements Transform<FilterInterfaceFieldsTransformationContext, TContext> {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GraphQLSchema } from 'graphql';
|
|
2
|
-
import { ObjectFieldFilter } from '@graphql-tools/utils';
|
|
3
2
|
import { SubschemaConfig, Transform } from '@graphql-tools/delegate';
|
|
3
|
+
import { ObjectFieldFilter } from '@graphql-tools/utils';
|
|
4
4
|
interface FilterObjectFieldsTransformationContext extends Record<string, any> {
|
|
5
5
|
}
|
|
6
6
|
export default class FilterObjectFields<TContext = Record<string, any>> implements Transform<FilterObjectFieldsTransformationContext, TContext> {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GraphQLSchema } from 'graphql';
|
|
2
|
-
import { ObjectFieldFilter } from '@graphql-tools/utils';
|
|
3
2
|
import { SubschemaConfig, Transform } from '@graphql-tools/delegate';
|
|
3
|
+
import { ObjectFieldFilter } from '@graphql-tools/utils';
|
|
4
4
|
interface FilterObjectFieldsTransformationContext extends Record<string, any> {
|
|
5
5
|
}
|
|
6
6
|
export default class FilterObjectFields<TContext = Record<string, any>> implements Transform<FilterObjectFieldsTransformationContext, TContext> {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GraphQLSchema } from 'graphql';
|
|
2
|
-
import { RootFieldFilter } from '@graphql-tools/utils';
|
|
3
2
|
import { SubschemaConfig, Transform } from '@graphql-tools/delegate';
|
|
3
|
+
import { RootFieldFilter } from '@graphql-tools/utils';
|
|
4
4
|
interface FilterRootFieldsTransformationContext extends Record<string, any> {
|
|
5
5
|
}
|
|
6
6
|
export default class FilterRootFields<TContext = Record<string, any>> implements Transform<FilterRootFieldsTransformationContext, TContext> {
|