Skip to content

Commit

Permalink
refactor: internal StitchingInfo properties
Browse files Browse the repository at this point in the history
to never be undefined
  • Loading branch information
yaacovCR committed Jul 6, 2021
1 parent 8f519da commit c3489b0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
4 changes: 1 addition & 3 deletions packages/delegate/src/delegationBindings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertSome, Maybe } from '@graphql-tools/utils';
import { Maybe } from '@graphql-tools/utils';
import { Transform, StitchingInfo, DelegationContext } from './types';

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

if (stitchingInfo != null) {
assertSome(stitchingInfo.selectionSetsByType);
assertSome(stitchingInfo.dynamicSelectionSetsByField);
delegationTransforms = delegationTransforms.concat([
new ExpandAbstractTypes(),
new AddSelectionSets(
Expand Down
4 changes: 2 additions & 2 deletions packages/delegate/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ export type MergedTypeResolver<TContext = Record<string, any>> = (

export interface StitchingInfo<TContext = Record<string, any>> {
subschemaMap: Map<GraphQLSchema | SubschemaConfig<any, any, any, TContext>, Subschema<any, any, any, TContext>>;
selectionSetsByType: Record<string, SelectionSetNode> | undefined;
selectionSetsByType: Record<string, SelectionSetNode>;
selectionSetsByField: Record<string, Record<string, SelectionSetNode>>;
dynamicSelectionSetsByField: Record<string, Record<string, Array<(node: FieldNode) => SelectionSetNode>>> | undefined;
dynamicSelectionSetsByField: Record<string, Record<string, Array<(node: FieldNode) => SelectionSetNode>>>;
mergedTypes: Record<string, MergedTypeInfo<TContext>>;
}

Expand Down
14 changes: 4 additions & 10 deletions packages/stitch/src/stitchingInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ export function createStitchingInfo<TContext = Record<string, any>>(

return {
subschemaMap,
selectionSetsByType: undefined,
selectionSetsByType: Object.create(null),
selectionSetsByField,
dynamicSelectionSetsByField: undefined,
dynamicSelectionSetsByField: Object.create(null),
mergedTypes,
};
}
Expand Down Expand Up @@ -227,17 +227,15 @@ export function completeStitchingInfo<TContext = Record<string, any>>(
resolvers: IResolvers,
schema: GraphQLSchema
): StitchingInfo<TContext> {
const selectionSetsByType = Object.create(null);
const { selectionSetsByType, selectionSetsByField, dynamicSelectionSetsByField } = stitchingInfo;

const rootTypes = [schema.getQueryType(), schema.getMutationType()];
for (const rootType of rootTypes) {
if (rootType) {
selectionSetsByType[rootType.name] = parseSelectionSet('{ __typename }', { noLocation: true });
}
}

const selectionSetsByField = stitchingInfo.selectionSetsByField;
const dynamicSelectionSetsByField = Object.create(null);

for (const typeName in resolvers) {
const type = resolvers[typeName];
if (isScalarType(type)) {
Expand Down Expand Up @@ -288,10 +286,6 @@ export function completeStitchingInfo<TContext = Record<string, any>>(
}
}

stitchingInfo.selectionSetsByType = selectionSetsByType;
stitchingInfo.selectionSetsByField = selectionSetsByField;
stitchingInfo.dynamicSelectionSetsByField = dynamicSelectionSetsByField;

return stitchingInfo;
}

Expand Down

0 comments on commit c3489b0

Please sign in to comment.