Skip to content

Commit e77cae6

Browse files
SamChou19815facebook-github-bot
authored andcommitted
Make many relay object types readonly or annotate objects to prevent future flow errors after object literal soundness fix: 2/n
Reviewed By: marcoww6 Differential Revision: D76989506 fbshipit-source-id: 3742260c46bd24b2176d9794493f619e26562ae0
1 parent 48e3351 commit e77cae6

File tree

8 files changed

+32
-24
lines changed

8 files changed

+32
-24
lines changed

packages/react-relay/__tests__/ReactRelayTestMocker-test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
'use strict';
1313
import type {RelayMockEnvironment} from '../../relay-test-utils/RelayModernMockEnvironment';
1414
import type {NetworkWriteConfig} from '../ReactRelayTestMocker';
15+
import type {GeneratedNodeMap} from '../ReactRelayTypes';
1516

1617
const RelayTestRenderer = require('../__mocks__/RelayTestRenderer');
1718
const {
@@ -47,7 +48,7 @@ const ReactRelayTestMockerTestNestedQuery = graphql`
4748
}
4849
}
4950
`;
50-
const ReactRelayTestMockerTest_meFragmentDefinition = {
51+
const ReactRelayTestMockerTest_meFragmentDefinition: GeneratedNodeMap = {
5152
me: graphql`
5253
fragment ReactRelayTestMockerTest_me on User {
5354
name

packages/react-relay/relay-hooks/EntryPointTypes.flow.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,6 @@ export type EntryPoint<TEntryPointParams, +TEntryPointComponent> =
293293

294294
export type PreloadParamsOf<T> = Parameters<T['getPreloadProps']>[0];
295295

296-
export type IEnvironmentProvider<TOptions> = {
296+
export type IEnvironmentProvider<TOptions> = $ReadOnly<{
297297
getEnvironment: (options: ?TOptions) => IEnvironment,
298-
};
298+
}>;

packages/react-relay/relay-hooks/__tests__/useSubscribeToInvalidationState-test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
*/
1111

1212
'use strict';
13+
1314
import type {RelayMockEnvironment} from '../../../relay-test-utils/RelayModernMockEnvironment';
15+
import type {RecordSourceJSON} from 'relay-runtime/store/RelayStoreTypes';
1416

1517
const RelayEnvironmentProvider = require('../RelayEnvironmentProvider');
1618
const useSubscribeToInvalidationState = require('../useSubscribeToInvalidationState');
@@ -27,7 +29,7 @@ let setDataIDs;
2729
let setCallback;
2830
let disposable;
2931
let renderedInstance;
30-
let data;
32+
let data: RecordSourceJSON;
3133
let callback;
3234

3335
beforeEach(() => {

packages/relay-runtime/mutations/commitMutation.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const validateMutation = require('./validateMutation');
3737
const invariant = require('invariant');
3838
const warning = require('warning');
3939

40-
export type MutationConfig<TMutation: MutationParameters> = {
40+
export type MutationConfig<TMutation: MutationParameters> = $ReadOnly<{
4141
cacheConfig?: CacheConfig,
4242
configs?: Array<DeclarativeMutationConfig>,
4343
mutation: GraphQLTaggedNode,
@@ -57,9 +57,9 @@ export type MutationConfig<TMutation: MutationParameters> = {
5757
updater?: ?SelectorStoreUpdater<TMutation['response']>,
5858
uploadables?: UploadableMap,
5959
variables: TMutation['variables'],
60-
};
60+
}>;
6161

62-
export type CommitMutationConfig<TVariables, TData, TRawResponse> = {
62+
export type CommitMutationConfig<TVariables, TData, TRawResponse> = $ReadOnly<{
6363
cacheConfig?: CacheConfig,
6464
configs?: Array<DeclarativeMutationConfig>,
6565
mutation: Mutation<TVariables, TData, TRawResponse>,
@@ -72,7 +72,7 @@ export type CommitMutationConfig<TVariables, TData, TRawResponse> = {
7272
updater?: ?SelectorStoreUpdater<TData>,
7373
uploadables?: UploadableMap,
7474
variables: TVariables,
75-
};
75+
}>;
7676

7777
/**
7878
* Higher-level helper function to execute a mutation against a specific

packages/relay-runtime/query/__tests__/fetchQueryInternal-test.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
*/
1111

1212
'use strict';
13-
import type {GraphQLResponse} from '../../network/RelayNetworkTypes';
13+
import type {
14+
GraphQLResponse,
15+
GraphQLSingularResponse,
16+
} from '../../network/RelayNetworkTypes';
1417
import type {Subscription} from '../../network/RelayObservable';
1518
import type {Observer} from '../../network/RelayObservable';
1619
import type {NormalizationSplitOperation} from '../../util/NormalizationNode';
@@ -41,7 +44,7 @@ const {
4144

4245
injectPromisePolyfill__DEPRECATED();
4346

44-
let response;
47+
let response: GraphQLSingularResponse;
4548
let gqlQuery:
4649
| Query<
4750
fetchQueryInternalTest1Query$variables,

packages/relay-runtime/store/__tests__/DataChecker-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ describe('check()', () => {
176176
});
177177

178178
it('reads fragment data', () => {
179-
const data = {
179+
const data: RecordSourceJSON = {
180180
'1': {
181181
__id: '1',
182182
id: '1',

packages/relay-runtime/store/__tests__/RelayResponseNormalizer-test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
'use strict';
1313

14+
import type {PayloadData, PayloadError} from '../../network/RelayNetworkTypes';
1415
import type {RecordSourceJSON} from '../RelayStoreTypes';
1516

1617
const {
@@ -4136,7 +4137,7 @@ describe('RelayResponseNormalizer', () => {
41364137
}
41374138
`;
41384139

4139-
const payload = {};
4140+
const payload: PayloadData = {};
41404141
const recordSource = new RelayRecordSource();
41414142
recordSource.set(ROOT_ID, RelayModernRecord.create(ROOT_ID, ROOT_TYPE));
41424143

@@ -4199,7 +4200,7 @@ describe('RelayResponseNormalizer', () => {
41994200
}
42004201
}
42014202
`;
4202-
const payload = {
4203+
const payload: PayloadData = {
42034204
node: {
42044205
id: '1',
42054206
__typename: 'User',
@@ -4235,7 +4236,7 @@ describe('RelayResponseNormalizer', () => {
42354236
},
42364237
},
42374238
};
4238-
const errors = [
4239+
const errors: Array<PayloadError> = [
42394240
{
42404241
message: "No one knows Kramer's first name until season six!",
42414242
path: ['node', 'friends', 'edges', 1, 'node', 'firstName'],

packages/relay-runtime/subscription/requestSubscription.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,17 @@ export type SubscriptionParameters = {
4141
* Updated Flow type that makes use of typed graphql tagged literals with
4242
* type information.
4343
*/
44-
export type GraphQLSubscriptionConfig<TVariables, TData, TRawResponse> = {
45-
configs?: Array<DeclarativeMutationConfig>,
46-
cacheConfig?: CacheConfig,
47-
subscription: GraphQLSubscription<TVariables, TData, TRawResponse>,
48-
variables: TVariables,
49-
onCompleted?: ?() => void,
50-
onError?: ?(error: Error) => void,
51-
onNext?: ?(response: ?TData) => void,
52-
updater?: ?SelectorStoreUpdater<TData>,
53-
};
44+
export type GraphQLSubscriptionConfig<TVariables, TData, TRawResponse> =
45+
$ReadOnly<{
46+
configs?: Array<DeclarativeMutationConfig>,
47+
cacheConfig?: CacheConfig,
48+
subscription: GraphQLSubscription<TVariables, TData, TRawResponse>,
49+
variables: TVariables,
50+
onCompleted?: ?() => void,
51+
onError?: ?(error: Error) => void,
52+
onNext?: ?(response: ?TData) => void,
53+
updater?: ?SelectorStoreUpdater<TData>,
54+
}>;
5455

5556
function requestSubscription<TVariables: Variables, TData, TRawResponse>(
5657
environment: IEnvironment,

0 commit comments

Comments
 (0)