You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Refine composition hints for progressive @override (#2922)
Composition hints w.r.t. `@override` usage don't _quite_ apply now that
fields could be in a "in migration" state when progressive `@override`
is in use.
This change introduces a different hint for progressive `@override`
usage which advises completing the migration before suggesting the
removal of the original field.
Copy file name to clipboardExpand all lines: composition-js/src/__tests__/hints.test.ts
+58
Original file line number
Diff line number
Diff line change
@@ -900,6 +900,64 @@ describe('hint tests related to the @override directive', () => {
900
900
'T.id'
901
901
);
902
902
});
903
+
904
+
it('hint when progressive @override migration is in progress',()=>{
905
+
constsubgraph1=gql`
906
+
type Query {
907
+
a: Int
908
+
}
909
+
910
+
type T @key(fields: "id"){
911
+
id: Int
912
+
f: Int @override(from: "Subgraph2", label: "percent(1)")
913
+
}
914
+
`;
915
+
916
+
constsubgraph2=gql`
917
+
type T @key(fields: "id"){
918
+
id: Int
919
+
f: Int
920
+
}
921
+
`;
922
+
constresult=mergeDocuments(subgraph1,subgraph2);
923
+
924
+
// We don't want to see the related hint for non-progressive overrides that
925
+
// suggest removing the original field.
926
+
expect(result.hints).toHaveLength(1);
927
+
expect(result).toRaiseHint(
928
+
HINTS.OVERRIDE_MIGRATION_IN_PROGRESS,
929
+
`Field "T.f" is currently being migrated with progressive @override. Once the migration is complete, remove the field from subgraph "Subgraph2".`,
930
+
'T.f',
931
+
);
932
+
});
933
+
934
+
it('hint when progressive @override migration is in progress (for a referenced field)',()=>{
935
+
constsubgraph1=gql`
936
+
type Query {
937
+
a: Int
938
+
}
939
+
940
+
type T @key(fields: "id"){
941
+
id: Int @override(from: "Subgraph2", label: "percent(1)")
942
+
}
943
+
`;
944
+
945
+
constsubgraph2=gql`
946
+
type T @key(fields: "id"){
947
+
id: Int
948
+
}
949
+
`;
950
+
constresult=mergeDocuments(subgraph1,subgraph2);
951
+
952
+
// We don't want to see the related hint for non-progressive overrides that
953
+
// suggest removing the original field.
954
+
expect(result.hints).toHaveLength(1);
955
+
expect(result).toRaiseHint(
956
+
HINTS.OVERRIDE_MIGRATION_IN_PROGRESS,
957
+
`Field "T.id" on subgraph "Subgraph2" is currently being migrated via progressive @override. It is still used in some federation directive(s) (@key, @requires, and/or @provides) and/or to satisfy interface constraint(s). Once the migration is complete, consider marking it @external explicitly or removing it along with its references.`,
958
+
'T.id'
959
+
);
960
+
});
903
961
});
904
962
905
963
describe('on non-repeatable directives used with incompatible arguments',()=>{
description: 'Field is currently being migrated with progressive @override. Once the migration is complete, remove the field from the original subgraph.',
`Field "${dest.coordinate}" on subgraph "${sourceSubgraphName}" is overridden. It is still used in some federation directive(s) (@key, @requires, and/or @provides) and/or to satisfy interface constraint(s), but consider marking it @external explicitly or removing it along with its references.`,
1321
-
dest,
1322
-
overriddenSubgraphASTNode,
1323
-
));
1320
+
if(!overrideLabel){
1321
+
this.hints.push(newCompositionHint(
1322
+
HINTS.OVERRIDDEN_FIELD_CAN_BE_REMOVED,
1323
+
`Field "${dest.coordinate}" on subgraph "${sourceSubgraphName}" is overridden. It is still used in some federation directive(s) (@key, @requires, and/or @provides) and/or to satisfy interface constraint(s), but consider marking it @external explicitly or removing it along with its references.`,
1324
+
dest,
1325
+
overriddenSubgraphASTNode,
1326
+
)
1327
+
);
1328
+
}
1324
1329
}else{
1325
1330
result.setUnusedOverridden(fromIdx);
1326
-
this.hints.push(newCompositionHint(
1327
-
HINTS.OVERRIDDEN_FIELD_CAN_BE_REMOVED,
1328
-
`Field "${dest.coordinate}" on subgraph "${sourceSubgraphName}" is overridden. Consider removing it.`,
1329
-
dest,
1330
-
overriddenSubgraphASTNode,
1331
-
));
1331
+
if(!overrideLabel){
1332
+
this.hints.push(newCompositionHint(
1333
+
HINTS.OVERRIDDEN_FIELD_CAN_BE_REMOVED,
1334
+
`Field "${dest.coordinate}" on subgraph "${sourceSubgraphName}" is overridden. Consider removing it.`,
// Enforce that the label matches the following pattern: percent(x)
@@ -1358,6 +1364,17 @@ class Merger {
1358
1364
{nodes: overridingSubgraphASTNode}
1359
1365
));
1360
1366
}
1367
+
1368
+
constmessage=overriddenFieldIsReferenced
1369
+
? `Field "${dest.coordinate}" on subgraph "${sourceSubgraphName}" is currently being migrated via progressive @override. It is still used in some federation directive(s) (@key, @requires, and/or @provides) and/or to satisfy interface constraint(s). Once the migration is complete, consider marking it @external explicitly or removing it along with its references.`
1370
+
: `Field "${dest.coordinate}" is currently being migrated with progressive @override. Once the migration is complete, remove the field from subgraph "${sourceSubgraphName}".`;
0 commit comments