@graphql-tools/wrap 9.2.16 → 9.2.17-alpha-20221130183912-f3cd3c72
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/transforms/HoistField.js +14 -1
- package/esm/transforms/HoistField.js +15 -2
- package/package.json +1 -1
- package/typings/transforms/RenameInputObjectFields.d.cts +1 -1
- package/typings/transforms/RenameInputObjectFields.d.ts +1 -1
- package/typings/transforms/RenameObjectFieldArguments.d.cts +1 -1
- package/typings/transforms/RenameObjectFieldArguments.d.ts +1 -1
- package/typings/transforms/TransformQuery.d.cts +3 -3
- package/typings/transforms/TransformQuery.d.ts +3 -3
- package/typings/transforms/WrapQuery.d.cts +1 -1
- package/typings/transforms/WrapQuery.d.ts +1 -1
- package/typings/types.d.cts +11 -11
- package/typings/types.d.ts +11 -11
|
@@ -38,6 +38,7 @@ class HoistField {
|
|
|
38
38
|
transformSchema(originalWrappingSchema, subschemaConfig) {
|
|
39
39
|
var _a, _b, _c, _d;
|
|
40
40
|
const argsMap = Object.create(null);
|
|
41
|
+
let isList = false;
|
|
41
42
|
const innerType = this.pathToField.reduce((acc, pathSegment, index) => {
|
|
42
43
|
const field = acc.getFields()[pathSegment];
|
|
43
44
|
for (const arg of field.args) {
|
|
@@ -46,7 +47,12 @@ class HoistField {
|
|
|
46
47
|
this.argLevels[arg.name] = index;
|
|
47
48
|
}
|
|
48
49
|
}
|
|
49
|
-
|
|
50
|
+
const nullableType = (0, graphql_1.getNullableType)(field.type);
|
|
51
|
+
if ((0, graphql_1.isListType)(nullableType)) {
|
|
52
|
+
isList = true;
|
|
53
|
+
return (0, graphql_1.getNamedType)(nullableType);
|
|
54
|
+
}
|
|
55
|
+
return nullableType;
|
|
50
56
|
}, originalWrappingSchema.getType(this.typeName));
|
|
51
57
|
let [newSchema, targetFieldConfigMap] = (0, utils_1.removeObjectFields)(originalWrappingSchema, innerType.name, fieldName => fieldName === this.oldFieldName);
|
|
52
58
|
const targetField = targetFieldConfigMap[this.oldFieldName];
|
|
@@ -93,6 +99,13 @@ class HoistField {
|
|
|
93
99
|
}
|
|
94
100
|
}
|
|
95
101
|
newTargetField.args = argsMap;
|
|
102
|
+
if (isList) {
|
|
103
|
+
newTargetField.type = new graphql_1.GraphQLList(newTargetField.type);
|
|
104
|
+
const resolver = newTargetField.resolve;
|
|
105
|
+
newTargetField.resolve = (parent, args, context, info) => Promise.all(Object.keys(parent)
|
|
106
|
+
.filter(key => !key.startsWith('__'))
|
|
107
|
+
.map(key => resolver(parent[key], args, context, info)));
|
|
108
|
+
}
|
|
96
109
|
newSchema = (0, utils_1.appendObjectFields)(newSchema, this.typeName, {
|
|
97
110
|
[this.newFieldName]: newTargetField,
|
|
98
111
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getNullableType, Kind, } from 'graphql';
|
|
1
|
+
import { getNullableType, Kind, isListType, getNamedType, GraphQLList, } from 'graphql';
|
|
2
2
|
import { appendObjectFields, removeObjectFields, relocatedError, } from '@graphql-tools/utils';
|
|
3
3
|
import { defaultMergedResolver } from '@graphql-tools/delegate';
|
|
4
4
|
import { defaultCreateProxyingResolver } from '../generateProxyingResolvers.js';
|
|
@@ -34,6 +34,7 @@ export default class HoistField {
|
|
|
34
34
|
transformSchema(originalWrappingSchema, subschemaConfig) {
|
|
35
35
|
var _a, _b, _c, _d;
|
|
36
36
|
const argsMap = Object.create(null);
|
|
37
|
+
let isList = false;
|
|
37
38
|
const innerType = this.pathToField.reduce((acc, pathSegment, index) => {
|
|
38
39
|
const field = acc.getFields()[pathSegment];
|
|
39
40
|
for (const arg of field.args) {
|
|
@@ -42,7 +43,12 @@ export default class HoistField {
|
|
|
42
43
|
this.argLevels[arg.name] = index;
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
|
-
|
|
46
|
+
const nullableType = getNullableType(field.type);
|
|
47
|
+
if (isListType(nullableType)) {
|
|
48
|
+
isList = true;
|
|
49
|
+
return getNamedType(nullableType);
|
|
50
|
+
}
|
|
51
|
+
return nullableType;
|
|
46
52
|
}, originalWrappingSchema.getType(this.typeName));
|
|
47
53
|
let [newSchema, targetFieldConfigMap] = removeObjectFields(originalWrappingSchema, innerType.name, fieldName => fieldName === this.oldFieldName);
|
|
48
54
|
const targetField = targetFieldConfigMap[this.oldFieldName];
|
|
@@ -89,6 +95,13 @@ export default class HoistField {
|
|
|
89
95
|
}
|
|
90
96
|
}
|
|
91
97
|
newTargetField.args = argsMap;
|
|
98
|
+
if (isList) {
|
|
99
|
+
newTargetField.type = new GraphQLList(newTargetField.type);
|
|
100
|
+
const resolver = newTargetField.resolve;
|
|
101
|
+
newTargetField.resolve = (parent, args, context, info) => Promise.all(Object.keys(parent)
|
|
102
|
+
.filter(key => !key.startsWith('__'))
|
|
103
|
+
.map(key => resolver(parent[key], args, context, info)));
|
|
104
|
+
}
|
|
92
105
|
newSchema = appendObjectFields(newSchema, this.typeName, {
|
|
93
106
|
[this.newFieldName]: newTargetField,
|
|
94
107
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { GraphQLSchema, GraphQLInputFieldConfig } from 'graphql';
|
|
2
2
|
import { ExecutionRequest } from '@graphql-tools/utils';
|
|
3
3
|
import { Transform, DelegationContext, SubschemaConfig } from '@graphql-tools/delegate';
|
|
4
|
-
|
|
4
|
+
type RenamerFunction = (typeName: string, fieldName: string, inputFieldConfig: GraphQLInputFieldConfig) => string | undefined;
|
|
5
5
|
interface RenameInputObjectFieldsTransformationContext extends Record<string, any> {
|
|
6
6
|
}
|
|
7
7
|
export default class RenameInputObjectFields<TContext = Record<string, any>> implements Transform<RenameInputObjectFieldsTransformationContext, TContext> {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { GraphQLSchema, GraphQLInputFieldConfig } from 'graphql';
|
|
2
2
|
import { ExecutionRequest } from '@graphql-tools/utils';
|
|
3
3
|
import { Transform, DelegationContext, SubschemaConfig } from '@graphql-tools/delegate';
|
|
4
|
-
|
|
4
|
+
type RenamerFunction = (typeName: string, fieldName: string, inputFieldConfig: GraphQLInputFieldConfig) => string | undefined;
|
|
5
5
|
interface RenameInputObjectFieldsTransformationContext extends Record<string, any> {
|
|
6
6
|
}
|
|
7
7
|
export default class RenameInputObjectFields<TContext = Record<string, any>> implements Transform<RenameInputObjectFieldsTransformationContext, TContext> {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { GraphQLSchema } from 'graphql';
|
|
2
2
|
import { ExecutionRequest } from '@graphql-tools/utils';
|
|
3
3
|
import { Transform, DelegationContext, SubschemaConfig } from '@graphql-tools/delegate';
|
|
4
|
-
|
|
4
|
+
type RenamerFunction = (typeName: string, fieldName: string, argName: string) => string;
|
|
5
5
|
interface RenameObjectFieldArgumentsTransformationContext extends Record<string, any> {
|
|
6
6
|
}
|
|
7
7
|
export default class RenameObjectFieldArguments<TContext = Record<string, any>> implements Transform<RenameObjectFieldArgumentsTransformationContext, TContext> {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { GraphQLSchema } from 'graphql';
|
|
2
2
|
import { ExecutionRequest } from '@graphql-tools/utils';
|
|
3
3
|
import { Transform, DelegationContext, SubschemaConfig } from '@graphql-tools/delegate';
|
|
4
|
-
|
|
4
|
+
type RenamerFunction = (typeName: string, fieldName: string, argName: string) => string;
|
|
5
5
|
interface RenameObjectFieldArgumentsTransformationContext extends Record<string, any> {
|
|
6
6
|
}
|
|
7
7
|
export default class RenameObjectFieldArguments<TContext = Record<string, any>> implements Transform<RenameObjectFieldArgumentsTransformationContext, TContext> {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { SelectionSetNode, FragmentDefinitionNode } from 'graphql';
|
|
2
2
|
import { ExecutionRequest, ExecutionResult } from '@graphql-tools/utils';
|
|
3
3
|
import { Transform, DelegationContext } from '@graphql-tools/delegate';
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
4
|
+
export type QueryTransformer = <TContext>(selectionSet: SelectionSetNode | undefined, fragments: Record<string, FragmentDefinitionNode>, delegationContext: DelegationContext<TContext>, transformationContext: Record<string, any>) => SelectionSetNode;
|
|
5
|
+
export type ResultTransformer = <TContext>(result: any, delegationContext: DelegationContext<TContext>, transformationContext: Record<string, any>) => any;
|
|
6
|
+
export type ErrorPathTransformer = (path: ReadonlyArray<string | number>) => Array<string | number>;
|
|
7
7
|
interface TransformQueryTransformationContext extends Record<string, any> {
|
|
8
8
|
}
|
|
9
9
|
export default class TransformQuery<TContext = Record<string, any>> implements Transform<TransformQueryTransformationContext, TContext> {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { SelectionSetNode, FragmentDefinitionNode } from 'graphql';
|
|
2
2
|
import { ExecutionRequest, ExecutionResult } from '@graphql-tools/utils';
|
|
3
3
|
import { Transform, DelegationContext } from '@graphql-tools/delegate';
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
4
|
+
export type QueryTransformer = <TContext>(selectionSet: SelectionSetNode | undefined, fragments: Record<string, FragmentDefinitionNode>, delegationContext: DelegationContext<TContext>, transformationContext: Record<string, any>) => SelectionSetNode;
|
|
5
|
+
export type ResultTransformer = <TContext>(result: any, delegationContext: DelegationContext<TContext>, transformationContext: Record<string, any>) => any;
|
|
6
|
+
export type ErrorPathTransformer = (path: ReadonlyArray<string | number>) => Array<string | number>;
|
|
7
7
|
interface TransformQueryTransformationContext extends Record<string, any> {
|
|
8
8
|
}
|
|
9
9
|
export default class TransformQuery<TContext = Record<string, any>> implements Transform<TransformQueryTransformationContext, TContext> {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SelectionNode, SelectionSetNode } from 'graphql';
|
|
2
2
|
import { ExecutionRequest, ExecutionResult } from '@graphql-tools/utils';
|
|
3
3
|
import { Transform, DelegationContext } from '@graphql-tools/delegate';
|
|
4
|
-
export
|
|
4
|
+
export type QueryWrapper = (subtree: SelectionSetNode) => SelectionNode | SelectionSetNode;
|
|
5
5
|
interface WrapQueryTransformationContext extends Record<string, any> {
|
|
6
6
|
}
|
|
7
7
|
export default class WrapQuery<TContext = Record<string, any>> implements Transform<WrapQueryTransformationContext, TContext> {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SelectionNode, SelectionSetNode } from 'graphql';
|
|
2
2
|
import { ExecutionRequest, ExecutionResult } from '@graphql-tools/utils';
|
|
3
3
|
import { Transform, DelegationContext } from '@graphql-tools/delegate';
|
|
4
|
-
export
|
|
4
|
+
export type QueryWrapper = (subtree: SelectionSetNode) => SelectionNode | SelectionSetNode;
|
|
5
5
|
interface WrapQueryTransformationContext extends Record<string, any> {
|
|
6
6
|
}
|
|
7
7
|
export default class WrapQuery<TContext = Record<string, any>> implements Transform<WrapQueryTransformationContext, TContext> {
|
package/typings/types.d.cts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { GraphQLInputFieldConfig, GraphQLFieldConfig, FieldNode, FragmentDefinitionNode, SelectionNode, ObjectFieldNode, ObjectValueNode, GraphQLError, GraphQLEnumValueConfig } from 'graphql';
|
|
2
2
|
import { DelegationContext } from '@graphql-tools/delegate';
|
|
3
3
|
import { ExecutionRequest, Maybe } from '@graphql-tools/utils';
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
export
|
|
4
|
+
export type InputFieldTransformer = (typeName: string, fieldName: string, inputFieldConfig: GraphQLInputFieldConfig) => GraphQLInputFieldConfig | [string, GraphQLInputFieldConfig] | null | undefined;
|
|
5
|
+
export type InputFieldNodeTransformer = <TContext>(typeName: string, fieldName: string, inputFieldNode: ObjectFieldNode, request: ExecutionRequest, delegationContext?: DelegationContext<TContext>) => ObjectFieldNode | Array<ObjectFieldNode>;
|
|
6
|
+
export type InputObjectNodeTransformer = <TContext>(typeName: string, inputObjectNode: ObjectValueNode, request: ExecutionRequest, delegationContext?: DelegationContext<TContext>) => ObjectValueNode | undefined;
|
|
7
|
+
export type FieldTransformer<TContext = Record<string, any>> = (typeName: string, fieldName: string, fieldConfig: GraphQLFieldConfig<any, TContext>) => Maybe<GraphQLFieldConfig<any, TContext> | [string, GraphQLFieldConfig<any, TContext>]>;
|
|
8
|
+
export type RootFieldTransformer<TContext = Record<string, any>> = (operation: 'Query' | 'Mutation' | 'Subscription', fieldName: string, fieldConfig: GraphQLFieldConfig<any, TContext>) => Maybe<GraphQLFieldConfig<any, TContext> | [string, GraphQLFieldConfig<any, TContext>]>;
|
|
9
|
+
export type EnumValueTransformer = (typeName: string, externalValue: string, enumValueConfig: GraphQLEnumValueConfig) => Maybe<GraphQLEnumValueConfig | [string, GraphQLEnumValueConfig]>;
|
|
10
|
+
export type FieldNodeTransformer = (typeName: string, fieldName: string, fieldNode: FieldNode, fragments: Record<string, FragmentDefinitionNode>, transformationContext: Record<string, any>) => Maybe<SelectionNode | Array<SelectionNode>>;
|
|
11
|
+
export type LeafValueTransformer = (typeName: string, value: any) => any;
|
|
12
|
+
export type DataTransformer = (value: any, transformationContext: Record<string, any>) => any;
|
|
13
|
+
export type ObjectValueTransformerMap = Record<string, DataTransformer>;
|
|
14
|
+
export type ErrorsTransformer = (errors: ReadonlyArray<GraphQLError> | undefined, transformationContext: Record<string, any>) => Array<GraphQLError> | undefined;
|
package/typings/types.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { GraphQLInputFieldConfig, GraphQLFieldConfig, FieldNode, FragmentDefinitionNode, SelectionNode, ObjectFieldNode, ObjectValueNode, GraphQLError, GraphQLEnumValueConfig } from 'graphql';
|
|
2
2
|
import { DelegationContext } from '@graphql-tools/delegate';
|
|
3
3
|
import { ExecutionRequest, Maybe } from '@graphql-tools/utils';
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
export
|
|
4
|
+
export type InputFieldTransformer = (typeName: string, fieldName: string, inputFieldConfig: GraphQLInputFieldConfig) => GraphQLInputFieldConfig | [string, GraphQLInputFieldConfig] | null | undefined;
|
|
5
|
+
export type InputFieldNodeTransformer = <TContext>(typeName: string, fieldName: string, inputFieldNode: ObjectFieldNode, request: ExecutionRequest, delegationContext?: DelegationContext<TContext>) => ObjectFieldNode | Array<ObjectFieldNode>;
|
|
6
|
+
export type InputObjectNodeTransformer = <TContext>(typeName: string, inputObjectNode: ObjectValueNode, request: ExecutionRequest, delegationContext?: DelegationContext<TContext>) => ObjectValueNode | undefined;
|
|
7
|
+
export type FieldTransformer<TContext = Record<string, any>> = (typeName: string, fieldName: string, fieldConfig: GraphQLFieldConfig<any, TContext>) => Maybe<GraphQLFieldConfig<any, TContext> | [string, GraphQLFieldConfig<any, TContext>]>;
|
|
8
|
+
export type RootFieldTransformer<TContext = Record<string, any>> = (operation: 'Query' | 'Mutation' | 'Subscription', fieldName: string, fieldConfig: GraphQLFieldConfig<any, TContext>) => Maybe<GraphQLFieldConfig<any, TContext> | [string, GraphQLFieldConfig<any, TContext>]>;
|
|
9
|
+
export type EnumValueTransformer = (typeName: string, externalValue: string, enumValueConfig: GraphQLEnumValueConfig) => Maybe<GraphQLEnumValueConfig | [string, GraphQLEnumValueConfig]>;
|
|
10
|
+
export type FieldNodeTransformer = (typeName: string, fieldName: string, fieldNode: FieldNode, fragments: Record<string, FragmentDefinitionNode>, transformationContext: Record<string, any>) => Maybe<SelectionNode | Array<SelectionNode>>;
|
|
11
|
+
export type LeafValueTransformer = (typeName: string, value: any) => any;
|
|
12
|
+
export type DataTransformer = (value: any, transformationContext: Record<string, any>) => any;
|
|
13
|
+
export type ObjectValueTransformerMap = Record<string, DataTransformer>;
|
|
14
|
+
export type ErrorsTransformer = (errors: ReadonlyArray<GraphQLError> | undefined, transformationContext: Record<string, any>) => Array<GraphQLError> | undefined;
|