@graphql-tools/stitch 10.1.21 → 10.1.22-alpha-5724fa0d93009d6d0c4b483c028f9d4b729b0682
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/CHANGELOG.md +23 -0
- package/dist/index.cjs +48 -3
- package/dist/index.d.cts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +49 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# @graphql-tools/stitch
|
|
2
2
|
|
|
3
|
+
## 10.1.22-alpha-5724fa0d93009d6d0c4b483c028f9d4b729b0682
|
|
4
|
+
### Patch Changes
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
- [#2401](https://github.com/graphql-hive/gateway/pull/2401) [`cfb89e6`](https://github.com/graphql-hive/gateway/commit/cfb89e6dc7a889c9d20f2a7bf10e447418afa6ab) Thanks [@n1ru4l](https://github.com/n1ru4l)! - Fix `mergeDirectives` option and default it to `true`
|
|
9
|
+
|
|
10
|
+
Custom directive definitions from subschemas were silently dropped from the stitched schema unless `mergeDirectives: true` was explicitly passed to `stitchSchemas`. This meant a schema like:
|
|
11
|
+
|
|
12
|
+
```graphql
|
|
13
|
+
directive @public on SCHEMA | OBJECT | FIELD_DEFINITION
|
|
14
|
+
|
|
15
|
+
type Query @public {
|
|
16
|
+
isAnExample: Boolean @public
|
|
17
|
+
}
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
would stitch into a broken schema where `@public` was used on types and fields but never defined.
|
|
21
|
+
|
|
22
|
+
The default is now `true`, so directive definitions are always collected and retained in the stitched schema, this is the expected behaviour since the merging was partial before this fix (usages got merged, but definitions not).
|
|
23
|
+
|
|
24
|
+
Passing `mergeDirectives: false` now produces a fully clean result - both directive definitions and all their usages on types, fields, input fields, and enum values are stripped.
|
|
25
|
+
|
|
3
26
|
## 10.1.21
|
|
4
27
|
### Patch Changes
|
|
5
28
|
|
package/dist/index.cjs
CHANGED
|
@@ -2770,7 +2770,7 @@ function buildTypeCandidates({
|
|
|
2770
2770
|
parseOptions,
|
|
2771
2771
|
directiveMap,
|
|
2772
2772
|
schemaDefs,
|
|
2773
|
-
mergeDirectives: isMergeDirectives
|
|
2773
|
+
mergeDirectives: isMergeDirectives = true
|
|
2774
2774
|
}) {
|
|
2775
2775
|
const directiveCandidates = new Map(
|
|
2776
2776
|
Object.entries(directiveMap).map(([name, directive]) => [
|
|
@@ -2804,7 +2804,7 @@ function buildTypeCandidates({
|
|
|
2804
2804
|
transformedSubschema: subschema
|
|
2805
2805
|
});
|
|
2806
2806
|
}
|
|
2807
|
-
if (isMergeDirectives
|
|
2807
|
+
if (isMergeDirectives) {
|
|
2808
2808
|
for (const directive of schema.getDirectives()) {
|
|
2809
2809
|
let directiveCandidatesForName = directiveCandidates.get(
|
|
2810
2810
|
directive.name
|
|
@@ -2962,7 +2962,6 @@ function stitchSchemas({
|
|
|
2962
2962
|
types = [],
|
|
2963
2963
|
typeDefs = [],
|
|
2964
2964
|
onTypeConflict,
|
|
2965
|
-
mergeDirectives,
|
|
2966
2965
|
mergeTypes = true,
|
|
2967
2966
|
typeMergingOptions,
|
|
2968
2967
|
subschemaConfigTransforms = [],
|
|
@@ -2973,6 +2972,7 @@ function stitchSchemas({
|
|
|
2973
2972
|
schemaExtensions,
|
|
2974
2973
|
...rest
|
|
2975
2974
|
}) {
|
|
2975
|
+
const mergeDirectives = rest.mergeDirectives ?? true;
|
|
2976
2976
|
const transformedSubschemas = [];
|
|
2977
2977
|
const subschemaMap = /* @__PURE__ */ new Map();
|
|
2978
2978
|
const originalSubschemaMap = /* @__PURE__ */ new Map();
|
|
@@ -3015,6 +3015,9 @@ function stitchSchemas({
|
|
|
3015
3015
|
mergeTypes,
|
|
3016
3016
|
typeMergingOptions
|
|
3017
3017
|
});
|
|
3018
|
+
if (!mergeDirectives) {
|
|
3019
|
+
stripCustomDirectiveUsages(Object.values(newTypeMap));
|
|
3020
|
+
}
|
|
3018
3021
|
let schema$1 = new graphql.GraphQLSchema({
|
|
3019
3022
|
query: newTypeMap[rootTypeNameMap.query],
|
|
3020
3023
|
mutation: newTypeMap[rootTypeNameMap.mutation],
|
|
@@ -3057,6 +3060,48 @@ function stitchSchemas({
|
|
|
3057
3060
|
}
|
|
3058
3061
|
return schema$1;
|
|
3059
3062
|
}
|
|
3063
|
+
function stripCustomDirectiveUsages(types) {
|
|
3064
|
+
const isBuiltin = (d) => graphql.isSpecifiedDirective(
|
|
3065
|
+
// @ts-expect-error it's ok to use just the name, isSpecifiedDirective does the same internally
|
|
3066
|
+
{ name: d.name.value }
|
|
3067
|
+
);
|
|
3068
|
+
for (const type of types) {
|
|
3069
|
+
if (type.astNode?.directives?.length) {
|
|
3070
|
+
type.astNode = {
|
|
3071
|
+
...type.astNode,
|
|
3072
|
+
directives: type.astNode.directives.filter(isBuiltin)
|
|
3073
|
+
};
|
|
3074
|
+
}
|
|
3075
|
+
if (graphql.isObjectType(type) || graphql.isInterfaceType(type)) {
|
|
3076
|
+
for (const field of Object.values(type.getFields())) {
|
|
3077
|
+
if (field.astNode?.directives?.length) {
|
|
3078
|
+
field.astNode = {
|
|
3079
|
+
...field.astNode,
|
|
3080
|
+
directives: field.astNode.directives.filter(isBuiltin)
|
|
3081
|
+
};
|
|
3082
|
+
}
|
|
3083
|
+
}
|
|
3084
|
+
} else if (graphql.isInputObjectType(type)) {
|
|
3085
|
+
for (const field of Object.values(type.getFields())) {
|
|
3086
|
+
if (field.astNode?.directives?.length) {
|
|
3087
|
+
field.astNode = {
|
|
3088
|
+
...field.astNode,
|
|
3089
|
+
directives: field.astNode.directives.filter(isBuiltin)
|
|
3090
|
+
};
|
|
3091
|
+
}
|
|
3092
|
+
}
|
|
3093
|
+
} else if (graphql.isEnumType(type)) {
|
|
3094
|
+
for (const value of type.getValues()) {
|
|
3095
|
+
if (value.astNode?.directives?.length) {
|
|
3096
|
+
value.astNode = {
|
|
3097
|
+
...value.astNode,
|
|
3098
|
+
directives: value.astNode.directives.filter(isBuiltin)
|
|
3099
|
+
};
|
|
3100
|
+
}
|
|
3101
|
+
}
|
|
3102
|
+
}
|
|
3103
|
+
}
|
|
3104
|
+
}
|
|
3060
3105
|
const subschemaConfigTransformerPresets = [isolateComputedFieldsTransformer, splitMergedTypeEntryPointsTransformer];
|
|
3061
3106
|
function applySubschemaConfigTransforms(subschemaConfigTransforms, subschemaOrSubschemaConfig, subschemaMap, originalSubschemaMap) {
|
|
3062
3107
|
let subschemaConfig;
|
package/dist/index.d.cts
CHANGED
|
@@ -35,6 +35,14 @@ interface IStitchSchemasOptions<TContext = Record<string, any>> extends Omit<IEx
|
|
|
35
35
|
typeDefs?: TypeSource;
|
|
36
36
|
types?: Array<GraphQLNamedType>;
|
|
37
37
|
onTypeConflict?: OnTypeConflict<TContext>;
|
|
38
|
+
/**
|
|
39
|
+
* Should directive definitions from all subschemas be collected and included in the stitched schema.
|
|
40
|
+
*
|
|
41
|
+
* When false, custom directive definitions are excluded and their usages are stripped from all type
|
|
42
|
+
* and field AST nodes.
|
|
43
|
+
*
|
|
44
|
+
* @default true
|
|
45
|
+
*/
|
|
38
46
|
mergeDirectives?: boolean | undefined;
|
|
39
47
|
mergeTypes?: boolean | Array<string> | MergeTypeFilter<TContext>;
|
|
40
48
|
typeMergingOptions?: TypeMergingOptions<TContext>;
|
|
@@ -77,7 +85,7 @@ declare module '@graphql-tools/utils' {
|
|
|
77
85
|
}
|
|
78
86
|
}
|
|
79
87
|
|
|
80
|
-
declare function stitchSchemas<TContext extends Record<string, any> = Record<string, any>>({ subschemas, types, typeDefs, onTypeConflict,
|
|
88
|
+
declare function stitchSchemas<TContext extends Record<string, any> = Record<string, any>>({ subschemas, types, typeDefs, onTypeConflict, mergeTypes, typeMergingOptions, subschemaConfigTransforms, resolvers, inheritResolversFromInterfaces, resolverValidationOptions, updateResolversInPlace, schemaExtensions, ...rest }: IStitchSchemasOptions<TContext>): GraphQLSchema;
|
|
81
89
|
|
|
82
90
|
declare function createMergedTypeResolver<TContext extends Record<string, any> = any>(mergedTypeResolverOptions: MergedTypeResolverOptions, mergedType?: GraphQLOutputType | string): MergedTypeResolver<TContext> | undefined;
|
|
83
91
|
|
package/dist/index.d.ts
CHANGED
|
@@ -35,6 +35,14 @@ interface IStitchSchemasOptions<TContext = Record<string, any>> extends Omit<IEx
|
|
|
35
35
|
typeDefs?: TypeSource;
|
|
36
36
|
types?: Array<GraphQLNamedType>;
|
|
37
37
|
onTypeConflict?: OnTypeConflict<TContext>;
|
|
38
|
+
/**
|
|
39
|
+
* Should directive definitions from all subschemas be collected and included in the stitched schema.
|
|
40
|
+
*
|
|
41
|
+
* When false, custom directive definitions are excluded and their usages are stripped from all type
|
|
42
|
+
* and field AST nodes.
|
|
43
|
+
*
|
|
44
|
+
* @default true
|
|
45
|
+
*/
|
|
38
46
|
mergeDirectives?: boolean | undefined;
|
|
39
47
|
mergeTypes?: boolean | Array<string> | MergeTypeFilter<TContext>;
|
|
40
48
|
typeMergingOptions?: TypeMergingOptions<TContext>;
|
|
@@ -77,7 +85,7 @@ declare module '@graphql-tools/utils' {
|
|
|
77
85
|
}
|
|
78
86
|
}
|
|
79
87
|
|
|
80
|
-
declare function stitchSchemas<TContext extends Record<string, any> = Record<string, any>>({ subschemas, types, typeDefs, onTypeConflict,
|
|
88
|
+
declare function stitchSchemas<TContext extends Record<string, any> = Record<string, any>>({ subschemas, types, typeDefs, onTypeConflict, mergeTypes, typeMergingOptions, subschemaConfigTransforms, resolvers, inheritResolversFromInterfaces, resolverValidationOptions, updateResolversInPlace, schemaExtensions, ...rest }: IStitchSchemasOptions<TContext>): GraphQLSchema;
|
|
81
89
|
|
|
82
90
|
declare function createMergedTypeResolver<TContext extends Record<string, any> = any>(mergedTypeResolverOptions: MergedTypeResolverOptions, mergedType?: GraphQLOutputType | string): MergedTypeResolver<TContext> | undefined;
|
|
83
91
|
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { handleOverrideByDelegation, subtractSelectionSets, extractUnavailableFi
|
|
|
2
2
|
import { mergeType, mergeInputType, mergeInterface, mergeUnion, mergeEnum, mergeScalar, mergeTypeDefs, mergeResolvers, mergeExtensions, applyExtensions } from '@graphql-tools/merge';
|
|
3
3
|
import { extendResolversFromInterfaces, addResolversToSchema, assertResolversPresent, makeExecutableSchema } from '@graphql-tools/schema';
|
|
4
4
|
import { collectSubFields, memoize2, memoize1, memoize3, parseSelectionSet, collectFields, isSome, getImplementingTypes, getRootTypeNames, filterSchema, mergeDeep, getDescription, createNamedStub, createStub, getRootTypeMap, getRootTypes, inspect, rewireTypes, getOperationASTFromRequest, getDefinedRootType, getArgumentValues } from '@graphql-tools/utils';
|
|
5
|
-
import { isAbstractType, Kind, TypeNameMetaFieldDef, getNamedType, GraphQLList, isLeafType, isInputObjectType, isUnionType, print, isObjectType, isInterfaceType, visit, isScalarType, isCompositeType, isNonNullType, isEnumType, isListType, getNullableType, isNullableType, GraphQLObjectType, GraphQLInputObjectType, GraphQLInterfaceType, GraphQLUnionType, GraphQLEnumType, GraphQLScalarType, GraphQLDirective, valueFromASTUntyped, getDirectiveValues, GraphQLDeprecatedDirective, DirectiveLocation, isNamedType, isIntrospectionType, isDirective, isSpecifiedScalarType, specifiedDirectives, GraphQLSchema, extendSchema } from 'graphql';
|
|
5
|
+
import { isAbstractType, Kind, TypeNameMetaFieldDef, getNamedType, GraphQLList, isLeafType, isInputObjectType, isUnionType, print, isObjectType, isInterfaceType, visit, isScalarType, isCompositeType, isNonNullType, isEnumType, isListType, getNullableType, isNullableType, GraphQLObjectType, GraphQLInputObjectType, GraphQLInterfaceType, GraphQLUnionType, GraphQLEnumType, GraphQLScalarType, GraphQLDirective, valueFromASTUntyped, getDirectiveValues, GraphQLDeprecatedDirective, DirectiveLocation, isNamedType, isIntrospectionType, isDirective, isSpecifiedScalarType, specifiedDirectives, GraphQLSchema, extendSchema, isSpecifiedDirective } from 'graphql';
|
|
6
6
|
import { handleMaybePromise } from '@whatwg-node/promise-helpers';
|
|
7
7
|
import { batchDelegateToSchema } from '@graphql-tools/batch-delegate';
|
|
8
8
|
import { FilterTypes, TransformCompositeFields, wrapSchema } from '@graphql-tools/wrap';
|
|
@@ -2768,7 +2768,7 @@ function buildTypeCandidates({
|
|
|
2768
2768
|
parseOptions,
|
|
2769
2769
|
directiveMap,
|
|
2770
2770
|
schemaDefs,
|
|
2771
|
-
mergeDirectives: isMergeDirectives
|
|
2771
|
+
mergeDirectives: isMergeDirectives = true
|
|
2772
2772
|
}) {
|
|
2773
2773
|
const directiveCandidates = new Map(
|
|
2774
2774
|
Object.entries(directiveMap).map(([name, directive]) => [
|
|
@@ -2802,7 +2802,7 @@ function buildTypeCandidates({
|
|
|
2802
2802
|
transformedSubschema: subschema
|
|
2803
2803
|
});
|
|
2804
2804
|
}
|
|
2805
|
-
if (isMergeDirectives
|
|
2805
|
+
if (isMergeDirectives) {
|
|
2806
2806
|
for (const directive of schema.getDirectives()) {
|
|
2807
2807
|
let directiveCandidatesForName = directiveCandidates.get(
|
|
2808
2808
|
directive.name
|
|
@@ -2960,7 +2960,6 @@ function stitchSchemas({
|
|
|
2960
2960
|
types = [],
|
|
2961
2961
|
typeDefs = [],
|
|
2962
2962
|
onTypeConflict,
|
|
2963
|
-
mergeDirectives,
|
|
2964
2963
|
mergeTypes = true,
|
|
2965
2964
|
typeMergingOptions,
|
|
2966
2965
|
subschemaConfigTransforms = [],
|
|
@@ -2971,6 +2970,7 @@ function stitchSchemas({
|
|
|
2971
2970
|
schemaExtensions,
|
|
2972
2971
|
...rest
|
|
2973
2972
|
}) {
|
|
2973
|
+
const mergeDirectives = rest.mergeDirectives ?? true;
|
|
2974
2974
|
const transformedSubschemas = [];
|
|
2975
2975
|
const subschemaMap = /* @__PURE__ */ new Map();
|
|
2976
2976
|
const originalSubschemaMap = /* @__PURE__ */ new Map();
|
|
@@ -3013,6 +3013,9 @@ function stitchSchemas({
|
|
|
3013
3013
|
mergeTypes,
|
|
3014
3014
|
typeMergingOptions
|
|
3015
3015
|
});
|
|
3016
|
+
if (!mergeDirectives) {
|
|
3017
|
+
stripCustomDirectiveUsages(Object.values(newTypeMap));
|
|
3018
|
+
}
|
|
3016
3019
|
let schema = new GraphQLSchema({
|
|
3017
3020
|
query: newTypeMap[rootTypeNameMap.query],
|
|
3018
3021
|
mutation: newTypeMap[rootTypeNameMap.mutation],
|
|
@@ -3055,6 +3058,48 @@ function stitchSchemas({
|
|
|
3055
3058
|
}
|
|
3056
3059
|
return schema;
|
|
3057
3060
|
}
|
|
3061
|
+
function stripCustomDirectiveUsages(types) {
|
|
3062
|
+
const isBuiltin = (d) => isSpecifiedDirective(
|
|
3063
|
+
// @ts-expect-error it's ok to use just the name, isSpecifiedDirective does the same internally
|
|
3064
|
+
{ name: d.name.value }
|
|
3065
|
+
);
|
|
3066
|
+
for (const type of types) {
|
|
3067
|
+
if (type.astNode?.directives?.length) {
|
|
3068
|
+
type.astNode = {
|
|
3069
|
+
...type.astNode,
|
|
3070
|
+
directives: type.astNode.directives.filter(isBuiltin)
|
|
3071
|
+
};
|
|
3072
|
+
}
|
|
3073
|
+
if (isObjectType(type) || isInterfaceType(type)) {
|
|
3074
|
+
for (const field of Object.values(type.getFields())) {
|
|
3075
|
+
if (field.astNode?.directives?.length) {
|
|
3076
|
+
field.astNode = {
|
|
3077
|
+
...field.astNode,
|
|
3078
|
+
directives: field.astNode.directives.filter(isBuiltin)
|
|
3079
|
+
};
|
|
3080
|
+
}
|
|
3081
|
+
}
|
|
3082
|
+
} else if (isInputObjectType(type)) {
|
|
3083
|
+
for (const field of Object.values(type.getFields())) {
|
|
3084
|
+
if (field.astNode?.directives?.length) {
|
|
3085
|
+
field.astNode = {
|
|
3086
|
+
...field.astNode,
|
|
3087
|
+
directives: field.astNode.directives.filter(isBuiltin)
|
|
3088
|
+
};
|
|
3089
|
+
}
|
|
3090
|
+
}
|
|
3091
|
+
} else if (isEnumType(type)) {
|
|
3092
|
+
for (const value of type.getValues()) {
|
|
3093
|
+
if (value.astNode?.directives?.length) {
|
|
3094
|
+
value.astNode = {
|
|
3095
|
+
...value.astNode,
|
|
3096
|
+
directives: value.astNode.directives.filter(isBuiltin)
|
|
3097
|
+
};
|
|
3098
|
+
}
|
|
3099
|
+
}
|
|
3100
|
+
}
|
|
3101
|
+
}
|
|
3102
|
+
}
|
|
3058
3103
|
const subschemaConfigTransformerPresets = [isolateComputedFieldsTransformer, splitMergedTypeEntryPointsTransformer];
|
|
3059
3104
|
function applySubschemaConfigTransforms(subschemaConfigTransforms, subschemaOrSubschemaConfig, subschemaMap, originalSubschemaMap) {
|
|
3060
3105
|
let subschemaConfig;
|
package/package.json
CHANGED