Skip to content

Commit 5f4bb16

Browse files
authored
Don't ever add @Shareable to subscription fields during schema upgrading (#3094)
It could be valid to have two fields of the same that are not shareable if one of them is being overridden. Don't add @sharable to subscription fields and just let it be a composition error if neither are overrides. As @Shareable is not allowed on a subscription field, they should never exist there in any case.
1 parent 4658fea commit 5f4bb16

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

.changeset/nice-dogs-walk.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@apollo/federation-internals": patch
3+
---
4+
5+
When auto-upgrading schemas from fed1, never add @shareable on subscription fields.

internals-js/src/__tests__/schemaUpgrader.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,3 +325,43 @@ test("fully upgrades a schema with no @link directive", () => {
325325
}`
326326
);
327327
});
328+
329+
test("don't add @shareable to subscriptions", () => {
330+
const subgraph1 = buildSubgraph(
331+
"subgraph1",
332+
"",
333+
`#graphql
334+
type Query {
335+
hello: String
336+
}
337+
338+
type Subscription {
339+
update: String!
340+
}
341+
`
342+
);
343+
344+
const subgraph2 = buildSubgraph(
345+
"subgraph2",
346+
"",
347+
`#graphql
348+
type Query {
349+
hello: String
350+
}
351+
352+
type Subscription {
353+
update: String!
354+
}
355+
`
356+
);
357+
const subgraphs = new Subgraphs();
358+
subgraphs.add(subgraph1);
359+
subgraphs.add(subgraph2);
360+
const result = upgradeSubgraphsIfNecessary(subgraphs);
361+
362+
expect(printSchema(result.subgraphs!.get("subgraph1")!.schema!)).not.toContain('update: String! @shareable');
363+
expect(printSchema(result.subgraphs!.get("subgraph2")!.schema!)).not.toContain('update: String! @shareable');
364+
365+
expect(result.subgraphs!.get("subgraph1")!.schema.type('Subscription')?.appliedDirectivesOf('@shareable').length).toBe(0);
366+
expect(result.subgraphs!.get("subgraph2")!.schema.type('Subscription')?.appliedDirectivesOf('@shareable').length).toBe(0);
367+
});

internals-js/src/schemaUpgrader.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,10 @@ class SchemaUpgrader {
714714
// - to every "value type" (in the fed1 sense of non-root type and non-entity) if it is used in any other subgraphs
715715
// - to any (non-external) field of an entity/root-type that is not a key field and if another subgraphs resolve it (fully or partially through @provides)
716716
for (const type of this.schema.objectTypes()) {
717-
if (type.hasAppliedDirective(keyDirective) || type.isRootType()) {
717+
if(type.isSubscriptionRootType()) {
718+
continue;
719+
}
720+
if (type.hasAppliedDirective(keyDirective) || (type.isRootType())) {
718721
for (const field of type.fields()) {
719722
// To know if the field is a "key" field which doesn't need shareable, we rely on whether the field is shareable in the original
720723
// schema (the fed1 version), because as fed1 schema will have no @shareable, the key fields will effectively be the only field

0 commit comments

Comments
 (0)