Skip to content

Commit 0bf407b

Browse files
authored
🤖 Merge PR DefinitelyTyped#74280 [relay-runtime] : Add missing RelayFeatureFlags with relay-runtime v20.1.1 by @manNomi
1 parent f103e59 commit 0bf407b

File tree

2 files changed

+103
-43
lines changed

2 files changed

+103
-43
lines changed

‎types/relay-runtime/lib/util/RelayFeatureFlags.d.ts‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,28 @@ export interface FeatureFlags {
55
ENABLE_RELAY_RESOLVERS: boolean;
66
ENABLE_GETFRAGMENTIDENTIFIER_OPTIMIZATION: boolean;
77
ENABLE_FRIENDLY_QUERY_NAME_GQL_URL: boolean;
8-
ENABLE_LOAD_QUERY_REQUEST_DEDUPING: boolean;
98
ENABLE_DO_NOT_WRAP_LIVE_QUERY: boolean;
109
ENABLE_NOTIFY_SUBSCRIPTION: boolean;
11-
BATCH_ASYNC_MODULE_UPDATES_FN: null | undefined | ((arg: () => void) => Disposable);
10+
BATCH_ASYNC_MODULE_UPDATES_FN: null | undefined | ((callback: () => void) => Disposable);
1211
ENABLE_CONTAINERS_SUBSCRIBE_ON_COMMIT: boolean;
1312
MAX_DATA_ID_LENGTH: number | null | undefined;
1413
STRING_INTERN_LEVEL: number;
1514
LOG_MISSING_RECORDS_IN_PROD: boolean;
1615
ENABLE_RELAY_OPERATION_TRACKER_SUSPENSE: boolean;
16+
ENABLE_UI_CONTEXT_ON_RELAY_LOGGER: boolean;
17+
ENABLE_NONCOMPLIANT_ERROR_HANDLING_ON_LISTS: boolean;
1718
ENABLE_LOOSE_SUBSCRIPTION_ATTRIBUTION: boolean;
1819
ENABLE_OPERATION_TRACKER_OPTIMISTIC_UPDATES: boolean;
19-
ENABLE_FIELD_ERROR_HANDLING: boolean;
20-
ENABLE_FIELD_ERROR_HANDLING_THROW_BY_DEFAULT: boolean;
21-
ENABLE_FIELD_ERROR_HANDLING_CATCH_DIRECTIVE: boolean;
2220
PROCESS_OPTIMISTIC_UPDATE_BEFORE_SUBSCRIPTION: boolean;
2321
MARK_RESOLVER_VALUES_AS_CLEAN_AFTER_FRAGMENT_REREAD: boolean;
22+
ENABLE_CYLE_DETECTION_IN_VARIABLES: boolean;
23+
ENABLE_ACTIVITY_COMPATIBILITY: boolean;
24+
ENABLE_READ_TIME_RESOLVER_STORAGE_KEY_PREFIX: boolean;
25+
ENABLE_USE_PAGINATION_IS_LOADING_FIX: boolean;
26+
ENABLE_STORE_ID_COLLISION_LOGGING: boolean;
27+
DISALLOW_NESTED_UPDATES: boolean;
28+
ENABLE_TYPENAME_PREFIXED_DATA_ID: boolean;
29+
CHECK_ALL_FRAGMENTS_FOR_MISSING_CLIENT_EDGES: boolean;
2430
}
2531

2632
export const RelayFeatureFlags: FeatureFlags;

‎types/relay-runtime/relay-runtime-tests.tsx‎

Lines changed: 92 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
RecordProxy,
3131
RecordSource,
3232
RecordSourceSelectorProxy,
33+
RelayFeatureFlags,
3334
requestSubscription,
3435
Result,
3536
ROOT_ID,
@@ -105,9 +106,9 @@ const handlerProvider: HandlerProvider = (handle: string) => {
105106
// Augment (or remove from) this list:
106107
case "connection":
107108
return ConnectionHandler;
108-
// case 'viewer':
109-
// // ViewerHandler is special-cased and does not have an `update` method
110-
// return ViewerHandler;
109+
// case 'viewer':
110+
// // ViewerHandler is special-cased and does not have an `update` method
111+
// return ViewerHandler;
111112
case "custom":
112113
return {
113114
update(store, fieldPayload) {
@@ -170,7 +171,7 @@ const environment = new Environment({
170171
kind: "linked",
171172
},
172173
],
173-
log: logEvent => {
174+
log: (logEvent) => {
174175
switch (logEvent.name) {
175176
case "suspense.fragment":
176177
case "suspense.query":
@@ -213,7 +214,7 @@ const environment = new Environment({
213214
break;
214215
}
215216
},
216-
relayFieldLogger: arg => {
217+
relayFieldLogger: (arg) => {
217218
if (arg.kind === "missing_required_field.log") {
218219
console.log(arg.fieldPath, arg.owner);
219220
} else if (arg.kind === "missing_required_field.throw") {
@@ -366,7 +367,7 @@ const get_store_recorditem_typed = store.getSource().get<TConversation>("someDat
366367
// commitLocalUpdate
367368
// ~~~~~~~~~~~~~~~~~~~~~
368369

369-
commitLocalUpdate(environment, store => {
370+
commitLocalUpdate(environment, (store) => {
370371
const root = store.get(ROOT_ID);
371372
root!.setValue("foo", "localKey");
372373
});
@@ -672,11 +673,7 @@ const operationWithCacheConfig = createOperationDescriptor(request, variables, c
672673
const operationWithDataID = createOperationDescriptor(request, variables, undefined, dataID);
673674
const operationWithAll = createOperationDescriptor(request, variables, cacheConfig, dataID);
674675

675-
__internal.fetchQueryDeduped(
676-
environment,
677-
operation.request.identifier,
678-
() => environment.execute({ operation }),
679-
);
676+
__internal.fetchQueryDeduped(environment, operation.request.identifier, () => environment.execute({ operation }));
680677

681678
// ~~~~~~~~~~~~~~~~~~~~~~~
682679
// MULTI ACTOR ENVIRONMENT
@@ -787,7 +784,7 @@ function NonNullableArrayFragmentResolver(usersKey: UserComponent_users$key) {
787784
usersKey,
788785
);
789786

790-
return data.map(thing => `${thing.id}: ${thing.name}, ${thing.profile_picture}`);
787+
return data.map((thing) => `${thing.id}: ${thing.name}, ${thing.profile_picture}`);
791788
}
792789

793790
function NullableArrayFragmentResolver(usersKey: UserComponent_users$key | null) {
@@ -803,7 +800,7 @@ function NullableArrayFragmentResolver(usersKey: UserComponent_users$key | null)
803800
usersKey,
804801
);
805802

806-
return data?.map(thing => `${thing.id}: ${thing.name}, ${thing.profile_picture}`);
803+
return data?.map((thing) => `${thing.id}: ${thing.name}, ${thing.profile_picture}`);
807804
}
808805

809806
function ArrayOfNullableFragmentResolver(usersKey: ReadonlyArray<UserComponent_users$key[0] | null>) {
@@ -819,7 +816,7 @@ function ArrayOfNullableFragmentResolver(usersKey: ReadonlyArray<UserComponent_u
819816
usersKey,
820817
);
821818

822-
return data?.map(thing => `${thing.id}: ${thing.name}, ${thing.profile_picture}`);
819+
return data?.map((thing) => `${thing.id}: ${thing.name}, ${thing.profile_picture}`);
823820
}
824821

825822
// ~~~~~~~~~~~~~~~~~~~~~
@@ -847,10 +844,10 @@ requestSubscription(environment, {
847844
onCompleted: () => {
848845
return;
849846
},
850-
onError: _error => {
847+
onError: (_error) => {
851848
return;
852849
},
853-
onNext: _response => {
850+
onNext: (_response) => {
854851
return;
855852
},
856853
updater: (_store, _data) => {
@@ -881,15 +878,18 @@ ConnectionInterface.inject({
881878
// Provided variables
882879
// ~~~~~~~~~~~~~~~~~~
883880

884-
__internal.withProvidedVariables({
885-
one: "value",
886-
}, {
887-
two: {
888-
get() {
889-
return "value";
881+
__internal.withProvidedVariables(
882+
{
883+
one: "value",
884+
},
885+
{
886+
two: {
887+
get() {
888+
return "value";
889+
},
890890
},
891891
},
892-
});
892+
);
893893

894894
__internal.withProvidedVariables.tests_only_resetDebugCache?.();
895895

@@ -974,7 +974,10 @@ const refetchMetadata: {
974974
// ~~~~~~~~~~~~~~~~~~~
975975

976976
async function waitForFragmentDataTest(userKey: UserComponent_user$key) {
977-
const { name, profile_picture: { uri } } = await waitForFragmentData(
977+
const {
978+
name,
979+
profile_picture: { uri },
980+
} = await waitForFragmentData(
978981
environment,
979982
graphql`
980983
fragment UserComponent_user on User {
@@ -1075,26 +1078,26 @@ function observeQueryTest() {
10751078
// ~~~~~~~~~~~~~~~~~~
10761079

10771080
const MyResolverType__id_graphql: ReaderFragment = {
1078-
"argumentDefinitions": [],
1079-
"kind": "Fragment",
1080-
"metadata": null,
1081-
"name": "MyResolverType__id",
1082-
"selections": [
1081+
argumentDefinitions: [],
1082+
kind: "Fragment",
1083+
metadata: null,
1084+
name: "MyResolverType__id",
1085+
selections: [
10831086
{
1084-
"kind": "ClientExtension",
1085-
"selections": [
1087+
kind: "ClientExtension",
1088+
selections: [
10861089
{
1087-
"alias": null,
1088-
"args": null,
1089-
"kind": "ScalarField",
1090-
"name": "id",
1091-
"storageKey": null,
1090+
alias: null,
1091+
args: null,
1092+
kind: "ScalarField",
1093+
name: "id",
1094+
storageKey: null,
10921095
},
10931096
],
10941097
},
10951098
],
1096-
"type": "MyResolverType",
1097-
"abstractKey": null,
1099+
type: "MyResolverType",
1100+
abstractKey: null,
10981101
};
10991102

11001103
interface MyResolverType {
@@ -1127,3 +1130,54 @@ type AnimalTypenames = "Cat" | "Dog";
11271130
export function myAnimal(): IdOf<"Animal", AnimalTypenames> {
11281131
return Math.random() > 0.5 ? { id: "5", __typename: "Dog" } : { id: "6", __typename: "Cat" };
11291132
}
1133+
1134+
// ~~~~~~~~~~~~~~~~~~
1135+
// RelayFeatureFlags
1136+
// ~~~~~~~~~~~~~~~~~~
1137+
1138+
// Test all existing flags
1139+
// $ExpectType boolean
1140+
const variableConnectionKey = RelayFeatureFlags.ENABLE_VARIABLE_CONNECTION_KEY;
1141+
1142+
// $ExpectType boolean
1143+
const relayResolvers = RelayFeatureFlags.ENABLE_RELAY_RESOLVERS;
1144+
1145+
// $ExpectType boolean
1146+
const uiContext = RelayFeatureFlags.ENABLE_UI_CONTEXT_ON_RELAY_LOGGER;
1147+
1148+
// $ExpectType boolean
1149+
const nonCompliantErrorHandling = RelayFeatureFlags.ENABLE_NONCOMPLIANT_ERROR_HANDLING_ON_LISTS;
1150+
1151+
// $ExpectType boolean
1152+
const cycleDetection = RelayFeatureFlags.ENABLE_CYLE_DETECTION_IN_VARIABLES;
1153+
1154+
// $ExpectType boolean
1155+
const activityCompatibility = RelayFeatureFlags.ENABLE_ACTIVITY_COMPATIBILITY;
1156+
1157+
// $ExpectType boolean
1158+
const readTimeResolverStorageKeyPrefix = RelayFeatureFlags.ENABLE_READ_TIME_RESOLVER_STORAGE_KEY_PREFIX;
1159+
1160+
// $ExpectType boolean
1161+
const usePaginationIsLoadingFix = RelayFeatureFlags.ENABLE_USE_PAGINATION_IS_LOADING_FIX;
1162+
1163+
// $ExpectType boolean
1164+
const storeIdCollisionLogging = RelayFeatureFlags.ENABLE_STORE_ID_COLLISION_LOGGING;
1165+
1166+
// $ExpectType boolean
1167+
const disallowNestedUpdates = RelayFeatureFlags.DISALLOW_NESTED_UPDATES;
1168+
1169+
// $ExpectType boolean
1170+
const typenamePrefixedDataId = RelayFeatureFlags.ENABLE_TYPENAME_PREFIXED_DATA_ID;
1171+
1172+
// $ExpectType boolean
1173+
const checkAllFragments = RelayFeatureFlags.CHECK_ALL_FRAGMENTS_FOR_MISSING_CLIENT_EDGES;
1174+
1175+
// Test that removed flags no longer exist (these should cause type errors)
1176+
// The following flags were removed as they don't exist in relay-runtime v20.1.1:
1177+
// - ENABLE_LOAD_QUERY_REQUEST_DEDUPING
1178+
// - ENABLE_FIELD_ERROR_HANDLING
1179+
// - ENABLE_FIELD_ERROR_HANDLING_THROW_BY_DEFAULT
1180+
// - ENABLE_FIELD_ERROR_HANDLING_CATCH_DIRECTIVE
1181+
// - FILTER_OUT_RELAY_RESOLVER_RECORDS
1182+
// - OPTIMIZE_NOTIFY
1183+
// - ENABLE_READER_FRAGMENTS_LOGGING

0 commit comments

Comments
 (0)