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/dirty-humans-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@theguild/federation-composition": patch
---

tag extraction respects @external on parent
38 changes: 19 additions & 19 deletions __tests__/composition.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7382,25 +7382,25 @@ testImplementations((api) => {
typeDefs: parse(/* GraphQL */ `
extend schema
@link(
url: "https://specs.apollo.dev/federation/v2.3"
import: ["@key", "@shareable"]
url: "https://specs.apollo.dev/federation/v2.3"
import: ["@key", "@shareable"]
)
type Note @key(fields: "id") @shareable {
id: ID!
name: String
author: User
}
type User @key(fields: "id") {
id: ID!
name: String
id: ID!
name: String
}
type PrivateNote @key(fields: "id") @shareable {
id: ID!
note: Note
}
type Query {
note: Note @shareable
privateNote: PrivateNote @shareable
type PrivateNote @key(fields: "id") @shareable {
id: ID!
note: Note
}
type Query {
note: Note @shareable
privateNote: PrivateNote @shareable
}
`),
},
Expand All @@ -7425,9 +7425,9 @@ testImplementations((api) => {
result = api.composeServices([
{
name: "foo",
typeDefs: parse(/* GraphQL */ `
typeDefs: parse(/* GraphQL */ `
extend schema
@link(
@link(
url: "https://specs.apollo.dev/federation/v2.3"
import: ["@key", "@external", "@provides", "@shareable"]
)
Expand All @@ -7442,8 +7442,8 @@ testImplementations((api) => {
type PrivateNote @key(fields: "id") @shareable {
id: ID!
note: Note @provides(fields: "name author { id }")
}
type Query {
}
type Query {
note: Note @shareable
privateNote: PrivateNote @shareable
}
Expand All @@ -7461,8 +7461,8 @@ testImplementations((api) => {
id: ID!
name: String
author: User
}
type User @key(fields: "id") {
}
type User @key(fields: "id") {
id: ID!
name: String
}
Expand Down Expand Up @@ -7490,7 +7490,7 @@ testImplementations((api) => {
type Note @key(fields: "id") @shareable {
id: ID!
tag: String
}
}
`),
},
]);
Expand All @@ -7510,7 +7510,7 @@ testImplementations((api) => {
@join__field(external: true, graph: FOO)
@join__field(graph: BAR)
tag: String @join__field(graph: BAZ)
}
}
`);
});

Expand Down
82 changes: 82 additions & 0 deletions __tests__/contracts/federation-tag-extraction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,88 @@ describe("applyTagFilterToInaccessibleTransformOnSubgraphSchema", () => {
`);
});

test("include of object type field if @external is applied to field", () => {
const filter: SchemaContractFilter = {
include: new Set(["tag1"]),
exclude: new Set(),
};
const sdl = parse(/* GraphQL */ `
schema
@link(
url: "https://specs.apollo.dev/federation/v2.0"
import: ["@tag", "@external"]
) {
query: Query
}

type Query {
field1: String! @tag(name: "tag1") @requires(fields: "field2")
field2: String! @external
}
`);

const output = applyTagFilterToInaccessibleTransformOnSubgraphSchema(
sdl,
buildSchemaCoordinateTagRegister([sdl]),
filter,
);

expect(print(output.typeDefs)).toMatchInlineSnapshot(`
"schema @link(url: "https://specs.apollo.dev/federation/v2.0", import: ["@tag", "@external"]) {
query: Query
}

type Query {
field1: String! @requires(fields: "field2")
field2: String! @external
}"
`);
});

test("include of object type field if @external is applied to object", () => {
const filter: SchemaContractFilter = {
include: new Set(["tag1"]),
exclude: new Set(),
};
const sdl = parse(/* GraphQL */ `
schema
@link(
url: "https://specs.apollo.dev/federation/v2.0"
import: ["@tag", "@external"]
) {
query: Query
}

extend type Query @external {
field2: String!
}

type Query {
field1: String! @tag(name: "tag1") @requires(fields: "field2")
}
`);

const output = applyTagFilterToInaccessibleTransformOnSubgraphSchema(
sdl,
buildSchemaCoordinateTagRegister([sdl]),
filter,
);

expect(print(output.typeDefs)).toMatchInlineSnapshot(`
"schema @link(url: "https://specs.apollo.dev/federation/v2.0", import: ["@tag", "@external"]) {
query: Query
}

extend type Query @external {
field2: String!
}

type Query {
field1: String! @requires(fields: "field2")
}"
`);
});

test("object type is excluded even if one of its fields is included", () => {
const filter: SchemaContractFilter = {
include: new Set(["tag1"]),
Expand Down
3 changes: 2 additions & 1 deletion src/contracts/tag-extraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,8 @@ export function applyTagFilterToInaccessibleTransformOnSubgraphSchema(
if (
fieldNode.directives?.find(
(d) => d.name.value === externalDirectiveName,
)
) ||
node.directives?.find((d) => d.name.value === externalDirectiveName)
) {
return fieldNode;
}
Expand Down