Skip to content

Commit

Permalink
Merge pull request #3069 from apollographql/benjamn/sparse-map-mergeT…
Browse files Browse the repository at this point in the history
…ype-sources

Use sparse `Map`s rather than dense `sources` arrays in `mergeType` code.
  • Loading branch information
sachindshinde authored Jul 8, 2024
2 parents 38debcf + f5f6a79 commit 3dff8a3
Show file tree
Hide file tree
Showing 4 changed files with 431 additions and 195 deletions.
5 changes: 5 additions & 0 deletions .changeset/smooth-melons-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@apollo/composition": patch
---

Type merging now uses maps instead of sparsely-populated arrays for per-subgraph data.
5 changes: 3 additions & 2 deletions composition-js/src/composeDirectiveManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import { GraphQLError } from 'graphql';
import { CompositionHint, HINTS } from './hints';
import { MismatchReporter } from './merging/reporter';
import { sourcesFromArray } from './merging';

/**
* Return true if the directive from the same core feature has a different name in the subgraph
Expand Down Expand Up @@ -367,7 +368,7 @@ export class ComposeDirectiveManager {
this.mismatchReporter.reportMismatchErrorWithoutSupergraph(
ERRORS.DIRECTIVE_COMPOSITION_ERROR,
'Composed directive is not named consistently in all subgraphs',
this.subgraphs.values()
sourcesFromArray(this.subgraphs.values()
.map(sg => {
const item = items.find(item => sg.name === item.sgName);
return item ? {
Expand All @@ -384,7 +385,7 @@ export class ComposeDirectiveManager {
sourceAST,
item: val.item,
} : undefined;
}),
})),
(elt) => elt ? `"@${elt.item.directiveNameAs}"` : undefined
);
}
Expand Down
Loading

0 comments on commit 3dff8a3

Please sign in to comment.