relay-test-utils 11.0.2 → 13.0.0-rc.2
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +4 -0
- package/RelayMockPayloadGenerator.js.flow +22 -22
- package/RelayModernMockEnvironment.js.flow +54 -21
- package/RelayResolverTestUtils.js.flow +53 -0
- package/__flowtests__/RelayResolverTestUtilsFlowTest.js.flow +52 -0
- package/__flowtests__/__generated__/RelayResolverTestUtilsFlowTest.graphql.js.flow +59 -0
- package/index.js +1 -1
- package/index.js.flow +3 -2
- package/lib/RelayMockPayloadGenerator.js +9 -7
- package/lib/RelayModernMockEnvironment.js +49 -21
- package/lib/RelayResolverTestUtils.js +53 -0
- package/lib/index.js +5 -2
- package/lib/unwrapContainer.js +3 -2
- package/package.json +3 -6
- package/relay-test-utils.js +2 -2
- package/relay-test-utils.min.js +2 -2
- package/unwrapContainer.js.flow +5 -5
package/README.md
ADDED
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -13,16 +13,29 @@
|
|
13
13
|
|
14
14
|
'use strict';
|
15
15
|
|
16
|
-
|
16
|
+
import type {
|
17
|
+
GraphQLSingularResponse,
|
18
|
+
NormalizationArgument,
|
19
|
+
NormalizationField,
|
20
|
+
NormalizationLinkedField,
|
21
|
+
NormalizationOperation,
|
22
|
+
NormalizationScalarField,
|
23
|
+
NormalizationSelection,
|
24
|
+
NormalizationSplitOperation,
|
25
|
+
OperationDescriptor,
|
26
|
+
Variables,
|
27
|
+
} from 'relay-runtime';
|
17
28
|
|
29
|
+
const invariant = require('invariant');
|
18
30
|
const {
|
19
|
-
TYPENAME_KEY,
|
20
31
|
RelayConcreteNode,
|
32
|
+
TYPENAME_KEY,
|
21
33
|
getModuleComponentKey,
|
22
34
|
getModuleOperationKey,
|
23
35
|
} = require('relay-runtime');
|
24
36
|
|
25
37
|
const {
|
38
|
+
ACTOR_CHANGE,
|
26
39
|
CLIENT_COMPONENT,
|
27
40
|
CLIENT_EXTENSION,
|
28
41
|
CONDITION,
|
@@ -40,19 +53,6 @@ const {
|
|
40
53
|
TYPE_DISCRIMINATOR,
|
41
54
|
} = RelayConcreteNode;
|
42
55
|
|
43
|
-
import type {
|
44
|
-
NormalizationArgument,
|
45
|
-
NormalizationField,
|
46
|
-
NormalizationLinkedField,
|
47
|
-
NormalizationOperation,
|
48
|
-
NormalizationScalarField,
|
49
|
-
NormalizationSelection,
|
50
|
-
OperationDescriptor,
|
51
|
-
GraphQLSingularResponse,
|
52
|
-
NormalizationSplitOperation,
|
53
|
-
Variables,
|
54
|
-
} from 'relay-runtime';
|
55
|
-
|
56
56
|
type ValueResolver = (
|
57
57
|
typeName: ?string,
|
58
58
|
context: MockResolverContext,
|
@@ -187,7 +187,6 @@ class RelayMockPayloadGenerator {
|
|
187
187
|
+selectionMetadata: SelectionMetadata | null,
|
188
188
|
|}) {
|
189
189
|
this._variables = options.variables;
|
190
|
-
// $FlowFixMe[cannot-spread-indexer]
|
191
190
|
// $FlowFixMe[cannot-spread-inexact]
|
192
191
|
// $FlowFixMe[incompatible-type]
|
193
192
|
this._mockResolvers = {
|
@@ -459,7 +458,8 @@ class RelayMockPayloadGenerator {
|
|
459
458
|
selection.fragmentName,
|
460
459
|
);
|
461
460
|
|
462
|
-
const splitOperation: NormalizationSplitOperation =
|
461
|
+
const splitOperation: NormalizationSplitOperation =
|
462
|
+
(operation: $FlowFixMe);
|
463
463
|
const {documentName} = selection;
|
464
464
|
if (mockData == null) {
|
465
465
|
mockData = {};
|
@@ -469,9 +469,8 @@ class RelayMockPayloadGenerator {
|
|
469
469
|
...mockData,
|
470
470
|
[TYPENAME_KEY]: typeName,
|
471
471
|
[getModuleOperationKey(documentName)]: operation.name,
|
472
|
-
[getModuleComponentKey(
|
473
|
-
|
474
|
-
)]: defaultValues.__module_component,
|
472
|
+
[getModuleComponentKey(documentName)]:
|
473
|
+
defaultValues.__module_component,
|
475
474
|
...this._traverseSelections(
|
476
475
|
splitOperation.selections,
|
477
476
|
typeName,
|
@@ -498,6 +497,8 @@ class RelayMockPayloadGenerator {
|
|
498
497
|
break;
|
499
498
|
case FLIGHT_FIELD:
|
500
499
|
throw new Error('Flight fields are not yet supported.');
|
500
|
+
case ACTOR_CHANGE:
|
501
|
+
throw new Error('ActorChange fields are not yet supported.');
|
501
502
|
default:
|
502
503
|
(selection: empty);
|
503
504
|
invariant(
|
@@ -752,7 +753,6 @@ class RelayMockPayloadGenerator {
|
|
752
753
|
'RelayMockPayloadGenerator(): Undefined variable `%s`.',
|
753
754
|
name,
|
754
755
|
);
|
755
|
-
// $FlowFixMe[cannot-write]
|
756
756
|
return this._variables[name];
|
757
757
|
}
|
758
758
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -14,32 +14,31 @@
|
|
14
14
|
|
15
15
|
/* global jest */
|
16
16
|
|
17
|
-
const areEqual = require('areEqual');
|
18
|
-
const invariant = require('invariant');
|
19
|
-
|
20
|
-
const {
|
21
|
-
RecordSource,
|
22
|
-
Store,
|
23
|
-
QueryResponseCache,
|
24
|
-
Observable,
|
25
|
-
Environment,
|
26
|
-
Network,
|
27
|
-
createOperationDescriptor,
|
28
|
-
getRequest,
|
29
|
-
} = require('relay-runtime');
|
30
|
-
|
31
|
-
import type {Sink} from 'relay-runtime/network/RelayObservable';
|
32
17
|
import type {
|
33
18
|
CacheConfig,
|
34
19
|
ConcreteRequest,
|
20
|
+
EnvironmentConfig,
|
35
21
|
GraphQLSingularResponse,
|
36
22
|
GraphQLTaggedNode,
|
37
23
|
IEnvironment,
|
38
24
|
OperationDescriptor,
|
39
25
|
RequestParameters,
|
40
26
|
Variables,
|
41
|
-
EnvironmentConfig,
|
42
27
|
} from 'relay-runtime';
|
28
|
+
import type {Sink} from 'relay-runtime/network/RelayObservable';
|
29
|
+
|
30
|
+
const areEqual = require('areEqual');
|
31
|
+
const invariant = require('invariant');
|
32
|
+
const {
|
33
|
+
Environment,
|
34
|
+
Network,
|
35
|
+
Observable,
|
36
|
+
QueryResponseCache,
|
37
|
+
RecordSource,
|
38
|
+
Store,
|
39
|
+
createOperationDescriptor,
|
40
|
+
getRequest,
|
41
|
+
} = require('relay-runtime');
|
43
42
|
|
44
43
|
type PendingRequest = {|
|
45
44
|
+request: RequestParameters,
|
@@ -441,10 +440,14 @@ function createMockEnvironment(
|
|
441
440
|
|
442
441
|
const createExecuteProxy = (
|
443
442
|
env: IEnvironment,
|
444
|
-
fn:
|
445
|
-
|
446
|
-
|
447
|
-
|
|
443
|
+
fn: // $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
444
|
+
| IEnvironment['execute']
|
445
|
+
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
446
|
+
| IEnvironment['executeSubscription']
|
447
|
+
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
448
|
+
| IEnvironment['executeWithSource']
|
449
|
+
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
450
|
+
| IEnvironment['executeMutation'],
|
448
451
|
) => {
|
449
452
|
return (...argumentsList) => {
|
450
453
|
const [{operation}] = argumentsList;
|
@@ -454,15 +457,24 @@ function createMockEnvironment(
|
|
454
457
|
};
|
455
458
|
|
456
459
|
// $FlowExpectedError[cannot-write]
|
460
|
+
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
457
461
|
environment.execute = createExecuteProxy(environment, environment.execute);
|
458
462
|
// $FlowExpectedError[cannot-write]
|
463
|
+
environment.executeSubscription = createExecuteProxy(
|
464
|
+
environment,
|
465
|
+
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
466
|
+
environment.executeSubscription,
|
467
|
+
);
|
468
|
+
// $FlowExpectedError[cannot-write]
|
459
469
|
environment.executeWithSource = createExecuteProxy(
|
460
470
|
environment,
|
471
|
+
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
461
472
|
environment.executeWithSource,
|
462
473
|
);
|
463
474
|
// $FlowExpectedError[cannot-write]
|
464
475
|
environment.executeMutation = createExecuteProxy(
|
465
476
|
environment,
|
477
|
+
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
466
478
|
environment.executeMutation,
|
467
479
|
);
|
468
480
|
|
@@ -476,6 +488,7 @@ function createMockEnvironment(
|
|
476
488
|
mockDisposableMethod(environment, 'subscribe');
|
477
489
|
mockDisposableMethod(environment, 'retain');
|
478
490
|
mockObservableMethod(environment, 'execute');
|
491
|
+
mockObservableMethod(environment, 'executeSubscription');
|
479
492
|
mockObservableMethod(environment, 'executeWithSource');
|
480
493
|
mockObservableMethod(environment, 'executeMutation');
|
481
494
|
|
@@ -519,21 +532,41 @@ function createMockEnvironment(
|
|
519
532
|
|
520
533
|
// $FlowExpectedError[cannot-write]
|
521
534
|
environment.mockClear = () => {
|
535
|
+
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
522
536
|
environment.applyUpdate.mockClear();
|
537
|
+
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
523
538
|
environment.commitPayload.mockClear();
|
539
|
+
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
524
540
|
environment.getStore.mockClear();
|
541
|
+
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
525
542
|
environment.lookup.mockClear();
|
543
|
+
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
526
544
|
environment.check.mockClear();
|
545
|
+
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
527
546
|
environment.subscribe.mockClear();
|
547
|
+
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
528
548
|
environment.retain.mockClear();
|
549
|
+
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
529
550
|
environment.execute.mockClear();
|
551
|
+
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
530
552
|
environment.executeMutation.mockClear();
|
553
|
+
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
554
|
+
environment.executeSubscription.mockClear();
|
555
|
+
|
556
|
+
// $FlowExpectedError[prop-missing]
|
557
|
+
store.getSource().clear?.();
|
531
558
|
|
559
|
+
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
532
560
|
store.getSource.mockClear();
|
561
|
+
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
533
562
|
store.lookup.mockClear();
|
563
|
+
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
534
564
|
store.notify.mockClear();
|
565
|
+
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
535
566
|
store.publish.mockClear();
|
567
|
+
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
536
568
|
store.retain.mockClear();
|
569
|
+
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
537
570
|
store.subscribe.mockClear();
|
538
571
|
|
539
572
|
cache.clear();
|
@@ -0,0 +1,53 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
* @emails oncall+relay
|
8
|
+
* @format
|
9
|
+
* @flow
|
10
|
+
*/
|
11
|
+
|
12
|
+
'use strict';
|
13
|
+
|
14
|
+
const ResolverFragments = require('relay-runtime/store/ResolverFragments');
|
15
|
+
|
16
|
+
/**
|
17
|
+
* Utility function for testing Relay Resolvers. Pass the resolver function and
|
18
|
+
* the data that will be returned from `readFragment` and it will return the
|
19
|
+
* value that the resolver would derive.
|
20
|
+
*
|
21
|
+
* *Note:* Relay fragment data includes a special `$fragmentType` key which is
|
22
|
+
* impossible for non-Relay code to construct. In tests you can work around
|
23
|
+
* this by passing `null` with a Flow supression:
|
24
|
+
*
|
25
|
+
* ```
|
26
|
+
* const fragmentData = {
|
27
|
+
* // Other fields here...
|
28
|
+
* $fragmentType: (null: any)
|
29
|
+
* };
|
30
|
+
*
|
31
|
+
* const actual = testResolver(resolverFunc, fragmentData);
|
32
|
+
* expect(actual).toEqual(expectedValue)
|
33
|
+
* ```
|
34
|
+
**/
|
35
|
+
function testResolver<D, Ret>(
|
36
|
+
resolver: ({$data: D, $fragmentRefs: any, $fragmentSpreads: any}) => Ret,
|
37
|
+
// indexed_access is not yet enabled for this code base. Once it is, this can
|
38
|
+
// become: `Key['$data']`
|
39
|
+
fragmentData: D,
|
40
|
+
): Ret {
|
41
|
+
const readFragment = ResolverFragments.readFragment;
|
42
|
+
// a test utility, so... YOLO!!
|
43
|
+
ResolverFragments.readFragment = () => fragmentData;
|
44
|
+
const result = resolver(
|
45
|
+
// This will be ignored since we mock the function it gets passed to.
|
46
|
+
// $FlowFixMe
|
47
|
+
null,
|
48
|
+
);
|
49
|
+
ResolverFragments.readFragment = readFragment;
|
50
|
+
return result;
|
51
|
+
}
|
52
|
+
|
53
|
+
module.exports = {testResolver};
|
@@ -0,0 +1,52 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
* @emails oncall+relay
|
8
|
+
* @flow
|
9
|
+
* @format
|
10
|
+
*/
|
11
|
+
|
12
|
+
'use strict';
|
13
|
+
|
14
|
+
import type {RelayResolverTestUtilsFlowTest$key} from './__generated__/RelayResolverTestUtilsFlowTest.graphql';
|
15
|
+
|
16
|
+
const {testResolver} = require('../RelayResolverTestUtils');
|
17
|
+
const {graphql} = require('relay-runtime');
|
18
|
+
const {readFragment} = require('relay-runtime/store/ResolverFragments');
|
19
|
+
|
20
|
+
function myTestResolver(rootKey: RelayResolverTestUtilsFlowTest$key): string {
|
21
|
+
const user = readFragment(
|
22
|
+
graphql`
|
23
|
+
fragment RelayResolverTestUtilsFlowTest on User {
|
24
|
+
name
|
25
|
+
}
|
26
|
+
`,
|
27
|
+
rootKey,
|
28
|
+
);
|
29
|
+
|
30
|
+
return `Hello ${user.name ?? 'stranger'}!`;
|
31
|
+
}
|
32
|
+
|
33
|
+
testResolver(myTestResolver, {
|
34
|
+
name: 'Elizabeth',
|
35
|
+
$fragmentType: (null: any),
|
36
|
+
});
|
37
|
+
|
38
|
+
testResolver(
|
39
|
+
myTestResolver,
|
40
|
+
// $FlowExpectedError foo is an unexpected key
|
41
|
+
{
|
42
|
+
name: 'Elizabeth',
|
43
|
+
foo: 'bar',
|
44
|
+
$fragmentType: (null: any),
|
45
|
+
},
|
46
|
+
);
|
47
|
+
|
48
|
+
testResolver(myTestResolver, {
|
49
|
+
// $FlowExpectedError Object is not a string
|
50
|
+
name: {},
|
51
|
+
$fragmentType: (null: any),
|
52
|
+
});
|
@@ -0,0 +1,59 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
* @generated SignedSource<<0d26a05d6bac38b34cb9d5933e995920>>
|
8
|
+
* @flow
|
9
|
+
* @lightSyntaxTransform
|
10
|
+
* @nogrep
|
11
|
+
*/
|
12
|
+
|
13
|
+
/* eslint-disable */
|
14
|
+
|
15
|
+
'use strict';
|
16
|
+
|
17
|
+
/*::
|
18
|
+
import type { Fragment, ReaderFragment } from 'relay-runtime';
|
19
|
+
import type { FragmentType } from "relay-runtime";
|
20
|
+
declare export opaque type RelayResolverTestUtilsFlowTest$fragmentType: FragmentType;
|
21
|
+
export type RelayResolverTestUtilsFlowTest$ref = RelayResolverTestUtilsFlowTest$fragmentType;
|
22
|
+
export type RelayResolverTestUtilsFlowTest$data = {|
|
23
|
+
+name: ?string,
|
24
|
+
+$fragmentType: RelayResolverTestUtilsFlowTest$fragmentType,
|
25
|
+
|};
|
26
|
+
export type RelayResolverTestUtilsFlowTest = RelayResolverTestUtilsFlowTest$data;
|
27
|
+
export type RelayResolverTestUtilsFlowTest$key = {
|
28
|
+
+$data?: RelayResolverTestUtilsFlowTest$data,
|
29
|
+
+$fragmentSpreads: RelayResolverTestUtilsFlowTest$fragmentType,
|
30
|
+
...
|
31
|
+
};
|
32
|
+
*/
|
33
|
+
|
34
|
+
var node/*: ReaderFragment*/ = {
|
35
|
+
"argumentDefinitions": [],
|
36
|
+
"kind": "Fragment",
|
37
|
+
"metadata": null,
|
38
|
+
"name": "RelayResolverTestUtilsFlowTest",
|
39
|
+
"selections": [
|
40
|
+
{
|
41
|
+
"alias": null,
|
42
|
+
"args": null,
|
43
|
+
"kind": "ScalarField",
|
44
|
+
"name": "name",
|
45
|
+
"storageKey": null
|
46
|
+
}
|
47
|
+
],
|
48
|
+
"type": "User",
|
49
|
+
"abstractKey": null
|
50
|
+
};
|
51
|
+
|
52
|
+
if (__DEV__) {
|
53
|
+
(node/*: any*/).hash = "f3f6718b7cf618c97293b5882ccc96c0";
|
54
|
+
}
|
55
|
+
|
56
|
+
module.exports = ((node/*: any*/)/*: Fragment<
|
57
|
+
RelayResolverTestUtilsFlowTest$fragmentType,
|
58
|
+
RelayResolverTestUtilsFlowTest$data,
|
59
|
+
>*/);
|
package/index.js
CHANGED
package/index.js.flow
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
const RelayMockPayloadGenerator = require('./RelayMockPayloadGenerator');
|
16
16
|
const RelayModernMockEnvironment = require('./RelayModernMockEnvironment');
|
17
|
-
|
17
|
+
const testResolver = require('./RelayResolverTestUtils');
|
18
18
|
const unwrapContainer = require('./unwrapContainer');
|
19
19
|
|
20
20
|
export type {MockResolvers} from './RelayMockPayloadGenerator';
|
@@ -27,4 +27,5 @@ module.exports = {
|
|
27
27
|
MockPayloadGenerator: RelayMockPayloadGenerator,
|
28
28
|
createMockEnvironment: RelayModernMockEnvironment.createMockEnvironment,
|
29
29
|
unwrapContainer: unwrapContainer,
|
30
|
+
testResolver: testResolver,
|
30
31
|
};
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -22,12 +22,13 @@ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers
|
|
22
22
|
var invariant = require('invariant');
|
23
23
|
|
24
24
|
var _require = require('relay-runtime'),
|
25
|
-
TYPENAME_KEY = _require.TYPENAME_KEY,
|
26
25
|
RelayConcreteNode = _require.RelayConcreteNode,
|
26
|
+
TYPENAME_KEY = _require.TYPENAME_KEY,
|
27
27
|
getModuleComponentKey = _require.getModuleComponentKey,
|
28
28
|
getModuleOperationKey = _require.getModuleOperationKey;
|
29
29
|
|
30
|
-
var
|
30
|
+
var ACTOR_CHANGE = RelayConcreteNode.ACTOR_CHANGE,
|
31
|
+
CLIENT_COMPONENT = RelayConcreteNode.CLIENT_COMPONENT,
|
31
32
|
CLIENT_EXTENSION = RelayConcreteNode.CLIENT_EXTENSION,
|
32
33
|
CONDITION = RelayConcreteNode.CONDITION,
|
33
34
|
CONNECTION = RelayConcreteNode.CONNECTION,
|
@@ -114,8 +115,7 @@ var RelayMockPayloadGenerator = /*#__PURE__*/function () {
|
|
114
115
|
function RelayMockPayloadGenerator(options) {
|
115
116
|
var _options$mockResolver, _options$selectionMet;
|
116
117
|
|
117
|
-
this._variables = options.variables; // $FlowFixMe[cannot-spread-
|
118
|
-
// $FlowFixMe[cannot-spread-inexact]
|
118
|
+
this._variables = options.variables; // $FlowFixMe[cannot-spread-inexact]
|
119
119
|
// $FlowFixMe[incompatible-type]
|
120
120
|
|
121
121
|
this._mockResolvers = (0, _objectSpread3["default"])((0, _objectSpread3["default"])({}, DEFAULT_MOCK_RESOLVERS), (_options$mockResolver = options.mockResolvers) !== null && _options$mockResolver !== void 0 ? _options$mockResolver : {});
|
@@ -326,6 +326,9 @@ var RelayMockPayloadGenerator = /*#__PURE__*/function () {
|
|
326
326
|
case FLIGHT_FIELD:
|
327
327
|
throw new Error('Flight fields are not yet supported.');
|
328
328
|
|
329
|
+
case ACTOR_CHANGE:
|
330
|
+
throw new Error('ActorChange fields are not yet supported.');
|
331
|
+
|
329
332
|
default:
|
330
333
|
selection;
|
331
334
|
!false ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayMockPayloadGenerator(): Unexpected AST kind `%s`.', selection.kind) : invariant(false) : void 0;
|
@@ -515,8 +518,7 @@ var RelayMockPayloadGenerator = /*#__PURE__*/function () {
|
|
515
518
|
;
|
516
519
|
|
517
520
|
_proto._getVariableValue = function _getVariableValue(name) {
|
518
|
-
!this._variables.hasOwnProperty(name) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayMockPayloadGenerator(): Undefined variable `%s`.', name) : invariant(false) : void 0;
|
519
|
-
|
521
|
+
!this._variables.hasOwnProperty(name) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayMockPayloadGenerator(): Undefined variable `%s`.', name) : invariant(false) : void 0;
|
520
522
|
return this._variables[name];
|
521
523
|
}
|
522
524
|
/**
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -20,12 +20,12 @@ var areEqual = require("fbjs/lib/areEqual");
|
|
20
20
|
var invariant = require('invariant');
|
21
21
|
|
22
22
|
var _require = require('relay-runtime'),
|
23
|
-
RecordSource = _require.RecordSource,
|
24
|
-
Store = _require.Store,
|
25
|
-
QueryResponseCache = _require.QueryResponseCache,
|
26
|
-
Observable = _require.Observable,
|
27
23
|
Environment = _require.Environment,
|
28
24
|
Network = _require.Network,
|
25
|
+
Observable = _require.Observable,
|
26
|
+
QueryResponseCache = _require.QueryResponseCache,
|
27
|
+
RecordSource = _require.RecordSource,
|
28
|
+
Store = _require.Store,
|
29
29
|
createOperationDescriptor = _require.createOperationDescriptor,
|
30
30
|
getRequest = _require.getRequest;
|
31
31
|
|
@@ -336,13 +336,19 @@ function createMockEnvironment(config) {
|
|
336
336
|
return fn.apply(env, argumentsList);
|
337
337
|
};
|
338
338
|
}; // $FlowExpectedError[cannot-write]
|
339
|
+
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
339
340
|
|
340
341
|
|
341
342
|
environment.execute = createExecuteProxy(environment, environment.execute); // $FlowExpectedError[cannot-write]
|
342
343
|
|
343
|
-
environment.
|
344
|
+
environment.executeSubscription = createExecuteProxy(environment, // $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
345
|
+
environment.executeSubscription); // $FlowExpectedError[cannot-write]
|
346
|
+
|
347
|
+
environment.executeWithSource = createExecuteProxy(environment, // $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
348
|
+
environment.executeWithSource); // $FlowExpectedError[cannot-write]
|
344
349
|
|
345
|
-
environment.executeMutation = createExecuteProxy(environment,
|
350
|
+
environment.executeMutation = createExecuteProxy(environment, // $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
351
|
+
environment.executeMutation);
|
346
352
|
|
347
353
|
if (((_global = global) === null || _global === void 0 ? void 0 : (_global$process = _global.process) === null || _global$process === void 0 ? void 0 : (_global$process$env = _global$process.env) === null || _global$process$env === void 0 ? void 0 : _global$process$env.NODE_ENV) === 'test') {
|
348
354
|
// Mock all the functions with their original behavior
|
@@ -354,6 +360,7 @@ function createMockEnvironment(config) {
|
|
354
360
|
mockDisposableMethod(environment, 'subscribe');
|
355
361
|
mockDisposableMethod(environment, 'retain');
|
356
362
|
mockObservableMethod(environment, 'execute');
|
363
|
+
mockObservableMethod(environment, 'executeSubscription');
|
357
364
|
mockObservableMethod(environment, 'executeWithSource');
|
358
365
|
mockObservableMethod(environment, 'executeMutation');
|
359
366
|
mockInstanceMethod(store, 'getSource');
|
@@ -394,20 +401,41 @@ function createMockEnvironment(config) {
|
|
394
401
|
environment.mock = mock; // $FlowExpectedError[cannot-write]
|
395
402
|
|
396
403
|
environment.mockClear = function () {
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
environment.
|
401
|
-
|
402
|
-
environment.
|
403
|
-
|
404
|
-
environment.
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
404
|
+
var _store$getSource$clea, _store$getSource;
|
405
|
+
|
406
|
+
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
407
|
+
environment.applyUpdate.mockClear(); // $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
408
|
+
|
409
|
+
environment.commitPayload.mockClear(); // $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
410
|
+
|
411
|
+
environment.getStore.mockClear(); // $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
412
|
+
|
413
|
+
environment.lookup.mockClear(); // $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
414
|
+
|
415
|
+
environment.check.mockClear(); // $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
416
|
+
|
417
|
+
environment.subscribe.mockClear(); // $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
418
|
+
|
419
|
+
environment.retain.mockClear(); // $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
420
|
+
|
421
|
+
environment.execute.mockClear(); // $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
422
|
+
|
423
|
+
environment.executeMutation.mockClear(); // $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
424
|
+
|
425
|
+
environment.executeSubscription.mockClear(); // $FlowExpectedError[prop-missing]
|
426
|
+
|
427
|
+
(_store$getSource$clea = (_store$getSource = store.getSource()).clear) === null || _store$getSource$clea === void 0 ? void 0 : _store$getSource$clea.call(_store$getSource); // $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
428
|
+
|
429
|
+
store.getSource.mockClear(); // $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
430
|
+
|
431
|
+
store.lookup.mockClear(); // $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
432
|
+
|
433
|
+
store.notify.mockClear(); // $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
434
|
+
|
435
|
+
store.publish.mockClear(); // $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
436
|
+
|
437
|
+
store.retain.mockClear(); // $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
438
|
+
|
411
439
|
store.subscribe.mockClear();
|
412
440
|
cache.clear();
|
413
441
|
pendingOperations = [];
|
@@ -0,0 +1,53 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
* @emails oncall+relay
|
8
|
+
* @format
|
9
|
+
*
|
10
|
+
*/
|
11
|
+
'use strict';
|
12
|
+
|
13
|
+
var ResolverFragments = require('relay-runtime/store/ResolverFragments');
|
14
|
+
/**
|
15
|
+
* Utility function for testing Relay Resolvers. Pass the resolver function and
|
16
|
+
* the data that will be returned from `readFragment` and it will return the
|
17
|
+
* value that the resolver would derive.
|
18
|
+
*
|
19
|
+
* *Note:* Relay fragment data includes a special `$fragmentType` key which is
|
20
|
+
* impossible for non-Relay code to construct. In tests you can work around
|
21
|
+
* this by passing `null` with a Flow supression:
|
22
|
+
*
|
23
|
+
* ```
|
24
|
+
* const fragmentData = {
|
25
|
+
* // Other fields here...
|
26
|
+
* $fragmentType: (null: any)
|
27
|
+
* };
|
28
|
+
*
|
29
|
+
* const actual = testResolver(resolverFunc, fragmentData);
|
30
|
+
* expect(actual).toEqual(expectedValue)
|
31
|
+
* ```
|
32
|
+
**/
|
33
|
+
|
34
|
+
|
35
|
+
function testResolver(resolver, // indexed_access is not yet enabled for this code base. Once it is, this can
|
36
|
+
// become: `Key['$data']`
|
37
|
+
fragmentData) {
|
38
|
+
var readFragment = ResolverFragments.readFragment; // a test utility, so... YOLO!!
|
39
|
+
|
40
|
+
ResolverFragments.readFragment = function () {
|
41
|
+
return fragmentData;
|
42
|
+
};
|
43
|
+
|
44
|
+
var result = resolver( // This will be ignored since we mock the function it gets passed to.
|
45
|
+
// $FlowFixMe
|
46
|
+
null);
|
47
|
+
ResolverFragments.readFragment = readFragment;
|
48
|
+
return result;
|
49
|
+
}
|
50
|
+
|
51
|
+
module.exports = {
|
52
|
+
testResolver: testResolver
|
53
|
+
};
|
package/lib/index.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -14,6 +14,8 @@ var RelayMockPayloadGenerator = require('./RelayMockPayloadGenerator');
|
|
14
14
|
|
15
15
|
var RelayModernMockEnvironment = require('./RelayModernMockEnvironment');
|
16
16
|
|
17
|
+
var testResolver = require('./RelayResolverTestUtils');
|
18
|
+
|
17
19
|
var unwrapContainer = require('./unwrapContainer');
|
18
20
|
|
19
21
|
/**
|
@@ -23,5 +25,6 @@ module.exports = {
|
|
23
25
|
MockEnvironment: RelayModernMockEnvironment,
|
24
26
|
MockPayloadGenerator: RelayMockPayloadGenerator,
|
25
27
|
createMockEnvironment: RelayModernMockEnvironment.createMockEnvironment,
|
26
|
-
unwrapContainer: unwrapContainer
|
28
|
+
unwrapContainer: unwrapContainer,
|
29
|
+
testResolver: testResolver
|
27
30
|
};
|
package/lib/unwrapContainer.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -9,10 +9,11 @@
|
|
9
9
|
'use strict';
|
10
10
|
|
11
11
|
var invariant = require('invariant');
|
12
|
-
|
13
12
|
/**
|
14
13
|
* Returns original component class wrapped by e.g. createFragmentContainer
|
15
14
|
*/
|
15
|
+
|
16
|
+
|
16
17
|
function unwrapContainer(ComponentClass) {
|
17
18
|
// $FlowExpectedError
|
18
19
|
var unwrapped = ComponentClass.__ComponentClass;
|
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": "13.0.0-rc.2",
|
5
5
|
"keywords": [
|
6
6
|
"graphql",
|
7
7
|
"relay"
|
@@ -12,12 +12,9 @@
|
|
12
12
|
"repository": "facebook/relay",
|
13
13
|
"dependencies": {
|
14
14
|
"@babel/runtime": "^7.0.0",
|
15
|
-
"fbjs": "^3.0.
|
15
|
+
"fbjs": "^3.0.2",
|
16
16
|
"invariant": "^2.2.4",
|
17
|
-
"relay-runtime": "
|
18
|
-
},
|
19
|
-
"peerDependencies": {
|
20
|
-
"graphql": "^15.0.0"
|
17
|
+
"relay-runtime": "13.0.0-rc.2"
|
21
18
|
},
|
22
19
|
"directories": {
|
23
20
|
"": "./"
|
package/relay-test-utils.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
/**
|
2
|
-
* Relay
|
2
|
+
* Relay v13.0.0-rc.2
|
3
3
|
*/
|
4
|
-
module.exports=function(e){var n={};function t(r){if(n[r])return n[r].exports;var a=n[r]={i:r,l:!1,exports:{}};return e[r].call(a.exports,a,a.exports,t),a.l=!0,a.exports}return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:r})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(t.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var a in e)t.d(r,a,function(n){return e[n]}.bind(null,a));return r},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="",t(t.s=4)}([function(e,n){e.exports=require("invariant")},function(e,n){e.exports=require("@babel/runtime/helpers/interopRequireDefault")},function(e,n){e.exports=require("@babel/runtime/helpers/objectSpread2")},function(e,n){e.exports=require("relay-runtime")},function(e,n,t){"use strict";var r=t(5),a=t(8),o=t(10);e.exports={MockEnvironment:a,MockPayloadGenerator:r,createMockEnvironment:a.createMockEnvironment,unwrapContainer:o}},function(e,n,t){"use strict";var r=t(1),a=r(t(6)),o=r(t(2)),l=r(t(7)),i=t(0),u=t(3),c=u.TYPENAME_KEY,s=u.RelayConcreteNode,f=u.getModuleComponentKey,p=u.getModuleOperationKey,d=s.CLIENT_COMPONENT,v=s.CLIENT_EXTENSION,m=s.CONDITION,y=s.CONNECTION,b=s.DEFER,k=s.FLIGHT_FIELD,h=s.FRAGMENT_SPREAD,g=s.INLINE_FRAGMENT,_=s.LINKED_FIELD,E=s.LINKED_HANDLE,A=s.MODULE_IMPORT,M=s.SCALAR_FIELD,S=s.SCALAR_HANDLE,C=s.STREAM,O=s.TYPE_DISCRIMINATOR;var x={ID:function(e,n){return"<".concat(null!=e.parentType&&e.parentType!==j?e.parentType+"-":"","mock-id-").concat(n(),">")},Boolean:function(){return!1},Int:function(){return 42},Float:function(){return 4.2}},j="__MockObject";function R(e,n,t,r){var a=arguments.length>4&&void 0!==arguments[4]&&arguments[4],o=arguments.length>5?arguments[5]:void 0,l=function(a){var o,l,i,u=null!=t&&null!=n?n[t]:null;(null!=u&&(o=u(r,e)),void 0===o)&&(o=null!=a?a:"ID"===t?x.ID(r,e):'<mock-value-for-field-"'.concat(null!==(l=null!==(i=r.alias)&&void 0!==i?i:r.name)&&void 0!==l?l:"undefined",'">'));return o};return!0===a?N(Array.isArray(o)?o:Array(1).fill(),l):l(o)}function N(e,n){return e.map((function(e){return n(e)}))}var T=function(){function e(e){var n,t,r,a,l;this._variables=e.variables,this._mockResolvers=(0,o.default)((0,o.default)({},x),null!==(n=e.mockResolvers)&&void 0!==n?n:{}),this._selectionMetadata=null!==(t=e.selectionMetadata)&&void 0!==t?t:{},this._resolveValue=(r=this._mockResolvers,a=0,l=function(){return++a},function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];return R.apply(void 0,[l,r].concat(n))})}var n=e.prototype;return n.generate=function(e,n){var t=this._getDefaultValuesForObject(n,null,null,[],{});return this._traverse({selections:e,typeName:n,isAbstractType:!1,name:null,alias:null,args:null},[],null,t)},n._traverse=function(e,n,t,r){var a=e.selections,o=e.typeName,l=e.isAbstractType;return this._traverseSelections(a,o,l,n,t,r)},n._traverseSelections=function(e,n,t,r,l,u){var s=this,x=null!=l?l:{};return e.forEach((function(e){switch(e.kind){case M:x=s._mockScalar(e,n,r,x,u);break;case y:x=s._traverseSelections([e.edges,e.pageInfo],n,t,r,l,u);break;case _:x=s._mockLink(e,r,x,u);break;case m:s._getVariableValue(e.condition)===e.passingValue&&(x=s._traverseSelections(e.selections,n,t,r,x,u));break;case b:case C:x=s._traverseSelections(e.selections,n,t,r,x,u);break;case d:case h:x=s._traverseSelections(e.fragment.selections,n,t,r,x,u);break;case g:var R,N=e.abstractKey;if(null!=N){null!=x&&(x[N]=!0),x=s._traverseSelections(e.selections,n,t,r,x,u);break}if(null!=x&&(null==x[c]||x[c]===j))x[c]=null!==(R=null==u?void 0:u[c])&&void 0!==R?R:e.type;if(!0===t&&null!=x&&x[c]===n&&(x[c]=e.type),null!=x&&x[c]===e.type){var T=s._getDefaultValuesForObject(e.type,r[r.length-1],null,r),q=n!==e.type?s._getDefaultValuesForObject(n,r[r.length-1],null,r):T,V=T;if(void 0===V&&(V=q),void 0===V&&(V=u),null===V){x=null;break}null!=(x=s._traverseSelections(e.selections,e.type,t,r,x,V))[c]&&(x[c]=e.type),null!=x.id&&null!=T&&null!=T.id&&(x.id=T.id)}break;case A:if(null!=u){var D;if(u.__typename!==n)break;var w=u.__module_operation;"object"==typeof w&&null!==w&&"SplitOperation"===w.kind&&Array.isArray(w.selections)&&"string"==typeof w.name||i(!1,'RelayMockPayloadGenerator(): Unexpected default value for a field `__module_operation` in the mock resolver for @module dependency. Provided value is "%s" and we\'re expecting an object of a type `NormalizationSplitOperation`. Please adjust mock resolver for the type "%s". Typically it should require a file "%s$normalization.graphql".',JSON.stringify(w),n,e.fragmentName);var I=w,P=e.documentName;null==x&&(x={}),x=(0,o.default)((0,o.default)({},x),{},(D={},(0,a.default)(D,c,n),(0,a.default)(D,p(P),w.name),(0,a.default)(D,f(P),u.__module_component),D),s._traverseSelections(I.selections,n,!1,r,null,null))}break;case v:break;case O:var F=e.abstractKey;null!=x&&(x[F]=!0);break;case S:case E:break;case k:throw new Error("Flight fields are not yet supported.");default:i(!1,"RelayMockPayloadGenerator(): Unexpected AST kind `%s`.",e.kind)}})),x},n._getCorrectDefaultEnum=function(e,n,t,r){if(void 0===n)return n;if(null===n)return n;var a=Array.isArray(n)?n.map((function(e){return String(e).toUpperCase()})):[String(n).toUpperCase()],o=e.map((function(e){return e.toUpperCase()}));a.filter((function(e){return o.includes(e)})).length!==a.length&&i(!1,'RelayMockPayloadGenerator: Invalid value "%s" provided for enum field "%s" via MockResolver.Expected one of the following values: %s.',n,"".concat(t.join("."),".").concat(r),e.map((function(e){return'"'.concat(e,'"')})).join(", "));var l=a.map((function(n){var t=o.indexOf(String(n).toUpperCase());return e[t]}));return Array.isArray(n)?l:l[0]},n._mockScalar=function(e,n,t,r,a){var o,i,u=null!=r?r:{},s=null!==(o=e.alias)&&void 0!==o?o:e.name;if(u.hasOwnProperty(s)&&e.name!==c)return u;e.name===c&&(i=null!=n?n:j);var f=[].concat((0,l.default)(t),[s]),p=this._getScalarFieldTypeDetails(e,n,f),d=p.type,v=p.plural,m=p.enumValues;if(null!=a&&a.hasOwnProperty(s)&&(i=a[s],null!=m&&(i=this._getCorrectDefaultEnum(m,i,t,s)),void 0!==i&&v&&!Array.isArray(i)&&(i=[i])),void 0===i){var y=null!=m?m[0]:void 0;i=this._resolveValue(d,{parentType:n,name:e.name,alias:e.alias,path:f,args:this._getFieldArgs(e)},v,y)}return u[s]=i,u},n._mockLink=function(e,n,t,r){var a,o,i,u,s=this,f=null!==(a=e.alias)&&void 0!==a?a:e.name,p=null!=t?t:{},d=this._getFieldArgs(e),v=[].concat((0,l.default)(n),[f]),m=null!==(o=this._selectionMetadata[v.join(".")])&&void 0!==o?o:{type:j};if(null!=r&&"object"==typeof r[f]&&(u=r[f]),null===u)return p[f]=null,p;var y=null!==(i=e.concreteType)&&void 0!==i?i:null!=u&&"string"==typeof u[c]?u[c]:m.type,b=null===e.concreteType&&y===m.type,k=function(t){var r,a,o=null!==(r=s._getDefaultValuesForObject(null!==(a=e.concreteType)&&void 0!==a?a:m.type,e.name,e.alias,v,d))&&void 0!==r?r:t;return null===o?null:s._traverse({selections:e.selections,typeName:y,isAbstractType:b,name:e.name,alias:e.alias,args:d},[].concat((0,l.default)(n),[f]),"object"==typeof p[f]?p[f]:null,o)};return p[f]="LinkedField"===e.kind&&e.plural?N(Array.isArray(u)?u:Array(1).fill(),k):k(u),p},n._getVariableValue=function(e){return this._variables.hasOwnProperty(e)||i(!1,"RelayMockPayloadGenerator(): Undefined variable `%s`.",e),this._variables[e]},n._getDefaultValuesForObject=function(e,n,t,r,a){var o;if(null!=e&&null!=this._mockResolvers[e]&&(o=this._resolveValue(e,{parentType:null,name:n,alias:t,args:a,path:r},!1)),"object"==typeof o)return o},n._getFieldArgs=function(e){var n=this,t={};return null!=e.args&&e.args.forEach((function(e){t[e.name]=n._getArgValue(e)})),t},n._getArgValue=function(e){var n=this;switch(e.kind){case"Literal":return e.value;case"Variable":return this._getVariableValue(e.variableName);case"ObjectValue":var t={};return e.fields.forEach((function(e){t[e.name]=n._getArgValue(e)})),t;case"ListValue":var r=[];return e.items.forEach((function(e){r.push(null!=e?n._getArgValue(e):null)})),r}},n._getScalarFieldTypeDetails=function(e,n,t){var r;return null!==(r=this._selectionMetadata[t.join(".")])&&void 0!==r?r:{type:"id"===e.name?"ID":"String",plural:!1,enumValues:null,nullable:!1}},e}();e.exports={generate:function(e,n){return{data:function(e,n,t,r){var a,o=new T({variables:n,mockResolvers:t,selectionMetadata:r});return a=e.name.endsWith("Mutation")?"Mutation":e.name.endsWith("Subscription")?"Subscription":"Query",o.generate(e.selections,a)}(e.request.node.operation,e.request.variables,null!=n?n:null,function(e){var n,t=null===(n=e.request.node.params.metadata)||void 0===n?void 0:n.relayTestingSelectionTypeInfo;if(null!=t&&!Array.isArray(t)&&"object"==typeof t){var r={};return Object.keys(t).forEach((function(e){var n=t[e];null==n||Array.isArray(n)||"object"!=typeof n||"string"!=typeof n.type||"boolean"!=typeof n.plural||"boolean"!=typeof n.nullable||null!==n.enumValues&&!Array.isArray(n.enumValues)||(r[e]={type:n.type,plural:n.plural,nullable:n.nullable,enumValues:Array.isArray(n.enumValues)?n.enumValues.map(String):null})})),r}return null}(e))}}}},function(e,n){e.exports=require("@babel/runtime/helpers/defineProperty")},function(e,n){e.exports=require("@babel/runtime/helpers/toConsumableArray")},function(e,n,t){"use strict";var r=t(1)(t(2)),a=t(9),o=t(0),l=t(3),i=l.RecordSource,u=l.Store,c=l.QueryResponseCache,s=l.Observable,f=l.Environment,p=l.Network,d=l.createOperationDescriptor,v=l.getRequest;function m(e,n){e[n]=jest.fn(e[n].bind(e))}function y(e,n){var t=e[n].bind(e);e[n]=jest.fn((function(){for(var r=arguments.length,a=new Array(r),o=0;o<r;o++)a[o]=arguments[o];var l=t.apply(void 0,a),i=jest.fn((function(){return l.dispose()}));return e[n].mock.dispose=i,{dispose:i}}));var r=e[n].mockClear.bind(e[n]);e[n].mockClear=function(){r(),e[n].mock.dispose=null}}function b(e,n){var t=e[n].bind(e),r=[];e[n]=jest.fn((function(){for(var e=arguments.length,n=new Array(e),a=0;a<e;a++)n[a]=arguments[a];return t.apply(void 0,n).do({start:function(e){r.push(e)}})})),e[n].mock.subscriptions=r;var a=e[n].mockClear.bind(e[n]);e[n].mockClear=function(){a(),e[n].mock.subscriptions=[]}}e.exports={createMockEnvironment:function(e){var n,t,l,k,h=null!==(n=null==e?void 0:e.store)&&void 0!==n?n:new u(new i),g=new c({size:10,ttl:3e5}),_=[],E=[],A=[],M=function(e,n,t){var r=e.id,o=e.text,l=null!=r?r:o,i=null;if(null!=(null==t?void 0:t.force)&&!1!==(null==t?void 0:t.force)||null==l||(i=g.get(l,n)),null!==i)return s.from(i);var u=E.find((function(t){return t.request.node.params===e&&a(t.request.variables,n)}));if(null!=u&&A.length>0){var c=A[0],f=c(u);if(null!=f)return A=A.filter((function(e){return e!==c})),E=E.filter((function(e){return e!==u})),f instanceof Error?s.create((function(e){e.error(f)})):s.from(f)}return s.create((function(r){var o={request:e,variables:n,cacheConfig:t,sink:r};return _=_.concat([o]),function(){_=_.filter((function(e){return!a(e,o)})),E=E.filter((function(e){return e!==u}))}}))};function S(e){if("Request"===e.kind)return e;var n=e;return E.includes(n)||o(!1,'RelayModernMockEnvironment: Operation "%s" was not found in the list of pending operations',n.request.node.operation.name),n.request.node}function C(e){var n,t;n="Request"===e.kind?e:(t=e).request.node;var r=_.filter((function(e){return!!a(e.request,n.params)&&(!t||a(t.request.variables,e.variables))}));return r.length||o(!1,"MockEnvironment: Cannot respond to request, it has not been requested yet."),r.forEach((function(e){e.sink||o(!1,"MockEnvironment: Cannot respond to `%s`, it has not been requested yet.",n.params.name)})),r}function O(e){return"object"==typeof e&&null!==e&&e.hasOwnProperty("data")||o(!1,"MockEnvironment(): Expected payload to be an object with a `data` key."),e}var x=function(e,n){var t="string"==typeof n?new Error(n):n;C(e).forEach((function(e){var n=e.sink;null===n&&o(!1,"Sink should be defined."),n.error(t)}))},j=function(e,n){C(e).forEach((function(e){var t=e.sink;null===t&&o(!1,"Sink should be defined."),t.next(O(n)),t.complete()}))},R=function(){var e=E[E.length-1];return null==e&&o(!1,"RelayModernMockEnvironment: There are no pending operations in the list"),e},N=new f((0,r.default)({configName:"RelayModernMockEnvironment",network:p.create(M,M),store:h},e)),T=function(e,n){return function(){for(var t=arguments.length,r=new Array(t),a=0;a<t;a++)r[a]=arguments[a];var o=r[0].operation;return E=E.concat([o]),n.apply(e,r)}};N.execute=T(N,N.execute),N.executeWithSource=T(N,N.executeWithSource),N.executeMutation=T(N,N.executeMutation),"test"===(null===(t=global)||void 0===t||null===(l=t.process)||void 0===l||null===(k=l.env)||void 0===k?void 0:k.NODE_ENV)&&(y(N,"applyUpdate"),m(N,"commitPayload"),m(N,"getStore"),m(N,"lookup"),m(N,"check"),y(N,"subscribe"),y(N,"retain"),b(N,"execute"),b(N,"executeWithSource"),b(N,"executeMutation"),m(h,"getSource"),m(h,"lookup"),m(h,"notify"),m(h,"publish"),y(h,"retain"),y(h,"subscribe"));var q={cachePayload:function(e,n,t){var r=S(e).params,a=r.id,l=r.text,i=null!=a?a:l;null==i&&o(!1,"CacheID should not be null"),g.set(i,n,t)},clearCache:function(){g.clear()},isLoading:function(e,n,t){return _.some((function(r){return a(r.request,S(e).params)&&a(r.variables,n)&&a(r.cacheConfig,null!=t?t:{})}))},reject:x,resolve:j,nextValue:function(e,n){C(e).forEach((function(e){var t=e.sink;null===t&&o(!1,"Sink should be defined."),t.next(O(n))}))},complete:function(e){C(e).forEach((function(e){var n=e.sink;null===n&&o(!1,"Sink should be defined."),n.complete()}))},getMostRecentOperation:R,resolveMostRecentOperation:function(e){var n=R(),t="function"==typeof e?e(n):e;return j(n,t)},rejectMostRecentOperation:function(e){var n=R(),t="function"==typeof e?e(n):e;return x(n,t)},findOperation:function(e){var n=E.find(e);return null==n&&o(!1,"RelayModernMockEnvironment: Operation was not found in the list of pending operations"),n},queuePendingOperation:function(e,n){var t=d(v(e),n);E=E.concat([t])},getAllOperations:function(){return E},queueOperationResolver:function(e){A=A.concat([e])}};return N.mock=q,N.mockClear=function(){N.applyUpdate.mockClear(),N.commitPayload.mockClear(),N.getStore.mockClear(),N.lookup.mockClear(),N.check.mockClear(),N.subscribe.mockClear(),N.retain.mockClear(),N.execute.mockClear(),N.executeMutation.mockClear(),h.getSource.mockClear(),h.lookup.mockClear(),h.notify.mockClear(),h.publish.mockClear(),h.retain.mockClear(),h.subscribe.mockClear(),g.clear(),E=[],_=[]},N}}},function(e,n){e.exports=require("fbjs/lib/areEqual")},function(e,n,t){"use strict";var r=t(0);e.exports=function(e){var n=e.__ComponentClass;return null==n&&r(!1,"Could not find component for %s, is it a Relay container?",e.displayName||e.name),n}}]);
|
4
|
+
module.exports=function(e){var n={};function t(r){if(n[r])return n[r].exports;var a=n[r]={i:r,l:!1,exports:{}};return e[r].call(a.exports,a,a.exports,t),a.l=!0,a.exports}return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:r})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(t.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var a in e)t.d(r,a,function(n){return e[n]}.bind(null,a));return r},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="",t(t.s=4)}([function(e,n){e.exports=require("invariant")},function(e,n){e.exports=require("@babel/runtime/helpers/interopRequireDefault")},function(e,n){e.exports=require("@babel/runtime/helpers/objectSpread2")},function(e,n){e.exports=require("relay-runtime")},function(e,n,t){"use strict";var r=t(5),a=t(8),o=t(10),l=t(12);e.exports={MockEnvironment:a,MockPayloadGenerator:r,createMockEnvironment:a.createMockEnvironment,unwrapContainer:l,testResolver:o}},function(e,n,t){"use strict";var r=t(1),a=r(t(6)),o=r(t(2)),l=r(t(7)),i=t(0),u=t(3),c=u.RelayConcreteNode,s=u.TYPENAME_KEY,f=u.getModuleComponentKey,p=u.getModuleOperationKey,d=c.ACTOR_CHANGE,v=c.CLIENT_COMPONENT,m=c.CLIENT_EXTENSION,y=c.CONDITION,b=c.CONNECTION,k=c.DEFER,g=c.FLIGHT_FIELD,h=c.FRAGMENT_SPREAD,_=c.INLINE_FRAGMENT,E=c.LINKED_FIELD,S=c.LINKED_HANDLE,A=c.MODULE_IMPORT,C=c.SCALAR_FIELD,M=c.SCALAR_HANDLE,O=c.STREAM,x=c.TYPE_DISCRIMINATOR;var R={ID:function(e,n){return"<".concat(null!=e.parentType&&e.parentType!==j?e.parentType+"-":"","mock-id-").concat(n(),">")},Boolean:function(){return!1},Int:function(){return 42},Float:function(){return 4.2}},j="__MockObject";function N(e,n,t,r){var a=arguments.length>4&&void 0!==arguments[4]&&arguments[4],o=arguments.length>5?arguments[5]:void 0,l=function(a){var o,l,i,u=null!=t&&null!=n?n[t]:null;(null!=u&&(o=u(r,e)),void 0===o)&&(o=null!=a?a:"ID"===t?R.ID(r,e):'<mock-value-for-field-"'.concat(null!==(l=null!==(i=r.alias)&&void 0!==i?i:r.name)&&void 0!==l?l:"undefined",'">'));return o};return!0===a?T(Array.isArray(o)?o:Array(1).fill(),l):l(o)}function T(e,n){return e.map((function(e){return n(e)}))}var q=function(){function e(e){var n,t,r,a,l;this._variables=e.variables,this._mockResolvers=(0,o.default)((0,o.default)({},R),null!==(n=e.mockResolvers)&&void 0!==n?n:{}),this._selectionMetadata=null!==(t=e.selectionMetadata)&&void 0!==t?t:{},this._resolveValue=(r=this._mockResolvers,a=0,l=function(){return++a},function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];return N.apply(void 0,[l,r].concat(n))})}var n=e.prototype;return n.generate=function(e,n){var t=this._getDefaultValuesForObject(n,null,null,[],{});return this._traverse({selections:e,typeName:n,isAbstractType:!1,name:null,alias:null,args:null},[],null,t)},n._traverse=function(e,n,t,r){var a=e.selections,o=e.typeName,l=e.isAbstractType;return this._traverseSelections(a,o,l,n,t,r)},n._traverseSelections=function(e,n,t,r,l,u){var c=this,R=null!=l?l:{};return e.forEach((function(e){switch(e.kind){case C:R=c._mockScalar(e,n,r,R,u);break;case b:R=c._traverseSelections([e.edges,e.pageInfo],n,t,r,l,u);break;case E:R=c._mockLink(e,r,R,u);break;case y:c._getVariableValue(e.condition)===e.passingValue&&(R=c._traverseSelections(e.selections,n,t,r,R,u));break;case k:case O:R=c._traverseSelections(e.selections,n,t,r,R,u);break;case v:case h:R=c._traverseSelections(e.fragment.selections,n,t,r,R,u);break;case _:var N,T=e.abstractKey;if(null!=T){null!=R&&(R[T]=!0),R=c._traverseSelections(e.selections,n,t,r,R,u);break}if(null!=R&&(null==R[s]||R[s]===j))R[s]=null!==(N=null==u?void 0:u[s])&&void 0!==N?N:e.type;if(!0===t&&null!=R&&R[s]===n&&(R[s]=e.type),null!=R&&R[s]===e.type){var q=c._getDefaultValuesForObject(e.type,r[r.length-1],null,r),V=n!==e.type?c._getDefaultValuesForObject(n,r[r.length-1],null,r):q,w=q;if(void 0===w&&(w=V),void 0===w&&(w=u),null===w){R=null;break}null!=(R=c._traverseSelections(e.selections,e.type,t,r,R,w))[s]&&(R[s]=e.type),null!=R.id&&null!=q&&null!=q.id&&(R.id=q.id)}break;case A:if(null!=u){var D;if(u.__typename!==n)break;var I=u.__module_operation;"object"==typeof I&&null!==I&&"SplitOperation"===I.kind&&Array.isArray(I.selections)&&"string"==typeof I.name||i(!1,'RelayMockPayloadGenerator(): Unexpected default value for a field `__module_operation` in the mock resolver for @module dependency. Provided value is "%s" and we\'re expecting an object of a type `NormalizationSplitOperation`. Please adjust mock resolver for the type "%s". Typically it should require a file "%s$normalization.graphql".',JSON.stringify(I),n,e.fragmentName);var P=I,F=e.documentName;null==R&&(R={}),R=(0,o.default)((0,o.default)({},R),{},(D={},(0,a.default)(D,s,n),(0,a.default)(D,p(F),I.name),(0,a.default)(D,f(F),u.__module_component),D),c._traverseSelections(P.selections,n,!1,r,null,null))}break;case m:break;case x:var L=e.abstractKey;null!=R&&(R[L]=!0);break;case M:case S:break;case g:throw new Error("Flight fields are not yet supported.");case d:throw new Error("ActorChange fields are not yet supported.");default:i(!1,"RelayMockPayloadGenerator(): Unexpected AST kind `%s`.",e.kind)}})),R},n._getCorrectDefaultEnum=function(e,n,t,r){if(void 0===n)return n;if(null===n)return n;var a=Array.isArray(n)?n.map((function(e){return String(e).toUpperCase()})):[String(n).toUpperCase()],o=e.map((function(e){return e.toUpperCase()}));a.filter((function(e){return o.includes(e)})).length!==a.length&&i(!1,'RelayMockPayloadGenerator: Invalid value "%s" provided for enum field "%s" via MockResolver.Expected one of the following values: %s.',n,"".concat(t.join("."),".").concat(r),e.map((function(e){return'"'.concat(e,'"')})).join(", "));var l=a.map((function(n){var t=o.indexOf(String(n).toUpperCase());return e[t]}));return Array.isArray(n)?l:l[0]},n._mockScalar=function(e,n,t,r,a){var o,i,u=null!=r?r:{},c=null!==(o=e.alias)&&void 0!==o?o:e.name;if(u.hasOwnProperty(c)&&e.name!==s)return u;e.name===s&&(i=null!=n?n:j);var f=[].concat((0,l.default)(t),[c]),p=this._getScalarFieldTypeDetails(e,n,f),d=p.type,v=p.plural,m=p.enumValues;if(null!=a&&a.hasOwnProperty(c)&&(i=a[c],null!=m&&(i=this._getCorrectDefaultEnum(m,i,t,c)),void 0!==i&&v&&!Array.isArray(i)&&(i=[i])),void 0===i){var y=null!=m?m[0]:void 0;i=this._resolveValue(d,{parentType:n,name:e.name,alias:e.alias,path:f,args:this._getFieldArgs(e)},v,y)}return u[c]=i,u},n._mockLink=function(e,n,t,r){var a,o,i,u,c=this,f=null!==(a=e.alias)&&void 0!==a?a:e.name,p=null!=t?t:{},d=this._getFieldArgs(e),v=[].concat((0,l.default)(n),[f]),m=null!==(o=this._selectionMetadata[v.join(".")])&&void 0!==o?o:{type:j};if(null!=r&&"object"==typeof r[f]&&(u=r[f]),null===u)return p[f]=null,p;var y=null!==(i=e.concreteType)&&void 0!==i?i:null!=u&&"string"==typeof u[s]?u[s]:m.type,b=null===e.concreteType&&y===m.type,k=function(t){var r,a,o=null!==(r=c._getDefaultValuesForObject(null!==(a=e.concreteType)&&void 0!==a?a:m.type,e.name,e.alias,v,d))&&void 0!==r?r:t;return null===o?null:c._traverse({selections:e.selections,typeName:y,isAbstractType:b,name:e.name,alias:e.alias,args:d},[].concat((0,l.default)(n),[f]),"object"==typeof p[f]?p[f]:null,o)};return p[f]="LinkedField"===e.kind&&e.plural?T(Array.isArray(u)?u:Array(1).fill(),k):k(u),p},n._getVariableValue=function(e){return this._variables.hasOwnProperty(e)||i(!1,"RelayMockPayloadGenerator(): Undefined variable `%s`.",e),this._variables[e]},n._getDefaultValuesForObject=function(e,n,t,r,a){var o;if(null!=e&&null!=this._mockResolvers[e]&&(o=this._resolveValue(e,{parentType:null,name:n,alias:t,args:a,path:r},!1)),"object"==typeof o)return o},n._getFieldArgs=function(e){var n=this,t={};return null!=e.args&&e.args.forEach((function(e){t[e.name]=n._getArgValue(e)})),t},n._getArgValue=function(e){var n=this;switch(e.kind){case"Literal":return e.value;case"Variable":return this._getVariableValue(e.variableName);case"ObjectValue":var t={};return e.fields.forEach((function(e){t[e.name]=n._getArgValue(e)})),t;case"ListValue":var r=[];return e.items.forEach((function(e){r.push(null!=e?n._getArgValue(e):null)})),r}},n._getScalarFieldTypeDetails=function(e,n,t){var r;return null!==(r=this._selectionMetadata[t.join(".")])&&void 0!==r?r:{type:"id"===e.name?"ID":"String",plural:!1,enumValues:null,nullable:!1}},e}();e.exports={generate:function(e,n){return{data:function(e,n,t,r){var a,o=new q({variables:n,mockResolvers:t,selectionMetadata:r});return a=e.name.endsWith("Mutation")?"Mutation":e.name.endsWith("Subscription")?"Subscription":"Query",o.generate(e.selections,a)}(e.request.node.operation,e.request.variables,null!=n?n:null,function(e){var n,t=null===(n=e.request.node.params.metadata)||void 0===n?void 0:n.relayTestingSelectionTypeInfo;if(null!=t&&!Array.isArray(t)&&"object"==typeof t){var r={};return Object.keys(t).forEach((function(e){var n=t[e];null==n||Array.isArray(n)||"object"!=typeof n||"string"!=typeof n.type||"boolean"!=typeof n.plural||"boolean"!=typeof n.nullable||null!==n.enumValues&&!Array.isArray(n.enumValues)||(r[e]={type:n.type,plural:n.plural,nullable:n.nullable,enumValues:Array.isArray(n.enumValues)?n.enumValues.map(String):null})})),r}return null}(e))}}}},function(e,n){e.exports=require("@babel/runtime/helpers/defineProperty")},function(e,n){e.exports=require("@babel/runtime/helpers/toConsumableArray")},function(e,n,t){"use strict";var r=t(1)(t(2)),a=t(9),o=t(0),l=t(3),i=l.Environment,u=l.Network,c=l.Observable,s=l.QueryResponseCache,f=l.RecordSource,p=l.Store,d=l.createOperationDescriptor,v=l.getRequest;function m(e,n){e[n]=jest.fn(e[n].bind(e))}function y(e,n){var t=e[n].bind(e);e[n]=jest.fn((function(){for(var r=arguments.length,a=new Array(r),o=0;o<r;o++)a[o]=arguments[o];var l=t.apply(void 0,a),i=jest.fn((function(){return l.dispose()}));return e[n].mock.dispose=i,{dispose:i}}));var r=e[n].mockClear.bind(e[n]);e[n].mockClear=function(){r(),e[n].mock.dispose=null}}function b(e,n){var t=e[n].bind(e),r=[];e[n]=jest.fn((function(){for(var e=arguments.length,n=new Array(e),a=0;a<e;a++)n[a]=arguments[a];return t.apply(void 0,n).do({start:function(e){r.push(e)}})})),e[n].mock.subscriptions=r;var a=e[n].mockClear.bind(e[n]);e[n].mockClear=function(){a(),e[n].mock.subscriptions=[]}}e.exports={createMockEnvironment:function(e){var n,t,l,k,g=null!==(n=null==e?void 0:e.store)&&void 0!==n?n:new p(new f),h=new s({size:10,ttl:3e5}),_=[],E=[],S=[],A=function(e,n,t){var r=e.id,o=e.text,l=null!=r?r:o,i=null;if(null!=(null==t?void 0:t.force)&&!1!==(null==t?void 0:t.force)||null==l||(i=h.get(l,n)),null!==i)return c.from(i);var u=E.find((function(t){return t.request.node.params===e&&a(t.request.variables,n)}));if(null!=u&&S.length>0){var s=S[0],f=s(u);if(null!=f)return S=S.filter((function(e){return e!==s})),E=E.filter((function(e){return e!==u})),f instanceof Error?c.create((function(e){e.error(f)})):c.from(f)}return c.create((function(r){var o={request:e,variables:n,cacheConfig:t,sink:r};return _=_.concat([o]),function(){_=_.filter((function(e){return!a(e,o)})),E=E.filter((function(e){return e!==u}))}}))};function C(e){if("Request"===e.kind)return e;var n=e;return E.includes(n)||o(!1,'RelayModernMockEnvironment: Operation "%s" was not found in the list of pending operations',n.request.node.operation.name),n.request.node}function M(e){var n,t;n="Request"===e.kind?e:(t=e).request.node;var r=_.filter((function(e){return!!a(e.request,n.params)&&(!t||a(t.request.variables,e.variables))}));return r.length||o(!1,"MockEnvironment: Cannot respond to request, it has not been requested yet."),r.forEach((function(e){e.sink||o(!1,"MockEnvironment: Cannot respond to `%s`, it has not been requested yet.",n.params.name)})),r}function O(e){return"object"==typeof e&&null!==e&&e.hasOwnProperty("data")||o(!1,"MockEnvironment(): Expected payload to be an object with a `data` key."),e}var x=function(e,n){var t="string"==typeof n?new Error(n):n;M(e).forEach((function(e){var n=e.sink;null===n&&o(!1,"Sink should be defined."),n.error(t)}))},R=function(e,n){M(e).forEach((function(e){var t=e.sink;null===t&&o(!1,"Sink should be defined."),t.next(O(n)),t.complete()}))},j=function(){var e=E[E.length-1];return null==e&&o(!1,"RelayModernMockEnvironment: There are no pending operations in the list"),e},N=new i((0,r.default)({configName:"RelayModernMockEnvironment",network:u.create(A,A),store:g},e)),T=function(e,n){return function(){for(var t=arguments.length,r=new Array(t),a=0;a<t;a++)r[a]=arguments[a];var o=r[0].operation;return E=E.concat([o]),n.apply(e,r)}};N.execute=T(N,N.execute),N.executeSubscription=T(N,N.executeSubscription),N.executeWithSource=T(N,N.executeWithSource),N.executeMutation=T(N,N.executeMutation),"test"===(null===(t=global)||void 0===t||null===(l=t.process)||void 0===l||null===(k=l.env)||void 0===k?void 0:k.NODE_ENV)&&(y(N,"applyUpdate"),m(N,"commitPayload"),m(N,"getStore"),m(N,"lookup"),m(N,"check"),y(N,"subscribe"),y(N,"retain"),b(N,"execute"),b(N,"executeSubscription"),b(N,"executeWithSource"),b(N,"executeMutation"),m(g,"getSource"),m(g,"lookup"),m(g,"notify"),m(g,"publish"),y(g,"retain"),y(g,"subscribe"));var q={cachePayload:function(e,n,t){var r=C(e).params,a=r.id,l=r.text,i=null!=a?a:l;null==i&&o(!1,"CacheID should not be null"),h.set(i,n,t)},clearCache:function(){h.clear()},isLoading:function(e,n,t){return _.some((function(r){return a(r.request,C(e).params)&&a(r.variables,n)&&a(r.cacheConfig,null!=t?t:{})}))},reject:x,resolve:R,nextValue:function(e,n){M(e).forEach((function(e){var t=e.sink;null===t&&o(!1,"Sink should be defined."),t.next(O(n))}))},complete:function(e){M(e).forEach((function(e){var n=e.sink;null===n&&o(!1,"Sink should be defined."),n.complete()}))},getMostRecentOperation:j,resolveMostRecentOperation:function(e){var n=j(),t="function"==typeof e?e(n):e;return R(n,t)},rejectMostRecentOperation:function(e){var n=j(),t="function"==typeof e?e(n):e;return x(n,t)},findOperation:function(e){var n=E.find(e);return null==n&&o(!1,"RelayModernMockEnvironment: Operation was not found in the list of pending operations"),n},queuePendingOperation:function(e,n){var t=d(v(e),n);E=E.concat([t])},getAllOperations:function(){return E},queueOperationResolver:function(e){S=S.concat([e])}};return N.mock=q,N.mockClear=function(){var e,n;N.applyUpdate.mockClear(),N.commitPayload.mockClear(),N.getStore.mockClear(),N.lookup.mockClear(),N.check.mockClear(),N.subscribe.mockClear(),N.retain.mockClear(),N.execute.mockClear(),N.executeMutation.mockClear(),N.executeSubscription.mockClear(),null===(e=(n=g.getSource()).clear)||void 0===e||e.call(n),g.getSource.mockClear(),g.lookup.mockClear(),g.notify.mockClear(),g.publish.mockClear(),g.retain.mockClear(),g.subscribe.mockClear(),h.clear(),E=[],_=[]},N}}},function(e,n){e.exports=require("fbjs/lib/areEqual")},function(e,n,t){"use strict";var r=t(11);e.exports={testResolver:function(e,n){var t=r.readFragment;r.readFragment=function(){return n};var a=e(null);return r.readFragment=t,a}}},function(e,n){e.exports=require("relay-runtime/store/ResolverFragments")},function(e,n,t){"use strict";var r=t(0);e.exports=function(e){var n=e.__ComponentClass;return null==n&&r(!1,"Could not find component for %s, is it a Relay container?",e.displayName||e.name),n}}]);
|
package/relay-test-utils.min.js
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
/**
|
2
|
-
* Relay
|
2
|
+
* Relay v13.0.0-rc.2
|
3
3
|
*
|
4
4
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
5
5
|
*
|
6
6
|
* This source code is licensed under the MIT license found in the
|
7
7
|
* LICENSE file in the root directory of this source tree.
|
8
8
|
*/
|
9
|
-
module.exports=function(e){var n={};function r(t){if(n[t])return n[t].exports;var a=n[t]={i:t,l:!1,exports:{}};return e[t].call(a.exports,a,a.exports,r),a.l=!0,a.exports}return r.m=e,r.c=n,r.d=function(e,n,t){r.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:t})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,n){if(1&n&&(e=r(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(r.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var a in e)r.d(t,a,function(n){return e[n]}.bind(null,a));return t},r.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(n,"a",n),n},r.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},r.p="",r(r.s=4)}([function(e,n){e.exports=require("invariant")},function(e,n){e.exports=require("@babel/runtime/helpers/interopRequireDefault")},function(e,n){e.exports=require("@babel/runtime/helpers/objectSpread2")},function(e,n){e.exports=require("relay-runtime")},function(e,n,r){"use strict";var t=r(5),a=r(8),l=r(10);e.exports={MockEnvironment:a,MockPayloadGenerator:t,createMockEnvironment:a.createMockEnvironment,unwrapContainer:l}},function(e,n,r){"use strict";var t=r(1),a=t(r(6)),l=t(r(2)),o=t(r(7)),u=r(0),i=r(3),c=i.TYPENAME_KEY,s=i.RelayConcreteNode,f=i.getModuleComponentKey,p=i.getModuleOperationKey,v=s.CLIENT_COMPONENT,d=s.CLIENT_EXTENSION,m=s.CONDITION,y=s.CONNECTION,b=s.DEFER,g=s.FLIGHT_FIELD,k=s.FRAGMENT_SPREAD,h=s.INLINE_FRAGMENT,_=s.LINKED_FIELD,A=s.LINKED_HANDLE,E=s.MODULE_IMPORT,C=s.SCALAR_FIELD,S=s.SCALAR_HANDLE,O=s.STREAM,M=s.TYPE_DISCRIMINATOR;var x={ID:function(e,n){return"<".concat(null!=e.parentType&&e.parentType!==j?e.parentType+"-":"","mock-id-").concat(n(),">")},Boolean:function(){return!1},Int:function(){return 42},Float:function(){return 4.2}},j="__MockObject";function N(e,n,r,t){var a=arguments.length>4&&void 0!==arguments[4]&&arguments[4],l=arguments.length>5?arguments[5]:void 0,o=function(a){var l,o,u,i=null!=r&&null!=n?n[r]:null;(null!=i&&(l=i(t,e)),void 0===l)&&(l=null!=a?a:"ID"===r?x.ID(t,e):'<mock-value-for-field-"'.concat(null!==(o=null!==(u=t.alias)&&void 0!==u?u:t.name)&&void 0!==o?o:"undefined",'">'));return l};return!0===a?T(Array.isArray(l)?l:Array(1).fill(),o):o(l)}function T(e,n){return e.map((function(e){return n(e)}))}var V=function(){function e(e){var n,r,t,a,o;this._variables=e.variables,this._mockResolvers=(0,l.default)((0,l.default)({},x),null!==(n=e.mockResolvers)&&void 0!==n?n:{}),this._selectionMetadata=null!==(r=e.selectionMetadata)&&void 0!==r?r:{},this._resolveValue=(t=this._mockResolvers,a=0,o=function(){return++a},function(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return N.apply(void 0,[o,t].concat(n))})}var n=e.prototype;return n.generate=function(e,n){var r=this._getDefaultValuesForObject(n,null,null,[],{});return this._traverse({selections:e,typeName:n,isAbstractType:!1,name:null,alias:null,args:null},[],null,r)},n._traverse=function(e,n,r,t){var a=e.selections,l=e.typeName,o=e.isAbstractType;return this._traverseSelections(a,l,o,n,r,t)},n._traverseSelections=function(e,n,r,t,o,i){var s=this,x=null!=o?o:{};return e.forEach((function(e){switch(e.kind){case C:x=s._mockScalar(e,n,t,x,i);break;case y:x=s._traverseSelections([e.edges,e.pageInfo],n,r,t,o,i);break;case _:x=s._mockLink(e,t,x,i);break;case m:s._getVariableValue(e.condition)===e.passingValue&&(x=s._traverseSelections(e.selections,n,r,t,x,i));break;case b:case O:x=s._traverseSelections(e.selections,n,r,t,x,i);break;case v:case k:x=s._traverseSelections(e.fragment.selections,n,r,t,x,i);break;case h:var N,T=e.abstractKey;if(null!=T){null!=x&&(x[T]=!0),x=s._traverseSelections(e.selections,n,r,t,x,i);break}if(null!=x&&(null==x[c]||x[c]===j))x[c]=null!==(N=null==i?void 0:i[c])&&void 0!==N?N:e.type;if(!0===r&&null!=x&&x[c]===n&&(x[c]=e.type),null!=x&&x[c]===e.type){var V=s._getDefaultValuesForObject(e.type,t[t.length-1],null,t),D=n!==e.type?s._getDefaultValuesForObject(n,t[t.length-1],null,t):V,R=V;if(void 0===R&&(R=D),void 0===R&&(R=i),null===R){x=null;break}null!=(x=s._traverseSelections(e.selections,e.type,r,t,x,R))[c]&&(x[c]=e.type),null!=x.id&&null!=V&&null!=V.id&&(x.id=V.id)}break;case E:if(null!=i){var q;if(i.__typename!==n)break;var I=i.__module_operation;"object"==typeof I&&null!==I&&"SplitOperation"===I.kind&&Array.isArray(I.selections)&&"string"==typeof I.name||u(!1);var w=I,F=e.documentName;null==x&&(x={}),x=(0,l.default)((0,l.default)({},x),{},(q={},(0,a.default)(q,c,n),(0,a.default)(q,p(F),I.name),(0,a.default)(q,f(F),i.__module_component),q),s._traverseSelections(w.selections,n,!1,t,null,null))}break;case d:break;case M:var L=e.abstractKey;null!=x&&(x[L]=!0);break;case S:case A:break;case g:throw new Error("Flight fields are not yet supported.");default:u(!1)}})),x},n._getCorrectDefaultEnum=function(e,n,r,t){if(void 0===n)return n;if(null===n)return n;var a=Array.isArray(n)?n.map((function(e){return String(e).toUpperCase()})):[String(n).toUpperCase()],l=e.map((function(e){return e.toUpperCase()}));a.filter((function(e){return l.includes(e)})).length!==a.length&&u(!1);var o=a.map((function(n){var r=l.indexOf(String(n).toUpperCase());return e[r]}));return Array.isArray(n)?o:o[0]},n._mockScalar=function(e,n,r,t,a){var l,u,i=null!=t?t:{},s=null!==(l=e.alias)&&void 0!==l?l:e.name;if(i.hasOwnProperty(s)&&e.name!==c)return i;e.name===c&&(u=null!=n?n:j);var f=[].concat((0,o.default)(r),[s]),p=this._getScalarFieldTypeDetails(e,n,f),v=p.type,d=p.plural,m=p.enumValues;if(null!=a&&a.hasOwnProperty(s)&&(u=a[s],null!=m&&(u=this._getCorrectDefaultEnum(m,u,r,s)),void 0!==u&&d&&!Array.isArray(u)&&(u=[u])),void 0===u){var y=null!=m?m[0]:void 0;u=this._resolveValue(v,{parentType:n,name:e.name,alias:e.alias,path:f,args:this._getFieldArgs(e)},d,y)}return i[s]=u,i},n._mockLink=function(e,n,r,t){var a,l,u,i,s=this,f=null!==(a=e.alias)&&void 0!==a?a:e.name,p=null!=r?r:{},v=this._getFieldArgs(e),d=[].concat((0,o.default)(n),[f]),m=null!==(l=this._selectionMetadata[d.join(".")])&&void 0!==l?l:{type:j};if(null!=t&&"object"==typeof t[f]&&(i=t[f]),null===i)return p[f]=null,p;var y=null!==(u=e.concreteType)&&void 0!==u?u:null!=i&&"string"==typeof i[c]?i[c]:m.type,b=null===e.concreteType&&y===m.type,g=function(r){var t,a,l=null!==(t=s._getDefaultValuesForObject(null!==(a=e.concreteType)&&void 0!==a?a:m.type,e.name,e.alias,d,v))&&void 0!==t?t:r;return null===l?null:s._traverse({selections:e.selections,typeName:y,isAbstractType:b,name:e.name,alias:e.alias,args:v},[].concat((0,o.default)(n),[f]),"object"==typeof p[f]?p[f]:null,l)};return p[f]="LinkedField"===e.kind&&e.plural?T(Array.isArray(i)?i:Array(1).fill(),g):g(i),p},n._getVariableValue=function(e){return this._variables.hasOwnProperty(e)||u(!1),this._variables[e]},n._getDefaultValuesForObject=function(e,n,r,t,a){var l;if(null!=e&&null!=this._mockResolvers[e]&&(l=this._resolveValue(e,{parentType:null,name:n,alias:r,args:a,path:t},!1)),"object"==typeof l)return l},n._getFieldArgs=function(e){var n=this,r={};return null!=e.args&&e.args.forEach((function(e){r[e.name]=n._getArgValue(e)})),r},n._getArgValue=function(e){var n=this;switch(e.kind){case"Literal":return e.value;case"Variable":return this._getVariableValue(e.variableName);case"ObjectValue":var r={};return e.fields.forEach((function(e){r[e.name]=n._getArgValue(e)})),r;case"ListValue":var t=[];return e.items.forEach((function(e){t.push(null!=e?n._getArgValue(e):null)})),t}},n._getScalarFieldTypeDetails=function(e,n,r){var t;return null!==(t=this._selectionMetadata[r.join(".")])&&void 0!==t?t:{type:"id"===e.name?"ID":"String",plural:!1,enumValues:null,nullable:!1}},e}();e.exports={generate:function(e,n){return{data:function(e,n,r,t){var a,l=new V({variables:n,mockResolvers:r,selectionMetadata:t});return a=e.name.endsWith("Mutation")?"Mutation":e.name.endsWith("Subscription")?"Subscription":"Query",l.generate(e.selections,a)}(e.request.node.operation,e.request.variables,null!=n?n:null,function(e){var n,r=null===(n=e.request.node.params.metadata)||void 0===n?void 0:n.relayTestingSelectionTypeInfo;if(null!=r&&!Array.isArray(r)&&"object"==typeof r){var t={};return Object.keys(r).forEach((function(e){var n=r[e];null==n||Array.isArray(n)||"object"!=typeof n||"string"!=typeof n.type||"boolean"!=typeof n.plural||"boolean"!=typeof n.nullable||null!==n.enumValues&&!Array.isArray(n.enumValues)||(t[e]={type:n.type,plural:n.plural,nullable:n.nullable,enumValues:Array.isArray(n.enumValues)?n.enumValues.map(String):null})})),t}return null}(e))}}}},function(e,n){e.exports=require("@babel/runtime/helpers/defineProperty")},function(e,n){e.exports=require("@babel/runtime/helpers/toConsumableArray")},function(e,n,r){"use strict";var t=r(1)(r(2)),a=r(9),l=r(0),o=r(3),u=o.RecordSource,i=o.Store,c=o.QueryResponseCache,s=o.Observable,f=o.Environment,p=o.Network,v=o.createOperationDescriptor,d=o.getRequest;function m(e,n){e[n]=jest.fn(e[n].bind(e))}function y(e,n){var r=e[n].bind(e);e[n]=jest.fn((function(){for(var t=arguments.length,a=new Array(t),l=0;l<t;l++)a[l]=arguments[l];var o=r.apply(void 0,a),u=jest.fn((function(){return o.dispose()}));return e[n].mock.dispose=u,{dispose:u}}));var t=e[n].mockClear.bind(e[n]);e[n].mockClear=function(){t(),e[n].mock.dispose=null}}function b(e,n){var r=e[n].bind(e),t=[];e[n]=jest.fn((function(){for(var e=arguments.length,n=new Array(e),a=0;a<e;a++)n[a]=arguments[a];return r.apply(void 0,n).do({start:function(e){t.push(e)}})})),e[n].mock.subscriptions=t;var a=e[n].mockClear.bind(e[n]);e[n].mockClear=function(){a(),e[n].mock.subscriptions=[]}}e.exports={createMockEnvironment:function(e){var n,r,o,g,k=null!==(n=null==e?void 0:e.store)&&void 0!==n?n:new i(new u),h=new c({size:10,ttl:3e5}),_=[],A=[],E=[],C=function(e,n,r){var t=e.id,l=e.text,o=null!=t?t:l,u=null;if(null!=(null==r?void 0:r.force)&&!1!==(null==r?void 0:r.force)||null==o||(u=h.get(o,n)),null!==u)return s.from(u);var i=A.find((function(r){return r.request.node.params===e&&a(r.request.variables,n)}));if(null!=i&&E.length>0){var c=E[0],f=c(i);if(null!=f)return E=E.filter((function(e){return e!==c})),A=A.filter((function(e){return e!==i})),f instanceof Error?s.create((function(e){e.error(f)})):s.from(f)}return s.create((function(t){var l={request:e,variables:n,cacheConfig:r,sink:t};return _=_.concat([l]),function(){_=_.filter((function(e){return!a(e,l)})),A=A.filter((function(e){return e!==i}))}}))};function S(e){if("Request"===e.kind)return e;var n=e;return A.includes(n)||l(!1),n.request.node}function O(e){var n,r;n="Request"===e.kind?e:(r=e).request.node;var t=_.filter((function(e){return!!a(e.request,n.params)&&(!r||a(r.request.variables,e.variables))}));return t.length||l(!1),t.forEach((function(e){e.sink||l(!1)})),t}function M(e){return"object"==typeof e&&null!==e&&e.hasOwnProperty("data")||l(!1),e}var x=function(e,n){var r="string"==typeof n?new Error(n):n;O(e).forEach((function(e){var n=e.sink;null===n&&l(!1),n.error(r)}))},j=function(e,n){O(e).forEach((function(e){var r=e.sink;null===r&&l(!1),r.next(M(n)),r.complete()}))},N=function(){var e=A[A.length-1];return null==e&&l(!1),e},T=new f((0,t.default)({configName:"RelayModernMockEnvironment",network:p.create(C,C),store:k},e)),V=function(e,n){return function(){for(var r=arguments.length,t=new Array(r),a=0;a<r;a++)t[a]=arguments[a];var l=t[0].operation;return A=A.concat([l]),n.apply(e,t)}};T.execute=V(T,T.execute),T.executeWithSource=V(T,T.executeWithSource),T.executeMutation=V(T,T.executeMutation),"test"===(null===(r=global)||void 0===r||null===(o=r.process)||void 0===o||null===(g=o.env)||void 0===g?void 0:g.NODE_ENV)&&(y(T,"applyUpdate"),m(T,"commitPayload"),m(T,"getStore"),m(T,"lookup"),m(T,"check"),y(T,"subscribe"),y(T,"retain"),b(T,"execute"),b(T,"executeWithSource"),b(T,"executeMutation"),m(k,"getSource"),m(k,"lookup"),m(k,"notify"),m(k,"publish"),y(k,"retain"),y(k,"subscribe"));var D={cachePayload:function(e,n,r){var t=S(e).params,a=t.id,o=t.text,u=null!=a?a:o;null==u&&l(!1),h.set(u,n,r)},clearCache:function(){h.clear()},isLoading:function(e,n,r){return _.some((function(t){return a(t.request,S(e).params)&&a(t.variables,n)&&a(t.cacheConfig,null!=r?r:{})}))},reject:x,resolve:j,nextValue:function(e,n){O(e).forEach((function(e){var r=e.sink;null===r&&l(!1),r.next(M(n))}))},complete:function(e){O(e).forEach((function(e){var n=e.sink;null===n&&l(!1),n.complete()}))},getMostRecentOperation:N,resolveMostRecentOperation:function(e){var n=N(),r="function"==typeof e?e(n):e;return j(n,r)},rejectMostRecentOperation:function(e){var n=N(),r="function"==typeof e?e(n):e;return x(n,r)},findOperation:function(e){var n=A.find(e);return null==n&&l(!1),n},queuePendingOperation:function(e,n){var r=v(d(e),n);A=A.concat([r])},getAllOperations:function(){return A},queueOperationResolver:function(e){E=E.concat([e])}};return T.mock=D,T.mockClear=function(){T.applyUpdate.mockClear(),T.commitPayload.mockClear(),T.getStore.mockClear(),T.lookup.mockClear(),T.check.mockClear(),T.subscribe.mockClear(),T.retain.mockClear(),T.execute.mockClear(),T.executeMutation.mockClear(),k.getSource.mockClear(),k.lookup.mockClear(),k.notify.mockClear(),k.publish.mockClear(),k.retain.mockClear(),k.subscribe.mockClear(),h.clear(),A=[],_=[]},T}}},function(e,n){e.exports=require("fbjs/lib/areEqual")},function(e,n,r){"use strict";var t=r(0);e.exports=function(e){var n=e.__ComponentClass;return null==n&&t(!1),n}}]);
|
9
|
+
module.exports=function(e){var n={};function r(t){if(n[t])return n[t].exports;var a=n[t]={i:t,l:!1,exports:{}};return e[t].call(a.exports,a,a.exports,r),a.l=!0,a.exports}return r.m=e,r.c=n,r.d=function(e,n,t){r.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:t})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,n){if(1&n&&(e=r(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(r.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var a in e)r.d(t,a,function(n){return e[n]}.bind(null,a));return t},r.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(n,"a",n),n},r.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},r.p="",r(r.s=4)}([function(e,n){e.exports=require("invariant")},function(e,n){e.exports=require("@babel/runtime/helpers/interopRequireDefault")},function(e,n){e.exports=require("@babel/runtime/helpers/objectSpread2")},function(e,n){e.exports=require("relay-runtime")},function(e,n,r){"use strict";var t=r(5),a=r(8),l=r(10),o=r(12);e.exports={MockEnvironment:a,MockPayloadGenerator:t,createMockEnvironment:a.createMockEnvironment,unwrapContainer:o,testResolver:l}},function(e,n,r){"use strict";var t=r(1),a=t(r(6)),l=t(r(2)),o=t(r(7)),u=r(0),i=r(3),c=i.RelayConcreteNode,s=i.TYPENAME_KEY,f=i.getModuleComponentKey,p=i.getModuleOperationKey,v=c.ACTOR_CHANGE,d=c.CLIENT_COMPONENT,m=c.CLIENT_EXTENSION,y=c.CONDITION,b=c.CONNECTION,g=c.DEFER,k=c.FLIGHT_FIELD,h=c.FRAGMENT_SPREAD,_=c.INLINE_FRAGMENT,A=c.LINKED_FIELD,E=c.LINKED_HANDLE,C=c.MODULE_IMPORT,S=c.SCALAR_FIELD,O=c.SCALAR_HANDLE,x=c.STREAM,M=c.TYPE_DISCRIMINATOR;var j={ID:function(e,n){return"<".concat(null!=e.parentType&&e.parentType!==N?e.parentType+"-":"","mock-id-").concat(n(),">")},Boolean:function(){return!1},Int:function(){return 42},Float:function(){return 4.2}},N="__MockObject";function T(e,n,r,t){var a=arguments.length>4&&void 0!==arguments[4]&&arguments[4],l=arguments.length>5?arguments[5]:void 0,o=function(a){var l,o,u,i=null!=r&&null!=n?n[r]:null;(null!=i&&(l=i(t,e)),void 0===l)&&(l=null!=a?a:"ID"===r?j.ID(t,e):'<mock-value-for-field-"'.concat(null!==(o=null!==(u=t.alias)&&void 0!==u?u:t.name)&&void 0!==o?o:"undefined",'">'));return l};return!0===a?R(Array.isArray(l)?l:Array(1).fill(),o):o(l)}function R(e,n){return e.map((function(e){return n(e)}))}var V=function(){function e(e){var n,r,t,a,o;this._variables=e.variables,this._mockResolvers=(0,l.default)((0,l.default)({},j),null!==(n=e.mockResolvers)&&void 0!==n?n:{}),this._selectionMetadata=null!==(r=e.selectionMetadata)&&void 0!==r?r:{},this._resolveValue=(t=this._mockResolvers,a=0,o=function(){return++a},function(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return T.apply(void 0,[o,t].concat(n))})}var n=e.prototype;return n.generate=function(e,n){var r=this._getDefaultValuesForObject(n,null,null,[],{});return this._traverse({selections:e,typeName:n,isAbstractType:!1,name:null,alias:null,args:null},[],null,r)},n._traverse=function(e,n,r,t){var a=e.selections,l=e.typeName,o=e.isAbstractType;return this._traverseSelections(a,l,o,n,r,t)},n._traverseSelections=function(e,n,r,t,o,i){var c=this,j=null!=o?o:{};return e.forEach((function(e){switch(e.kind){case S:j=c._mockScalar(e,n,t,j,i);break;case b:j=c._traverseSelections([e.edges,e.pageInfo],n,r,t,o,i);break;case A:j=c._mockLink(e,t,j,i);break;case y:c._getVariableValue(e.condition)===e.passingValue&&(j=c._traverseSelections(e.selections,n,r,t,j,i));break;case g:case x:j=c._traverseSelections(e.selections,n,r,t,j,i);break;case d:case h:j=c._traverseSelections(e.fragment.selections,n,r,t,j,i);break;case _:var T,R=e.abstractKey;if(null!=R){null!=j&&(j[R]=!0),j=c._traverseSelections(e.selections,n,r,t,j,i);break}if(null!=j&&(null==j[s]||j[s]===N))j[s]=null!==(T=null==i?void 0:i[s])&&void 0!==T?T:e.type;if(!0===r&&null!=j&&j[s]===n&&(j[s]=e.type),null!=j&&j[s]===e.type){var V=c._getDefaultValuesForObject(e.type,t[t.length-1],null,t),D=n!==e.type?c._getDefaultValuesForObject(n,t[t.length-1],null,t):V,q=V;if(void 0===q&&(q=D),void 0===q&&(q=i),null===q){j=null;break}null!=(j=c._traverseSelections(e.selections,e.type,r,t,j,q))[s]&&(j[s]=e.type),null!=j.id&&null!=V&&null!=V.id&&(j.id=V.id)}break;case C:if(null!=i){var I;if(i.__typename!==n)break;var w=i.__module_operation;"object"==typeof w&&null!==w&&"SplitOperation"===w.kind&&Array.isArray(w.selections)&&"string"==typeof w.name||u(!1);var F=w,L=e.documentName;null==j&&(j={}),j=(0,l.default)((0,l.default)({},j),{},(I={},(0,a.default)(I,s,n),(0,a.default)(I,p(L),w.name),(0,a.default)(I,f(L),i.__module_component),I),c._traverseSelections(F.selections,n,!1,t,null,null))}break;case m:break;case M:var P=e.abstractKey;null!=j&&(j[P]=!0);break;case O:case E:break;case k:throw new Error("Flight fields are not yet supported.");case v:throw new Error("ActorChange fields are not yet supported.");default:u(!1)}})),j},n._getCorrectDefaultEnum=function(e,n,r,t){if(void 0===n)return n;if(null===n)return n;var a=Array.isArray(n)?n.map((function(e){return String(e).toUpperCase()})):[String(n).toUpperCase()],l=e.map((function(e){return e.toUpperCase()}));a.filter((function(e){return l.includes(e)})).length!==a.length&&u(!1);var o=a.map((function(n){var r=l.indexOf(String(n).toUpperCase());return e[r]}));return Array.isArray(n)?o:o[0]},n._mockScalar=function(e,n,r,t,a){var l,u,i=null!=t?t:{},c=null!==(l=e.alias)&&void 0!==l?l:e.name;if(i.hasOwnProperty(c)&&e.name!==s)return i;e.name===s&&(u=null!=n?n:N);var f=[].concat((0,o.default)(r),[c]),p=this._getScalarFieldTypeDetails(e,n,f),v=p.type,d=p.plural,m=p.enumValues;if(null!=a&&a.hasOwnProperty(c)&&(u=a[c],null!=m&&(u=this._getCorrectDefaultEnum(m,u,r,c)),void 0!==u&&d&&!Array.isArray(u)&&(u=[u])),void 0===u){var y=null!=m?m[0]:void 0;u=this._resolveValue(v,{parentType:n,name:e.name,alias:e.alias,path:f,args:this._getFieldArgs(e)},d,y)}return i[c]=u,i},n._mockLink=function(e,n,r,t){var a,l,u,i,c=this,f=null!==(a=e.alias)&&void 0!==a?a:e.name,p=null!=r?r:{},v=this._getFieldArgs(e),d=[].concat((0,o.default)(n),[f]),m=null!==(l=this._selectionMetadata[d.join(".")])&&void 0!==l?l:{type:N};if(null!=t&&"object"==typeof t[f]&&(i=t[f]),null===i)return p[f]=null,p;var y=null!==(u=e.concreteType)&&void 0!==u?u:null!=i&&"string"==typeof i[s]?i[s]:m.type,b=null===e.concreteType&&y===m.type,g=function(r){var t,a,l=null!==(t=c._getDefaultValuesForObject(null!==(a=e.concreteType)&&void 0!==a?a:m.type,e.name,e.alias,d,v))&&void 0!==t?t:r;return null===l?null:c._traverse({selections:e.selections,typeName:y,isAbstractType:b,name:e.name,alias:e.alias,args:v},[].concat((0,o.default)(n),[f]),"object"==typeof p[f]?p[f]:null,l)};return p[f]="LinkedField"===e.kind&&e.plural?R(Array.isArray(i)?i:Array(1).fill(),g):g(i),p},n._getVariableValue=function(e){return this._variables.hasOwnProperty(e)||u(!1),this._variables[e]},n._getDefaultValuesForObject=function(e,n,r,t,a){var l;if(null!=e&&null!=this._mockResolvers[e]&&(l=this._resolveValue(e,{parentType:null,name:n,alias:r,args:a,path:t},!1)),"object"==typeof l)return l},n._getFieldArgs=function(e){var n=this,r={};return null!=e.args&&e.args.forEach((function(e){r[e.name]=n._getArgValue(e)})),r},n._getArgValue=function(e){var n=this;switch(e.kind){case"Literal":return e.value;case"Variable":return this._getVariableValue(e.variableName);case"ObjectValue":var r={};return e.fields.forEach((function(e){r[e.name]=n._getArgValue(e)})),r;case"ListValue":var t=[];return e.items.forEach((function(e){t.push(null!=e?n._getArgValue(e):null)})),t}},n._getScalarFieldTypeDetails=function(e,n,r){var t;return null!==(t=this._selectionMetadata[r.join(".")])&&void 0!==t?t:{type:"id"===e.name?"ID":"String",plural:!1,enumValues:null,nullable:!1}},e}();e.exports={generate:function(e,n){return{data:function(e,n,r,t){var a,l=new V({variables:n,mockResolvers:r,selectionMetadata:t});return a=e.name.endsWith("Mutation")?"Mutation":e.name.endsWith("Subscription")?"Subscription":"Query",l.generate(e.selections,a)}(e.request.node.operation,e.request.variables,null!=n?n:null,function(e){var n,r=null===(n=e.request.node.params.metadata)||void 0===n?void 0:n.relayTestingSelectionTypeInfo;if(null!=r&&!Array.isArray(r)&&"object"==typeof r){var t={};return Object.keys(r).forEach((function(e){var n=r[e];null==n||Array.isArray(n)||"object"!=typeof n||"string"!=typeof n.type||"boolean"!=typeof n.plural||"boolean"!=typeof n.nullable||null!==n.enumValues&&!Array.isArray(n.enumValues)||(t[e]={type:n.type,plural:n.plural,nullable:n.nullable,enumValues:Array.isArray(n.enumValues)?n.enumValues.map(String):null})})),t}return null}(e))}}}},function(e,n){e.exports=require("@babel/runtime/helpers/defineProperty")},function(e,n){e.exports=require("@babel/runtime/helpers/toConsumableArray")},function(e,n,r){"use strict";var t=r(1)(r(2)),a=r(9),l=r(0),o=r(3),u=o.Environment,i=o.Network,c=o.Observable,s=o.QueryResponseCache,f=o.RecordSource,p=o.Store,v=o.createOperationDescriptor,d=o.getRequest;function m(e,n){e[n]=jest.fn(e[n].bind(e))}function y(e,n){var r=e[n].bind(e);e[n]=jest.fn((function(){for(var t=arguments.length,a=new Array(t),l=0;l<t;l++)a[l]=arguments[l];var o=r.apply(void 0,a),u=jest.fn((function(){return o.dispose()}));return e[n].mock.dispose=u,{dispose:u}}));var t=e[n].mockClear.bind(e[n]);e[n].mockClear=function(){t(),e[n].mock.dispose=null}}function b(e,n){var r=e[n].bind(e),t=[];e[n]=jest.fn((function(){for(var e=arguments.length,n=new Array(e),a=0;a<e;a++)n[a]=arguments[a];return r.apply(void 0,n).do({start:function(e){t.push(e)}})})),e[n].mock.subscriptions=t;var a=e[n].mockClear.bind(e[n]);e[n].mockClear=function(){a(),e[n].mock.subscriptions=[]}}e.exports={createMockEnvironment:function(e){var n,r,o,g,k=null!==(n=null==e?void 0:e.store)&&void 0!==n?n:new p(new f),h=new s({size:10,ttl:3e5}),_=[],A=[],E=[],C=function(e,n,r){var t=e.id,l=e.text,o=null!=t?t:l,u=null;if(null!=(null==r?void 0:r.force)&&!1!==(null==r?void 0:r.force)||null==o||(u=h.get(o,n)),null!==u)return c.from(u);var i=A.find((function(r){return r.request.node.params===e&&a(r.request.variables,n)}));if(null!=i&&E.length>0){var s=E[0],f=s(i);if(null!=f)return E=E.filter((function(e){return e!==s})),A=A.filter((function(e){return e!==i})),f instanceof Error?c.create((function(e){e.error(f)})):c.from(f)}return c.create((function(t){var l={request:e,variables:n,cacheConfig:r,sink:t};return _=_.concat([l]),function(){_=_.filter((function(e){return!a(e,l)})),A=A.filter((function(e){return e!==i}))}}))};function S(e){if("Request"===e.kind)return e;var n=e;return A.includes(n)||l(!1),n.request.node}function O(e){var n,r;n="Request"===e.kind?e:(r=e).request.node;var t=_.filter((function(e){return!!a(e.request,n.params)&&(!r||a(r.request.variables,e.variables))}));return t.length||l(!1),t.forEach((function(e){e.sink||l(!1)})),t}function x(e){return"object"==typeof e&&null!==e&&e.hasOwnProperty("data")||l(!1),e}var M=function(e,n){var r="string"==typeof n?new Error(n):n;O(e).forEach((function(e){var n=e.sink;null===n&&l(!1),n.error(r)}))},j=function(e,n){O(e).forEach((function(e){var r=e.sink;null===r&&l(!1),r.next(x(n)),r.complete()}))},N=function(){var e=A[A.length-1];return null==e&&l(!1),e},T=new u((0,t.default)({configName:"RelayModernMockEnvironment",network:i.create(C,C),store:k},e)),R=function(e,n){return function(){for(var r=arguments.length,t=new Array(r),a=0;a<r;a++)t[a]=arguments[a];var l=t[0].operation;return A=A.concat([l]),n.apply(e,t)}};T.execute=R(T,T.execute),T.executeSubscription=R(T,T.executeSubscription),T.executeWithSource=R(T,T.executeWithSource),T.executeMutation=R(T,T.executeMutation),"test"===(null===(r=global)||void 0===r||null===(o=r.process)||void 0===o||null===(g=o.env)||void 0===g?void 0:g.NODE_ENV)&&(y(T,"applyUpdate"),m(T,"commitPayload"),m(T,"getStore"),m(T,"lookup"),m(T,"check"),y(T,"subscribe"),y(T,"retain"),b(T,"execute"),b(T,"executeSubscription"),b(T,"executeWithSource"),b(T,"executeMutation"),m(k,"getSource"),m(k,"lookup"),m(k,"notify"),m(k,"publish"),y(k,"retain"),y(k,"subscribe"));var V={cachePayload:function(e,n,r){var t=S(e).params,a=t.id,o=t.text,u=null!=a?a:o;null==u&&l(!1),h.set(u,n,r)},clearCache:function(){h.clear()},isLoading:function(e,n,r){return _.some((function(t){return a(t.request,S(e).params)&&a(t.variables,n)&&a(t.cacheConfig,null!=r?r:{})}))},reject:M,resolve:j,nextValue:function(e,n){O(e).forEach((function(e){var r=e.sink;null===r&&l(!1),r.next(x(n))}))},complete:function(e){O(e).forEach((function(e){var n=e.sink;null===n&&l(!1),n.complete()}))},getMostRecentOperation:N,resolveMostRecentOperation:function(e){var n=N(),r="function"==typeof e?e(n):e;return j(n,r)},rejectMostRecentOperation:function(e){var n=N(),r="function"==typeof e?e(n):e;return M(n,r)},findOperation:function(e){var n=A.find(e);return null==n&&l(!1),n},queuePendingOperation:function(e,n){var r=v(d(e),n);A=A.concat([r])},getAllOperations:function(){return A},queueOperationResolver:function(e){E=E.concat([e])}};return T.mock=V,T.mockClear=function(){var e,n;T.applyUpdate.mockClear(),T.commitPayload.mockClear(),T.getStore.mockClear(),T.lookup.mockClear(),T.check.mockClear(),T.subscribe.mockClear(),T.retain.mockClear(),T.execute.mockClear(),T.executeMutation.mockClear(),T.executeSubscription.mockClear(),null===(e=(n=k.getSource()).clear)||void 0===e||e.call(n),k.getSource.mockClear(),k.lookup.mockClear(),k.notify.mockClear(),k.publish.mockClear(),k.retain.mockClear(),k.subscribe.mockClear(),h.clear(),A=[],_=[]},T}}},function(e,n){e.exports=require("fbjs/lib/areEqual")},function(e,n,r){"use strict";var t=r(11);e.exports={testResolver:function(e,n){var r=t.readFragment;t.readFragment=function(){return n};var a=e(null);return t.readFragment=r,a}}},function(e,n){e.exports=require("relay-runtime/store/ResolverFragments")},function(e,n,r){"use strict";var t=r(0);e.exports=function(e){var n=e.__ComponentClass;return null==n&&t(!1),n}}]);
|
package/unwrapContainer.js.flow
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -9,16 +9,16 @@
|
|
9
9
|
|
10
10
|
'use strict';
|
11
11
|
|
12
|
-
const invariant = require('invariant');
|
13
|
-
|
14
12
|
import type React from 'React';
|
15
13
|
import type {
|
16
|
-
$RelayProps,
|
17
|
-
RelayProp,
|
18
14
|
RelayPaginationProp,
|
15
|
+
RelayProp,
|
19
16
|
RelayRefetchProp,
|
17
|
+
$RelayProps,
|
20
18
|
} from 'react-relay';
|
21
19
|
|
20
|
+
const invariant = require('invariant');
|
21
|
+
|
22
22
|
/**
|
23
23
|
* Returns original component class wrapped by e.g. createFragmentContainer
|
24
24
|
*/
|