forked from apollographql/federation
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix repeatable custom directives (apollographql#2136)
Composing repeatable custom directives throws an error during composition saying they are not repeatable. This happens because we addDirectivesShallow, but the directive isn't fully created when this check is run. Solved by merging applied directives after all other elements are merged.
- Loading branch information
Showing
11 changed files
with
133 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { | ||
asFed2SubgraphDocument, | ||
buildSchema, | ||
extractSubgraphsFromSupergraph, | ||
Schema, | ||
ServiceDefinition, | ||
Subgraphs | ||
} from '@apollo/federation-internals'; | ||
import { CompositionResult, composeServices, CompositionSuccess } from '../compose'; | ||
|
||
export function assertCompositionSuccess(r: CompositionResult): asserts r is CompositionSuccess { | ||
if (r.errors) { | ||
throw new Error(`Expected composition to succeed but got errors:\n${r.errors.join('\n\n')}`); | ||
} | ||
} | ||
|
||
export function errors(r: CompositionResult): [string, string][] { | ||
return r.errors?.map(e => [e.extensions.code as string, e.message]) ?? []; | ||
} | ||
|
||
// Returns [the supergraph schema, its api schema, the extracted subgraphs] | ||
export function schemas(result: CompositionSuccess): [Schema, Schema, Subgraphs] { | ||
// Note that we could user `result.schema`, but reparsing to ensure we don't lose anything with printing/parsing. | ||
const schema = buildSchema(result.supergraphSdl); | ||
expect(schema.isCoreSchema()).toBeTruthy(); | ||
return [schema, schema.toAPISchema(), extractSubgraphsFromSupergraph(schema)]; | ||
} | ||
|
||
// Note that tests for composition involving fed1 subgraph are in `composeFed1Subgraphs.test.ts` so all the test of this | ||
// file are on fed2 subgraphs, but to avoid needing to add the proper `@link(...)` everytime, we inject it here automatically. | ||
export function composeAsFed2Subgraphs(services: ServiceDefinition[]): CompositionResult { | ||
return composeServices(services.map((s) => asFed2Service(s))); | ||
} | ||
|
||
export function asFed2Service(service: ServiceDefinition): ServiceDefinition { | ||
return { | ||
...service, | ||
typeDefs: asFed2SubgraphDocument(service.typeDefs) | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters