Skip to content

Commit c3489b0

Browse files
committed
refactor: internal StitchingInfo properties
to never be undefined
1 parent 8f519da commit c3489b0

3 files changed

Lines changed: 7 additions & 15 deletions

File tree

packages/delegate/src/delegationBindings.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assertSome, Maybe } from '@graphql-tools/utils';
1+
import { Maybe } from '@graphql-tools/utils';
22
import { Transform, StitchingInfo, DelegationContext } from './types';
33

44
import AddSelectionSets from './transforms/AddSelectionSets';
@@ -18,8 +18,6 @@ export function defaultDelegationBinding<TContext>(
1818
const stitchingInfo: Maybe<StitchingInfo> = info?.schema.extensions?.['stitchingInfo'];
1919

2020
if (stitchingInfo != null) {
21-
assertSome(stitchingInfo.selectionSetsByType);
22-
assertSome(stitchingInfo.dynamicSelectionSetsByField);
2321
delegationTransforms = delegationTransforms.concat([
2422
new ExpandAbstractTypes(),
2523
new AddSelectionSets(

packages/delegate/src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,9 @@ export type MergedTypeResolver<TContext = Record<string, any>> = (
188188

189189
export interface StitchingInfo<TContext = Record<string, any>> {
190190
subschemaMap: Map<GraphQLSchema | SubschemaConfig<any, any, any, TContext>, Subschema<any, any, any, TContext>>;
191-
selectionSetsByType: Record<string, SelectionSetNode> | undefined;
191+
selectionSetsByType: Record<string, SelectionSetNode>;
192192
selectionSetsByField: Record<string, Record<string, SelectionSetNode>>;
193-
dynamicSelectionSetsByField: Record<string, Record<string, Array<(node: FieldNode) => SelectionSetNode>>> | undefined;
193+
dynamicSelectionSetsByField: Record<string, Record<string, Array<(node: FieldNode) => SelectionSetNode>>>;
194194
mergedTypes: Record<string, MergedTypeInfo<TContext>>;
195195
}
196196

packages/stitch/src/stitchingInfo.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ export function createStitchingInfo<TContext = Record<string, any>>(
7676

7777
return {
7878
subschemaMap,
79-
selectionSetsByType: undefined,
79+
selectionSetsByType: Object.create(null),
8080
selectionSetsByField,
81-
dynamicSelectionSetsByField: undefined,
81+
dynamicSelectionSetsByField: Object.create(null),
8282
mergedTypes,
8383
};
8484
}
@@ -227,17 +227,15 @@ export function completeStitchingInfo<TContext = Record<string, any>>(
227227
resolvers: IResolvers,
228228
schema: GraphQLSchema
229229
): StitchingInfo<TContext> {
230-
const selectionSetsByType = Object.create(null);
230+
const { selectionSetsByType, selectionSetsByField, dynamicSelectionSetsByField } = stitchingInfo;
231+
231232
const rootTypes = [schema.getQueryType(), schema.getMutationType()];
232233
for (const rootType of rootTypes) {
233234
if (rootType) {
234235
selectionSetsByType[rootType.name] = parseSelectionSet('{ __typename }', { noLocation: true });
235236
}
236237
}
237238

238-
const selectionSetsByField = stitchingInfo.selectionSetsByField;
239-
const dynamicSelectionSetsByField = Object.create(null);
240-
241239
for (const typeName in resolvers) {
242240
const type = resolvers[typeName];
243241
if (isScalarType(type)) {
@@ -288,10 +286,6 @@ export function completeStitchingInfo<TContext = Record<string, any>>(
288286
}
289287
}
290288

291-
stitchingInfo.selectionSetsByType = selectionSetsByType;
292-
stitchingInfo.selectionSetsByField = selectionSetsByField;
293-
stitchingInfo.dynamicSelectionSetsByField = dynamicSelectionSetsByField;
294-
295289
return stitchingInfo;
296290
}
297291

0 commit comments

Comments
 (0)