relay-test-utils 20.1.1 → 21.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/RelayMockPayloadGenerator.js.flow +45 -43
- package/RelayModernMockEnvironment.js.flow +25 -13
- package/RelayResolverTestUtils.js.flow +4 -4
- package/__flowtests__/RelayResolverTestUtilsFlowTest.js.flow +2 -2
- package/__flowtests__/__generated__/RelayResolverTestUtilsFlowTest.graphql.js.flow +3 -4
- package/index.js +1 -1
- package/index.js.flow +4 -0
- package/package.json +2 -2
- package/unwrapContainer.js.flow +3 -3
|
@@ -60,28 +60,28 @@ type ValueResolver = (
|
|
|
60
60
|
typeName: ?string,
|
|
61
61
|
context: MockResolverContext,
|
|
62
62
|
plural: ?boolean,
|
|
63
|
-
defaultValue?:
|
|
64
|
-
) =>
|
|
63
|
+
defaultValue?: unknown,
|
|
64
|
+
) => unknown;
|
|
65
65
|
type Traversable = {
|
|
66
|
-
+selections:
|
|
66
|
+
+selections: ReadonlyArray<NormalizationSelection>,
|
|
67
67
|
+typeName: ?string,
|
|
68
68
|
+isAbstractType: ?boolean,
|
|
69
69
|
+name: ?string,
|
|
70
70
|
+alias: ?string,
|
|
71
|
-
+args: ?{[string]:
|
|
71
|
+
+args: ?{[string]: unknown, ...},
|
|
72
72
|
};
|
|
73
|
-
type MockData = {[string]:
|
|
73
|
+
type MockData = {[string]: unknown, ...};
|
|
74
74
|
export type MockResolverContext = {
|
|
75
75
|
+parentType: ?string,
|
|
76
76
|
+name: ?string,
|
|
77
77
|
+alias: ?string,
|
|
78
|
-
+path:
|
|
79
|
-
+args: ?{[string]:
|
|
78
|
+
+path: ?ReadonlyArray<string>,
|
|
79
|
+
+args: ?{[string]: unknown, ...},
|
|
80
80
|
};
|
|
81
81
|
type MockResolver = (
|
|
82
82
|
context: MockResolverContext,
|
|
83
83
|
generateId: () => number,
|
|
84
|
-
) =>
|
|
84
|
+
) => unknown;
|
|
85
85
|
export type MockResolvers = {+[typeName: string]: MockResolver, ...};
|
|
86
86
|
|
|
87
87
|
type SelectionMetadata = {
|
|
@@ -89,7 +89,7 @@ type SelectionMetadata = {
|
|
|
89
89
|
+type: string,
|
|
90
90
|
+plural: boolean,
|
|
91
91
|
+nullable: boolean,
|
|
92
|
-
+enumValues:
|
|
92
|
+
+enumValues: ReadonlyArray<string> | null,
|
|
93
93
|
},
|
|
94
94
|
...
|
|
95
95
|
};
|
|
@@ -131,9 +131,9 @@ function valueResolver(
|
|
|
131
131
|
typeName: ?string,
|
|
132
132
|
context: MockResolverContext,
|
|
133
133
|
plural: ?boolean = false,
|
|
134
|
-
defaultValue?:
|
|
135
|
-
):
|
|
136
|
-
const generateValue = (possibleDefaultValue:
|
|
134
|
+
defaultValue?: unknown,
|
|
135
|
+
): unknown {
|
|
136
|
+
const generateValue = (possibleDefaultValue: unknown) => {
|
|
137
137
|
let mockValue;
|
|
138
138
|
const mockResolver =
|
|
139
139
|
typeName != null && mockResolvers != null
|
|
@@ -170,9 +170,9 @@ function createValueResolver(mockResolvers: ?MockResolvers): ValueResolver {
|
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
function generateMockList<T>(
|
|
173
|
-
placeholderArray:
|
|
174
|
-
generateListItem: (defaultValue:
|
|
175
|
-
):
|
|
173
|
+
placeholderArray: ReadonlyArray<unknown>,
|
|
174
|
+
generateListItem: (defaultValue: unknown, index?: number) => T,
|
|
175
|
+
): ReadonlyArray<T> {
|
|
176
176
|
return placeholderArray.map((possibleDefaultValue, index) =>
|
|
177
177
|
generateListItem(possibleDefaultValue, index),
|
|
178
178
|
);
|
|
@@ -207,7 +207,7 @@ class RelayMockPayloadGenerator {
|
|
|
207
207
|
}
|
|
208
208
|
|
|
209
209
|
generate(
|
|
210
|
-
selections:
|
|
210
|
+
selections: ReadonlyArray<NormalizationSelection>,
|
|
211
211
|
operationType: string,
|
|
212
212
|
): Array<GraphQLSingularResponse> {
|
|
213
213
|
const defaultValues = this._getDefaultValuesForObject(
|
|
@@ -236,7 +236,7 @@ class RelayMockPayloadGenerator {
|
|
|
236
236
|
|
|
237
237
|
_traverse(
|
|
238
238
|
traversable: Traversable,
|
|
239
|
-
path:
|
|
239
|
+
path: ReadonlyArray<string>,
|
|
240
240
|
prevData: ?MockData,
|
|
241
241
|
defaultValues: ?MockData,
|
|
242
242
|
): MockData {
|
|
@@ -256,10 +256,10 @@ class RelayMockPayloadGenerator {
|
|
|
256
256
|
* Generate mock values for selection of fields
|
|
257
257
|
*/
|
|
258
258
|
_traverseSelections(
|
|
259
|
-
selections:
|
|
259
|
+
selections: ReadonlyArray<NormalizationSelection>,
|
|
260
260
|
typeName: ?string,
|
|
261
261
|
isAbstractType: ?boolean,
|
|
262
|
-
path:
|
|
262
|
+
path: ReadonlyArray<string>,
|
|
263
263
|
prevData: ?MockData,
|
|
264
264
|
defaultValues: ?MockData,
|
|
265
265
|
): MockData {
|
|
@@ -278,6 +278,8 @@ class RelayMockPayloadGenerator {
|
|
|
278
278
|
break;
|
|
279
279
|
}
|
|
280
280
|
// $FlowFixMe[incompatible-type]
|
|
281
|
+
/* $FlowFixMe[invalid-compare] Error discovered during Constant
|
|
282
|
+
* Condition roll out. See https://fburl.com/workplace/4oq3zi07. */
|
|
281
283
|
case CONNECTION: {
|
|
282
284
|
mockData = this._traverseSelections(
|
|
283
285
|
[selection.edges, selection.pageInfo],
|
|
@@ -528,7 +530,7 @@ class RelayMockPayloadGenerator {
|
|
|
528
530
|
);
|
|
529
531
|
|
|
530
532
|
const splitOperation: NormalizationSplitOperation =
|
|
531
|
-
|
|
533
|
+
operation as $FlowFixMe;
|
|
532
534
|
const {documentName} = selection;
|
|
533
535
|
if (mockData == null) {
|
|
534
536
|
mockData = {};
|
|
@@ -587,7 +589,7 @@ class RelayMockPayloadGenerator {
|
|
|
587
589
|
);
|
|
588
590
|
break;
|
|
589
591
|
default:
|
|
590
|
-
|
|
592
|
+
selection as empty;
|
|
591
593
|
invariant(
|
|
592
594
|
false,
|
|
593
595
|
'RelayMockPayloadGenerator(): Unexpected AST kind `%s`.',
|
|
@@ -595,7 +597,7 @@ class RelayMockPayloadGenerator {
|
|
|
595
597
|
);
|
|
596
598
|
}
|
|
597
599
|
});
|
|
598
|
-
// $FlowFixMe[incompatible-
|
|
600
|
+
// $FlowFixMe[incompatible-type]
|
|
599
601
|
return mockData;
|
|
600
602
|
}
|
|
601
603
|
|
|
@@ -604,9 +606,9 @@ class RelayMockPayloadGenerator {
|
|
|
604
606
|
* @private
|
|
605
607
|
*/
|
|
606
608
|
_getCorrectDefaultEnum(
|
|
607
|
-
enumValues:
|
|
608
|
-
value:
|
|
609
|
-
path:
|
|
609
|
+
enumValues: ReadonlyArray<string>,
|
|
610
|
+
value: unknown | Array<unknown>,
|
|
611
|
+
path: ReadonlyArray<string>,
|
|
610
612
|
applicationName: string,
|
|
611
613
|
): ?(string | Array<string>) {
|
|
612
614
|
if (value === undefined) {
|
|
@@ -662,17 +664,17 @@ class RelayMockPayloadGenerator {
|
|
|
662
664
|
_mockScalar(
|
|
663
665
|
field: NormalizationScalarField,
|
|
664
666
|
typeName: ?string,
|
|
665
|
-
path:
|
|
667
|
+
path: ReadonlyArray<string>,
|
|
666
668
|
mockData: ?MockData,
|
|
667
669
|
defaultValues: ?MockData,
|
|
668
670
|
): MockData {
|
|
669
|
-
const data = mockData ?? ({}
|
|
671
|
+
const data = mockData ?? ({} as {[string]: unknown});
|
|
670
672
|
const applicationName = field.alias ?? field.name;
|
|
671
673
|
if (data.hasOwnProperty(applicationName) && field.name !== TYPENAME_KEY) {
|
|
672
674
|
return data;
|
|
673
675
|
}
|
|
674
676
|
|
|
675
|
-
let value:
|
|
677
|
+
let value: unknown;
|
|
676
678
|
|
|
677
679
|
// For __typename fields we are going to return typeName
|
|
678
680
|
if (field.name === TYPENAME_KEY) {
|
|
@@ -740,7 +742,7 @@ class RelayMockPayloadGenerator {
|
|
|
740
742
|
*/
|
|
741
743
|
_mockLink(
|
|
742
744
|
field: NormalizationLinkedField,
|
|
743
|
-
path:
|
|
745
|
+
path: ReadonlyArray<string>,
|
|
744
746
|
prevData: ?MockData,
|
|
745
747
|
defaultValues: ?MockData,
|
|
746
748
|
): MockData | null {
|
|
@@ -787,7 +789,7 @@ class RelayMockPayloadGenerator {
|
|
|
787
789
|
field.concreteType == null && typeName === typeFromSelection.type;
|
|
788
790
|
|
|
789
791
|
const generateDataForField = (
|
|
790
|
-
possibleDefaultValue:
|
|
792
|
+
possibleDefaultValue: unknown,
|
|
791
793
|
index?: number,
|
|
792
794
|
) => {
|
|
793
795
|
const fieldPath = field.plural
|
|
@@ -819,7 +821,7 @@ class RelayMockPayloadGenerator {
|
|
|
819
821
|
? // $FlowFixMe[incompatible-variance]
|
|
820
822
|
data[applicationName]
|
|
821
823
|
: null,
|
|
822
|
-
// $FlowFixMe[incompatible-
|
|
824
|
+
// $FlowFixMe[incompatible-type]
|
|
823
825
|
fieldDefaultValue,
|
|
824
826
|
);
|
|
825
827
|
};
|
|
@@ -837,7 +839,7 @@ class RelayMockPayloadGenerator {
|
|
|
837
839
|
/**
|
|
838
840
|
* Get the value for a variable by name
|
|
839
841
|
*/
|
|
840
|
-
_getVariableValue(name: string):
|
|
842
|
+
_getVariableValue(name: string): unknown {
|
|
841
843
|
invariant(
|
|
842
844
|
this._variables.hasOwnProperty(name),
|
|
843
845
|
'RelayMockPayloadGenerator(): Undefined variable `%s`.',
|
|
@@ -855,8 +857,8 @@ class RelayMockPayloadGenerator {
|
|
|
855
857
|
typeName: ?string,
|
|
856
858
|
fieldName: ?string,
|
|
857
859
|
fieldAlias: ?string,
|
|
858
|
-
path:
|
|
859
|
-
args: ?{[string]:
|
|
860
|
+
path: ReadonlyArray<string>,
|
|
861
|
+
args: ?{[string]: unknown, ...},
|
|
860
862
|
): ?MockData {
|
|
861
863
|
let data;
|
|
862
864
|
if (typeName != null && this._mockResolvers[typeName] != null) {
|
|
@@ -881,8 +883,8 @@ class RelayMockPayloadGenerator {
|
|
|
881
883
|
/**
|
|
882
884
|
* Get object with variables for field
|
|
883
885
|
*/
|
|
884
|
-
_getFieldArgs(field: NormalizationField): {[string]:
|
|
885
|
-
const args: {[string]:
|
|
886
|
+
_getFieldArgs(field: NormalizationField): {[string]: unknown, ...} {
|
|
887
|
+
const args: {[string]: unknown} = {};
|
|
886
888
|
if (field.args != null) {
|
|
887
889
|
field.args.forEach(arg => {
|
|
888
890
|
args[arg.name] = this._getArgValue(arg);
|
|
@@ -891,14 +893,14 @@ class RelayMockPayloadGenerator {
|
|
|
891
893
|
return args;
|
|
892
894
|
}
|
|
893
895
|
|
|
894
|
-
_getArgValue(arg: NormalizationArgument):
|
|
896
|
+
_getArgValue(arg: NormalizationArgument): unknown {
|
|
895
897
|
switch (arg.kind) {
|
|
896
898
|
case 'Literal':
|
|
897
899
|
return arg.value;
|
|
898
900
|
case 'Variable':
|
|
899
901
|
return this._getVariableValue(arg.variableName);
|
|
900
902
|
case 'ObjectValue': {
|
|
901
|
-
const value: {[string]:
|
|
903
|
+
const value: {[string]: unknown} = {};
|
|
902
904
|
arg.fields.forEach(field => {
|
|
903
905
|
value[field.name] = this._getArgValue(field);
|
|
904
906
|
});
|
|
@@ -920,11 +922,11 @@ class RelayMockPayloadGenerator {
|
|
|
920
922
|
_getScalarFieldTypeDetails(
|
|
921
923
|
field: NormalizationScalarField,
|
|
922
924
|
typeName: ?string,
|
|
923
|
-
selectionPath:
|
|
925
|
+
selectionPath: ReadonlyArray<string>,
|
|
924
926
|
): {
|
|
925
927
|
+type: string,
|
|
926
928
|
+plural: boolean,
|
|
927
|
-
+enumValues:
|
|
929
|
+
+enumValues: ReadonlyArray<string> | null,
|
|
928
930
|
+nullable: boolean,
|
|
929
931
|
} {
|
|
930
932
|
return (
|
|
@@ -943,8 +945,8 @@ class RelayMockPayloadGenerator {
|
|
|
943
945
|
* @private
|
|
944
946
|
*/
|
|
945
947
|
_getTypeDetailsForPath(
|
|
946
|
-
path:
|
|
947
|
-
):
|
|
948
|
+
path: ReadonlyArray<string>,
|
|
949
|
+
): Values<SelectionMetadata> {
|
|
948
950
|
return this._selectionMetadata[
|
|
949
951
|
// When selecting metadata, skip the number on plural fields so that every field in the array
|
|
950
952
|
// gets the same metadata.
|
|
@@ -1050,7 +1052,7 @@ function generateWithDefer(
|
|
|
1050
1052
|
operation.request.variables,
|
|
1051
1053
|
mockResolvers ?? null,
|
|
1052
1054
|
getSelectionMetadataFromOperation(operation),
|
|
1053
|
-
{...otherOptions, generateDeferredPayload
|
|
1055
|
+
{...otherOptions, generateDeferredPayload},
|
|
1054
1056
|
);
|
|
1055
1057
|
|
|
1056
1058
|
if (!generateDeferredPayload) {
|
|
@@ -113,9 +113,9 @@ type MockFunctions = {
|
|
|
113
113
|
+complete: (request: ConcreteRequest | OperationDescriptor) => void,
|
|
114
114
|
+resolve: (
|
|
115
115
|
request: ConcreteRequest | OperationDescriptor,
|
|
116
|
-
payload:
|
|
116
|
+
payload: ReadonlyArray<GraphQLSingularResponse> | GraphQLSingularResponse,
|
|
117
117
|
) => void,
|
|
118
|
-
+getAllOperations: () =>
|
|
118
|
+
+getAllOperations: () => ReadonlyArray<OperationDescriptor>,
|
|
119
119
|
+findOperation: (
|
|
120
120
|
findFn: (operation: OperationDescriptor) => boolean,
|
|
121
121
|
) => OperationDescriptor,
|
|
@@ -187,8 +187,8 @@ function createMockEnvironment(
|
|
|
187
187
|
ttl: MAX_TTL,
|
|
188
188
|
});
|
|
189
189
|
|
|
190
|
-
let pendingRequests:
|
|
191
|
-
let pendingOperations:
|
|
190
|
+
let pendingRequests: ReadonlyArray<PendingRequest> = [];
|
|
191
|
+
let pendingOperations: ReadonlyArray<OperationDescriptor> = [];
|
|
192
192
|
const queuePendingOperation = (
|
|
193
193
|
query: GraphQLTaggedNode,
|
|
194
194
|
variables: Variables,
|
|
@@ -199,7 +199,7 @@ function createMockEnvironment(
|
|
|
199
199
|
);
|
|
200
200
|
pendingOperations = pendingOperations.concat([operationDescriptor]);
|
|
201
201
|
};
|
|
202
|
-
let resolversQueue:
|
|
202
|
+
let resolversQueue: ReadonlyArray<OperationMockResolver> = [];
|
|
203
203
|
|
|
204
204
|
const queueOperationResolver = (resolver: OperationMockResolver): void => {
|
|
205
205
|
resolversQueue = resolversQueue.concat([resolver]);
|
|
@@ -222,7 +222,7 @@ function createMockEnvironment(
|
|
|
222
222
|
cachedPayload = cache.get(cacheID, variables);
|
|
223
223
|
}
|
|
224
224
|
if (cachedPayload !== null) {
|
|
225
|
-
// $FlowFixMe[incompatible-
|
|
225
|
+
// $FlowFixMe[incompatible-type]
|
|
226
226
|
return Observable.from<GraphQLSingularResponse>(cachedPayload);
|
|
227
227
|
}
|
|
228
228
|
|
|
@@ -275,10 +275,10 @@ function createMockEnvironment(
|
|
|
275
275
|
input: ConcreteRequest | OperationDescriptor,
|
|
276
276
|
): ConcreteRequest {
|
|
277
277
|
if (input.kind === 'Request') {
|
|
278
|
-
const request: ConcreteRequest =
|
|
278
|
+
const request: ConcreteRequest = input as $FlowFixMe;
|
|
279
279
|
return request;
|
|
280
280
|
} else {
|
|
281
|
-
const operationDescriptor: OperationDescriptor =
|
|
281
|
+
const operationDescriptor: OperationDescriptor = input as $FlowFixMe;
|
|
282
282
|
invariant(
|
|
283
283
|
pendingOperations.includes(operationDescriptor),
|
|
284
284
|
'RelayModernMockEnvironment: Operation "%s" was not found in the list of pending operations',
|
|
@@ -291,13 +291,13 @@ function createMockEnvironment(
|
|
|
291
291
|
// The same request may be made by multiple query renderers
|
|
292
292
|
function getRequests(
|
|
293
293
|
input: ConcreteRequest | OperationDescriptor,
|
|
294
|
-
):
|
|
294
|
+
): ReadonlyArray<PendingRequest> {
|
|
295
295
|
let concreteRequest: ConcreteRequest;
|
|
296
296
|
let operationDescriptor: OperationDescriptor;
|
|
297
297
|
if (input.kind === 'Request') {
|
|
298
|
-
concreteRequest =
|
|
298
|
+
concreteRequest = input as $FlowFixMe;
|
|
299
299
|
} else {
|
|
300
|
-
operationDescriptor =
|
|
300
|
+
operationDescriptor = input as $FlowFixMe;
|
|
301
301
|
concreteRequest = operationDescriptor.request.node;
|
|
302
302
|
}
|
|
303
303
|
const foundRequests = pendingRequests.filter(pending => {
|
|
@@ -334,6 +334,8 @@ function createMockEnvironment(
|
|
|
334
334
|
function ensureValidPayload(payload: GraphQLSingularResponse) {
|
|
335
335
|
invariant(
|
|
336
336
|
typeof payload === 'object' &&
|
|
337
|
+
/* $FlowFixMe[invalid-compare] Error discovered during Constant
|
|
338
|
+
* Condition roll out. See https://fburl.com/workplace/5whu3i34. */
|
|
337
339
|
payload !== null &&
|
|
338
340
|
payload.hasOwnProperty('data'),
|
|
339
341
|
'MockEnvironment(): Expected payload to be an object with a `data` key.',
|
|
@@ -379,6 +381,8 @@ function createMockEnvironment(
|
|
|
379
381
|
const rejectError = typeof error === 'string' ? new Error(error) : error;
|
|
380
382
|
getRequests(request).forEach(foundRequest => {
|
|
381
383
|
const {sink} = foundRequest;
|
|
384
|
+
/* $FlowFixMe[invalid-compare] Error discovered during Constant Condition
|
|
385
|
+
* roll out. See https://fburl.com/workplace/5whu3i34. */
|
|
382
386
|
invariant(sink !== null, 'Sink should be defined.');
|
|
383
387
|
sink.error(rejectError);
|
|
384
388
|
});
|
|
@@ -390,6 +394,8 @@ function createMockEnvironment(
|
|
|
390
394
|
): void => {
|
|
391
395
|
getRequests(request).forEach(foundRequest => {
|
|
392
396
|
const {sink} = foundRequest;
|
|
397
|
+
/* $FlowFixMe[invalid-compare] Error discovered during Constant Condition
|
|
398
|
+
* roll out. See https://fburl.com/workplace/5whu3i34. */
|
|
393
399
|
invariant(sink !== null, 'Sink should be defined.');
|
|
394
400
|
sink.next(ensureValidPayload(payload));
|
|
395
401
|
});
|
|
@@ -398,6 +404,8 @@ function createMockEnvironment(
|
|
|
398
404
|
const complete = (request: ConcreteRequest | OperationDescriptor): void => {
|
|
399
405
|
getRequests(request).forEach(foundRequest => {
|
|
400
406
|
const {sink} = foundRequest;
|
|
407
|
+
/* $FlowFixMe[invalid-compare] Error discovered during Constant Condition
|
|
408
|
+
* roll out. See https://fburl.com/workplace/5whu3i34. */
|
|
401
409
|
invariant(sink !== null, 'Sink should be defined.');
|
|
402
410
|
sink.complete();
|
|
403
411
|
});
|
|
@@ -405,10 +413,12 @@ function createMockEnvironment(
|
|
|
405
413
|
|
|
406
414
|
const resolve = (
|
|
407
415
|
request: ConcreteRequest | OperationDescriptor,
|
|
408
|
-
response:
|
|
416
|
+
response: ReadonlyArray<GraphQLSingularResponse> | GraphQLSingularResponse,
|
|
409
417
|
): void => {
|
|
410
418
|
getRequests(request).forEach(foundRequest => {
|
|
411
419
|
const {sink} = foundRequest;
|
|
420
|
+
/* $FlowFixMe[invalid-compare] Error discovered during Constant Condition
|
|
421
|
+
* roll out. See https://fburl.com/workplace/5whu3i34. */
|
|
412
422
|
invariant(sink !== null, 'Sink should be defined.');
|
|
413
423
|
const payloads = Array.isArray(response) ? response : [response];
|
|
414
424
|
payloads.forEach(payload => {
|
|
@@ -438,7 +448,7 @@ function createMockEnvironment(
|
|
|
438
448
|
return pendingOperation;
|
|
439
449
|
};
|
|
440
450
|
|
|
441
|
-
// $FlowExpectedError[
|
|
451
|
+
// $FlowExpectedError[incompatible-type]
|
|
442
452
|
const environment: RelayMockEnvironment = new Environment({
|
|
443
453
|
configName: 'RelayModernMockEnvironment',
|
|
444
454
|
network: Network.create(execute, execute),
|
|
@@ -487,6 +497,8 @@ function createMockEnvironment(
|
|
|
487
497
|
);
|
|
488
498
|
|
|
489
499
|
// $FlowFixMe[incompatible-type]
|
|
500
|
+
/* $FlowFixMe[invalid-compare] Error discovered during Constant Condition
|
|
501
|
+
* roll out. See https://fburl.com/workplace/4oq3zi07. */
|
|
490
502
|
if (global?.process?.env?.NODE_ENV === 'test') {
|
|
491
503
|
// Mock all the functions with their original behavior
|
|
492
504
|
mockDisposableMethod(environment, 'applyUpdate');
|
|
@@ -34,18 +34,18 @@ const {
|
|
|
34
34
|
* expect(actual).toEqual(expectedValue)
|
|
35
35
|
* ```
|
|
36
36
|
**/
|
|
37
|
-
function testResolver<D
|
|
37
|
+
function testResolver<D extends ?{+$fragmentType?: unknown, ...}, Ret>(
|
|
38
38
|
resolver: ({$data?: D, $fragmentRefs: any, $fragmentSpreads: any}) => Ret,
|
|
39
39
|
// indexed_access is not yet enabled for this code base. Once it is, this can
|
|
40
40
|
// become: `Key['$data']`
|
|
41
|
-
fragmentData: NoInfer<Omit
|
|
41
|
+
fragmentData: NoInfer<Omit<NonNullable<D>, '$fragmentType'>>,
|
|
42
42
|
): Ret {
|
|
43
43
|
const readFragment = ResolverFragments.readFragment;
|
|
44
|
-
// $FlowFixMe: a test utility, so... YOLO!!
|
|
44
|
+
// $FlowFixMe[incompatible-type]: a test utility, so... YOLO!!
|
|
45
45
|
ResolverFragments.readFragment = () => fragmentData;
|
|
46
46
|
const result = resolver(
|
|
47
47
|
// This will be ignored since we mock the function it gets passed to.
|
|
48
|
-
// $FlowFixMe
|
|
48
|
+
// $FlowFixMe[incompatible-type]
|
|
49
49
|
null,
|
|
50
50
|
);
|
|
51
51
|
ResolverFragments.readFragment = readFragment;
|
|
@@ -32,11 +32,11 @@ function myTestResolver(rootKey: RelayResolverTestUtilsFlowTest$key): string {
|
|
|
32
32
|
|
|
33
33
|
testResolver(myTestResolver, {name: 'Elizabeth'});
|
|
34
34
|
|
|
35
|
-
// $FlowExpectedError
|
|
35
|
+
// $FlowExpectedError[incompatible-type] foo is an unexpected key
|
|
36
36
|
testResolver(myTestResolver, {
|
|
37
37
|
name: 'Elizabeth',
|
|
38
38
|
foo: 'bar',
|
|
39
39
|
});
|
|
40
40
|
|
|
41
|
-
// $FlowExpectedError
|
|
41
|
+
// $FlowExpectedError[incompatible-type] Object is not a string
|
|
42
42
|
testResolver(myTestResolver, {name: {}});
|
|
@@ -6,10 +6,9 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @oncall relay
|
|
8
8
|
*
|
|
9
|
-
* @generated SignedSource<<
|
|
9
|
+
* @generated SignedSource<<eff5153dfb25d03ddd6c26d0ff39c34b>>
|
|
10
10
|
* @flow
|
|
11
11
|
* @lightSyntaxTransform
|
|
12
|
-
* @nogrep
|
|
13
12
|
*/
|
|
14
13
|
|
|
15
14
|
/* eslint-disable */
|
|
@@ -50,10 +49,10 @@ var node/*: ReaderFragment*/ = {
|
|
|
50
49
|
};
|
|
51
50
|
|
|
52
51
|
if (__DEV__) {
|
|
53
|
-
(node
|
|
52
|
+
(node/*:: as any*/).hash = "f3f6718b7cf618c97293b5882ccc96c0";
|
|
54
53
|
}
|
|
55
54
|
|
|
56
|
-
module.exports = ((node
|
|
55
|
+
module.exports = ((node/*:: as any*/)/*:: as Fragment<
|
|
57
56
|
RelayResolverTestUtilsFlowTest$fragmentType,
|
|
58
57
|
RelayResolverTestUtilsFlowTest$data,
|
|
59
58
|
>*/);
|
package/index.js
CHANGED
package/index.js.flow
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "relay-test-utils",
|
|
3
3
|
"description": "Utilities for testing Relay applications.",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "21.0.0",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"graphql",
|
|
7
7
|
"relay"
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"@babel/runtime": "^7.25.0",
|
|
19
19
|
"fbjs": "^3.0.2",
|
|
20
20
|
"invariant": "^2.2.4",
|
|
21
|
-
"relay-runtime": "
|
|
21
|
+
"relay-runtime": "21.0.0"
|
|
22
22
|
},
|
|
23
23
|
"directories": {
|
|
24
24
|
"": "./"
|
package/unwrapContainer.js.flow
CHANGED
|
@@ -23,19 +23,19 @@ const invariant = require('invariant');
|
|
|
23
23
|
/**
|
|
24
24
|
* Returns original component class wrapped by e.g. createFragmentContainer
|
|
25
25
|
*/
|
|
26
|
-
function unwrapContainer<Props
|
|
26
|
+
function unwrapContainer<Props extends {...}>(
|
|
27
27
|
ComponentClass: component(
|
|
28
28
|
...$RelayProps<Props, RelayProp | RelayPaginationProp | RelayRefetchProp>
|
|
29
29
|
),
|
|
30
30
|
): component(...Props) {
|
|
31
|
-
// $FlowExpectedError
|
|
31
|
+
// $FlowExpectedError[prop-missing]
|
|
32
32
|
const unwrapped = ComponentClass.__ComponentClass;
|
|
33
33
|
invariant(
|
|
34
34
|
unwrapped != null,
|
|
35
35
|
'Could not find component for %s, is it a Relay container?',
|
|
36
36
|
ComponentClass.displayName || ComponentClass.name,
|
|
37
37
|
);
|
|
38
|
-
return
|
|
38
|
+
return unwrapped as any;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
module.exports = unwrapContainer;
|