Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/dull-goats-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'hive': patch
---

Fix failing schema contract composition.
44 changes: 44 additions & 0 deletions integration-tests/tests/schema/contracts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,47 @@ test('failed contract composition has errors and no sdl and supergraph', async (
expect(result.contracts?.[0].supergraph).toEqual(null);
expect(result.contracts?.[0].errors).toBeDefined();
});

test('type is marked as inaccessible if all fields are inaccessible and the type is not used', async () => {
const result = await client.composeAndValidate.mutate({
type: 'federation',
native: true,
schemas: [
{
raw: /* GraphQL */ `
extend schema
@link(url: "https://specs.apollo.dev/link/v1.0")
@link(url: "https://specs.apollo.dev/federation/v2.8", import: ["@tag"])

type Query {
hello: String @tag(name: "public")
}

type Brr {
a: String
b: String
c: String
}
`,
source: 'foo.graphql',
url: null,
},
],
external: null,
contracts: [
{
id: 'foo',
filter: {
removeUnreachableTypesFromPublicApiSchema: true,
exclude: null,
include: ['public'],
},
},
],
});

expect(result.contracts?.[0].errors).toEqual([]);
expect(result.contracts?.[0].supergraph).toContain(
'type Brr @join__type(graph: FOO_GRAPHQL) @inaccessible {',
);
});
20 changes: 4 additions & 16 deletions packages/services/schema/src/orchestrators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ import {
} from './lib/compose';
import { CompositionErrorSource, errorWithSource, toValidationError } from './lib/errors';
import {
applyTagFilterToInaccessibleTransformOnSubgraphSchema,
applyTagFilterOnSubgraphs,
createTagDirectiveNameExtractionStrategy,
extractTagsFromDocument,
Federation2SubgraphDocumentNodeByTagsFilter,
} from './lib/federation-tag-extraction';
import { extractMetadata, mergeMetadata } from './lib/metadata-extraction';
import { SetMap } from './lib/setmap';
Expand Down Expand Up @@ -348,20 +347,9 @@ const createFederation: (
const contractResults = await Promise.all(
contracts.map(async contract => {
// apply contracts to replace tags with inaccessible directives
const filteredSubgraphs = subgraphs.map(subgraph => {
const filter: Federation2SubgraphDocumentNodeByTagsFilter = {
include: new Set(contract.filter.include),
exclude: new Set(contract.filter.exclude),
};
const filteredSubgraph = applyTagFilterToInaccessibleTransformOnSubgraphSchema(
subgraph.typeDefs,
filter,
);
return {
// @note Although it can differ from the supergraph's, ignore metadata on contracts.
...subgraph,
typeDefs: filteredSubgraph.typeDefs,
};
const filteredSubgraphs = applyTagFilterOnSubgraphs(subgraphs, {
include: new Set(contract.filter.include),
exclude: new Set(contract.filter.exclude),
});

// attempt to compose the contract filtered subgraph
Expand Down
Loading