Skip to content

Commit a107ad3

Browse files
authored
fix: failing composition for contract schemas (#6685)
1 parent 0e05049 commit a107ad3

File tree

3 files changed

+53
-16
lines changed

3 files changed

+53
-16
lines changed

.changeset/dull-goats-brush.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'hive': patch
3+
---
4+
5+
Fix failing schema contract composition.

integration-tests/tests/schema/contracts.spec.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,3 +348,47 @@ test('failed contract composition has errors and no sdl and supergraph', async (
348348
expect(result.contracts?.[0].supergraph).toEqual(null);
349349
expect(result.contracts?.[0].errors).toBeDefined();
350350
});
351+
352+
test('type is marked as inaccessible if all fields are inaccessible and the type is not used', async () => {
353+
const result = await client.composeAndValidate.mutate({
354+
type: 'federation',
355+
native: true,
356+
schemas: [
357+
{
358+
raw: /* GraphQL */ `
359+
extend schema
360+
@link(url: "https://specs.apollo.dev/link/v1.0")
361+
@link(url: "https://specs.apollo.dev/federation/v2.8", import: ["@tag"])
362+
363+
type Query {
364+
hello: String @tag(name: "public")
365+
}
366+
367+
type Brr {
368+
a: String
369+
b: String
370+
c: String
371+
}
372+
`,
373+
source: 'foo.graphql',
374+
url: null,
375+
},
376+
],
377+
external: null,
378+
contracts: [
379+
{
380+
id: 'foo',
381+
filter: {
382+
removeUnreachableTypesFromPublicApiSchema: true,
383+
exclude: null,
384+
include: ['public'],
385+
},
386+
},
387+
],
388+
});
389+
390+
expect(result.contracts?.[0].errors).toEqual([]);
391+
expect(result.contracts?.[0].supergraph).toContain(
392+
'type Brr @join__type(graph: FOO_GRAPHQL) @inaccessible {',
393+
);
394+
});

packages/services/schema/src/orchestrators.ts

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ import {
3131
} from './lib/compose';
3232
import { CompositionErrorSource, errorWithSource, toValidationError } from './lib/errors';
3333
import {
34-
applyTagFilterToInaccessibleTransformOnSubgraphSchema,
34+
applyTagFilterOnSubgraphs,
3535
createTagDirectiveNameExtractionStrategy,
3636
extractTagsFromDocument,
37-
Federation2SubgraphDocumentNodeByTagsFilter,
3837
} from './lib/federation-tag-extraction';
3938
import { extractMetadata, mergeMetadata } from './lib/metadata-extraction';
4039
import { SetMap } from './lib/setmap';
@@ -348,20 +347,9 @@ const createFederation: (
348347
const contractResults = await Promise.all(
349348
contracts.map(async contract => {
350349
// apply contracts to replace tags with inaccessible directives
351-
const filteredSubgraphs = subgraphs.map(subgraph => {
352-
const filter: Federation2SubgraphDocumentNodeByTagsFilter = {
353-
include: new Set(contract.filter.include),
354-
exclude: new Set(contract.filter.exclude),
355-
};
356-
const filteredSubgraph = applyTagFilterToInaccessibleTransformOnSubgraphSchema(
357-
subgraph.typeDefs,
358-
filter,
359-
);
360-
return {
361-
// @note Although it can differ from the supergraph's, ignore metadata on contracts.
362-
...subgraph,
363-
typeDefs: filteredSubgraph.typeDefs,
364-
};
350+
const filteredSubgraphs = applyTagFilterOnSubgraphs(subgraphs, {
351+
include: new Set(contract.filter.include),
352+
exclude: new Set(contract.filter.exclude),
365353
});
366354

367355
// attempt to compose the contract filtered subgraph

0 commit comments

Comments
 (0)