Skip to content

Commit faa22bb

Browse files
authored
fix(schema): invalid schema contract composition for shared scalars/types (#6850)
1 parent e96f836 commit faa22bb

File tree

4 files changed

+498
-109
lines changed

4 files changed

+498
-109
lines changed

.changeset/long-beds-bow.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'hive': patch
3+
---
4+
5+
Fix issue where contract composition marks types occuring in multiple subgraphs as `@inaccessible`
6+
despite being used within the public API schema.

packages/services/schema/src/composition/__tests__/federation.spec.ts

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,3 +519,78 @@ test('contract: mutation type is part of the public schema if at least one field
519519
}
520520
`);
521521
});
522+
523+
test('contract: scalar is inaccessible, despite being included in at least one subraph', async () => {
524+
const compose = createComposeFederation({
525+
decrypt: () => '',
526+
requestTimeoutMs: Infinity,
527+
});
528+
529+
const sdl2 = /* GraphQL */ `
530+
schema @link(url: "https://specs.apollo.dev/federation/v2.3", import: ["@tag"]) {
531+
query: Query
532+
}
533+
534+
type Query {
535+
field1: Foo!
536+
}
537+
538+
type Foo {
539+
field: Brr @tag(name: "include")
540+
}
541+
542+
scalar Brr @tag(name: "include")
543+
`;
544+
545+
const sdl = /* GraphQL */ `
546+
schema @link(url: "https://specs.apollo.dev/federation/v2.3", import: ["@tag"]) {
547+
query: Query
548+
}
549+
550+
type Query {
551+
c: Int @tag(name: "include")
552+
}
553+
554+
scalar Brr
555+
`;
556+
557+
const result = await compose({
558+
contracts: [
559+
{
560+
filter: {
561+
include: ['include'],
562+
exclude: null,
563+
removeUnreachableTypesFromPublicApiSchema: false,
564+
},
565+
id: '1',
566+
},
567+
],
568+
external: null,
569+
native: true,
570+
requestId: '1',
571+
schemas: [
572+
{
573+
raw: sdl,
574+
source: 'foo.graphql',
575+
url: 'https://lol.de',
576+
},
577+
{
578+
raw: sdl2,
579+
source: 'foo2.graphql',
580+
url: 'https://trolol.de',
581+
},
582+
],
583+
});
584+
expect(result.type).toEqual('success');
585+
const contractResult = result.result.contracts?.at(0);
586+
587+
expect(contractResult?.id).toEqual('1');
588+
expect(contractResult?.result.type).toEqual('success');
589+
590+
const line = contractResult?.result.result.supergraph
591+
?.split('\n')
592+
.find(line => line.includes('scalar Brr'));
593+
expect(line).toEqual(
594+
`scalar Brr @join__type(graph: FOO_GRAPHQL) @join__type(graph: FOO2_GRAPHQL) `,
595+
);
596+
});

0 commit comments

Comments
 (0)