Skip to content

Commit 8bb88f9

Browse files
authored
fix(composition): preserve user-defined _service fields (#3442)
`ignoreParsedField` was stripping any field named `_service` or `_entities` from all types during fed1 schema parsing, but should only strip them from the `Query` root type where they are federation built-in operations.
1 parent 6215687 commit 8bb88f9

3 files changed

Lines changed: 39 additions & 0 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@apollo/federation-internals": patch
3+
---
4+
5+
Preserve user-defined `_service` fields
6+
7+
`ignoreParsedField` was stripping any field named `_service` or `_entities` from all types during fed1 schema parsing, but should only strip them from the Query root type where they are federation built-in operations.

composition-js/src/__tests__/composeFed1Subgraphs.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,3 +795,32 @@ describe('override', () => {
795795
assertCompositionSuccess(result);
796796
});
797797
});
798+
799+
describe('user-defined fields named like federation built-ins', () => {
800+
it('preserves _service field on non-Query types', () => {
801+
const subgraphA = {
802+
typeDefs: gql`
803+
type Query {
804+
product: Product
805+
}
806+
807+
type Product @key(fields: "id") {
808+
id: ID!
809+
_service: ProductService
810+
}
811+
812+
type ProductService {
813+
name: String
814+
}
815+
`,
816+
name: 'subgraphA',
817+
};
818+
819+
const result = composeServices([subgraphA]);
820+
assertCompositionSuccess(result);
821+
822+
const [_, api] = schemas(result);
823+
const printed = printSchema(api);
824+
expect(printed).toContain('_service: ProductService');
825+
});
826+
});

internals-js/src/federation.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,6 +1567,9 @@ export class FederationBlueprint extends SchemaBlueprint {
15671567
if (!FEDERATION_OPERATION_FIELDS.includes(fieldName)) {
15681568
return false;
15691569
}
1570+
if (!isObjectType(type) || !type.isQueryRootType()) {
1571+
return false;
1572+
}
15701573
const metadata = federationMetadata(type.schema());
15711574
return !!metadata && !metadata.isFed2Schema();
15721575
}

0 commit comments

Comments
 (0)