@apollo/client 3.6.2 → 3.6.5
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/apollo-client.cjs +164 -105
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/cache/cache.cjs +9 -10
- package/cache/cache.cjs.map +1 -1
- package/cache/cache.cjs.native.js +2288 -0
- package/cache/inmemory/readFromStore.d.ts.map +1 -1
- package/cache/inmemory/readFromStore.js +10 -11
- package/cache/inmemory/readFromStore.js.map +1 -1
- package/core/ApolloClient.d.ts.map +1 -1
- package/core/ApolloClient.js.map +1 -1
- package/core/ObservableQuery.d.ts.map +1 -1
- package/core/ObservableQuery.js +5 -3
- package/core/ObservableQuery.js.map +1 -1
- package/core/core.cjs +5 -3
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +2141 -0
- package/errors/errors.cjs.native.js +48 -0
- package/invariantErrorCodes.js +1 -1
- package/link/batch/batch.cjs.native.js +161 -0
- package/link/batch-http/batch-http.cjs.native.js +127 -0
- package/link/context/context.cjs.native.js +38 -0
- package/link/core/core.cjs.native.js +121 -0
- package/link/error/error.cjs.native.js +90 -0
- package/link/http/http.cjs.native.js +320 -0
- package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
- package/link/http/selectHttpOptionsAndBody.js.map +1 -1
- package/link/persisted-queries/persisted-queries.cjs.native.js +174 -0
- package/link/retry/retry.cjs.native.js +170 -0
- package/link/schema/schema.cjs.native.js +56 -0
- package/link/subscriptions/subscriptions.cjs.native.js +45 -0
- package/link/utils/utils.cjs.native.js +115 -0
- package/link/ws/ws.cjs.native.js +28 -0
- package/main.cjs.native.js +16 -0
- package/package.json +16 -17
- package/react/components/components.cjs.native.js +79 -0
- package/react/context/context.cjs.native.js +67 -0
- package/react/hoc/hoc.cjs.native.js +325 -0
- package/react/hooks/hooks.cjs +168 -99
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +612 -0
- package/react/hooks/useLazyQuery.d.ts.map +1 -1
- package/react/hooks/useLazyQuery.js +12 -23
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useMutation.js +7 -7
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.d.ts +6 -2
- package/react/hooks/useQuery.d.ts.map +1 -1
- package/react/hooks/useQuery.js +52 -40
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useSubscription.d.ts.map +1 -1
- package/react/hooks/useSubscription.js +17 -7
- package/react/hooks/useSubscription.js.map +1 -1
- package/react/hooks/useSyncExternalStore.d.ts +4 -0
- package/react/hooks/useSyncExternalStore.d.ts.map +1 -0
- package/react/hooks/useSyncExternalStore.js +48 -0
- package/react/hooks/useSyncExternalStore.js.map +1 -0
- package/react/parser/parser.cjs.native.js +103 -0
- package/react/react.cjs.native.js +22 -0
- package/react/ssr/ssr.cjs.native.js +150 -0
- package/testing/core/core.cjs.native.js +288 -0
- package/testing/testing.cjs.native.js +58 -0
- package/utilities/common/canUse.d.ts +2 -0
- package/utilities/common/canUse.d.ts.map +1 -1
- package/utilities/common/canUse.js +6 -2
- package/utilities/common/canUse.js.map +1 -1
- package/utilities/common/mergeDeep.d.ts.map +1 -1
- package/utilities/common/mergeDeep.js +8 -11
- package/utilities/common/mergeDeep.js.map +1 -1
- package/utilities/common/mergeOptions.d.ts +1 -1
- package/utilities/common/mergeOptions.d.ts.map +1 -1
- package/utilities/common/mergeOptions.js +1 -1
- package/utilities/common/mergeOptions.js.map +1 -1
- package/utilities/globals/globals.cjs.native.js +56 -0
- package/utilities/observables/Concast.d.ts.map +1 -1
- package/utilities/observables/Concast.js +5 -2
- package/utilities/observables/Concast.js.map +1 -1
- package/utilities/policies/pagination.d.ts.map +1 -1
- package/utilities/policies/pagination.js +9 -7
- package/utilities/policies/pagination.js.map +1 -1
- package/utilities/utilities.cjs +30 -23
- package/utilities/utilities.cjs.map +1 -1
- package/utilities/utilities.cjs.native.js +1281 -0
- package/version.js +1 -1
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { invariant } from "../../utilities/globals/index.js";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { canUseLayoutEffect } from "../../utilities/index.js";
|
|
4
|
+
var didWarnUncachedGetSnapshot = false;
|
|
5
|
+
var uSESKey = "useSyncExternalStore";
|
|
6
|
+
var realHook = React[uSESKey];
|
|
7
|
+
export var useSyncExternalStore = realHook || (function (subscribe, getSnapshot, getServerSnapshot) {
|
|
8
|
+
var value = getSnapshot();
|
|
9
|
+
if (__DEV__ &&
|
|
10
|
+
!didWarnUncachedGetSnapshot &&
|
|
11
|
+
value !== getSnapshot()) {
|
|
12
|
+
didWarnUncachedGetSnapshot = true;
|
|
13
|
+
__DEV__ && invariant.error('The result of getSnapshot should be cached to avoid an infinite loop');
|
|
14
|
+
}
|
|
15
|
+
var _a = React.useState({ inst: { value: value, getSnapshot: getSnapshot } }), inst = _a[0].inst, forceUpdate = _a[1];
|
|
16
|
+
if (canUseLayoutEffect) {
|
|
17
|
+
React.useLayoutEffect(function () {
|
|
18
|
+
Object.assign(inst, { value: value, getSnapshot: getSnapshot });
|
|
19
|
+
if (checkIfSnapshotChanged(inst)) {
|
|
20
|
+
forceUpdate({ inst: inst });
|
|
21
|
+
}
|
|
22
|
+
}, [subscribe, value, getSnapshot]);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
Object.assign(inst, { value: value, getSnapshot: getSnapshot });
|
|
26
|
+
}
|
|
27
|
+
React.useEffect(function () {
|
|
28
|
+
if (checkIfSnapshotChanged(inst)) {
|
|
29
|
+
forceUpdate({ inst: inst });
|
|
30
|
+
}
|
|
31
|
+
return subscribe(function handleStoreChange() {
|
|
32
|
+
if (checkIfSnapshotChanged(inst)) {
|
|
33
|
+
forceUpdate({ inst: inst });
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}, [subscribe]);
|
|
37
|
+
return value;
|
|
38
|
+
});
|
|
39
|
+
function checkIfSnapshotChanged(_a) {
|
|
40
|
+
var value = _a.value, getSnapshot = _a.getSnapshot;
|
|
41
|
+
try {
|
|
42
|
+
return value !== getSnapshot();
|
|
43
|
+
}
|
|
44
|
+
catch (_b) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=useSyncExternalStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSyncExternalStore.js","sourceRoot":"","sources":["../../../src/react/hooks/useSyncExternalStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,IAAI,0BAA0B,GAAG,KAAK,CAAC;AAYvC,IAAM,OAAO,GAAG,sBAA4C,CAAC;AAC7D,IAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAmC,CAAC;AAMlE,MAAM,CAAC,IAAM,oBAAoB,GAAuB,QAAQ,IAAI,CAAC,UACnE,SAAS,EACT,WAAW,EACX,iBAAiB;IAMjB,IAAM,KAAK,GAAG,WAAW,EAAE,CAAC;IAC5B,IAEE,OAAO;QACP,CAAC,0BAA0B;QAG3B,KAAK,KAAK,WAAW,EAAE,EACvB;QACA,0BAA0B,GAAG,IAAI,CAAC;QAElC,SAAS,CAAC,KAAK,CACb,sEAAsE,CACvE,CAAC;KACH;IAgBK,IAAA,KAAwB,KAAK,CAAC,QAAQ,CAAC,EAAC,IAAI,EAAE,EAAC,KAAK,OAAA,EAAE,WAAW,aAAA,EAAC,EAAC,CAAC,EAAlE,IAAI,aAAA,EAAG,WAAW,QAAgD,CAAC;IAK3E,IAAI,kBAAkB,EAAE;QAKtB,KAAK,CAAC,eAAe,CAAC;YACpB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,KAAK,OAAA,EAAE,WAAW,aAAA,EAAE,CAAC,CAAC;YAK5C,IAAI,sBAAsB,CAAC,IAAI,CAAC,EAAE;gBAEhC,WAAW,CAAC,EAAC,IAAI,MAAA,EAAC,CAAC,CAAC;aACrB;QACH,CAAC,EAAE,CAAC,SAAS,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC;KACrC;SAAM;QACL,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,KAAK,OAAA,EAAE,WAAW,aAAA,EAAE,CAAC,CAAC;KAC7C;IAED,KAAK,CAAC,SAAS,CAAC;QAGd,IAAI,sBAAsB,CAAC,IAAI,CAAC,EAAE;YAEhC,WAAW,CAAC,EAAC,IAAI,MAAA,EAAC,CAAC,CAAC;SACrB;QAGD,OAAO,SAAS,CAAC,SAAS,iBAAiB;YAQzC,IAAI,sBAAsB,CAAC,IAAI,CAAC,EAAE;gBAEhC,WAAW,CAAC,EAAC,IAAI,MAAA,EAAC,CAAC,CAAC;aACrB;QACH,CAAC,CAAC,CAAC;IACL,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;IAEhB,OAAO,KAAK,CAAC;AACf,CAAC,CAAC,CAAC;AAEH,SAAS,sBAAsB,CAAW,EAMzC;QALC,KAAK,WAAA,EACL,WAAW,iBAAA;IAKX,IAAI;QACF,OAAO,KAAK,KAAK,WAAW,EAAE,CAAC;KAChC;IAAC,WAAM;QACN,OAAO,IAAI,CAAC;KACb;AACH,CAAC","sourcesContent":["import { invariant } from '../../utilities/globals';\nimport * as React from 'react';\n\nimport { canUseLayoutEffect } from '../../utilities';\n\nlet didWarnUncachedGetSnapshot = false;\n\ntype RealUseSESHookType =\n // This import depends only on the @types/use-sync-external-store package, not\n // the actual use-sync-external-store package, which is not installed. It\n // might be nice to get this type from React 18, but it still needs to work\n // when only React 17 or earlier is installed.\n typeof import(\"use-sync-external-store\").useSyncExternalStore;\n\n// Prevent webpack from complaining about our feature detection of the\n// useSyncExternalStore property of the React namespace, which is expected not\n// to exist when using React 17 and earlier, and that's fine.\nconst uSESKey = \"useSyncExternalStore\" as keyof typeof React;\nconst realHook = React[uSESKey] as RealUseSESHookType | undefined;\n\n// Adapted from https://www.npmjs.com/package/use-sync-external-store, with\n// Apollo Client deviations called out by \"// DEVIATION ...\" comments.\n\n// When/if React.useSyncExternalStore is defined, delegate fully to it.\nexport const useSyncExternalStore: RealUseSESHookType = realHook || ((\n subscribe,\n getSnapshot,\n getServerSnapshot,\n) => {\n // Read the current snapshot from the store on every render. Again, this\n // breaks the rules of React, and only works here because of specific\n // implementation details, most importantly that updates are\n // always synchronous.\n const value = getSnapshot();\n if (\n // DEVIATION: Using our own __DEV__ polyfill (from ../../utilities/globals).\n __DEV__ &&\n !didWarnUncachedGetSnapshot &&\n // DEVIATION: Not using Object.is because we know our snapshots will never\n // be exotic primitive values like NaN, which is !== itself.\n value !== getSnapshot()\n ) {\n didWarnUncachedGetSnapshot = true;\n // DEVIATION: Using invariant.error instead of console.error directly.\n invariant.error(\n 'The result of getSnapshot should be cached to avoid an infinite loop',\n );\n }\n\n // Because updates are synchronous, we don't queue them. Instead we force a\n // re-render whenever the subscribed state changes by updating an some\n // arbitrary useState hook. Then, during render, we call getSnapshot to read\n // the current value.\n //\n // Because we don't actually use the state returned by the useState hook, we\n // can save a bit of memory by storing other stuff in that slot.\n //\n // To implement the early bailout, we need to track some things on a mutable\n // object. Usually, we would put that in a useRef hook, but we can stash it in\n // our useState hook instead.\n //\n // To force a re-render, we call forceUpdate({inst}). That works because the\n // new object always fails an equality check.\n const [{inst}, forceUpdate] = React.useState({inst: {value, getSnapshot}});\n\n // Track the latest getSnapshot function with a ref. This needs to be updated\n // in the layout phase so we can access it during the tearing check that\n // happens on subscribe.\n if (canUseLayoutEffect) {\n // DEVIATION: We avoid calling useLayoutEffect when !canUseLayoutEffect,\n // which may seem like a conditional hook, but this code ends up behaving\n // unconditionally (one way or the other) because canUseLayoutEffect is\n // constant.\n React.useLayoutEffect(() => {\n Object.assign(inst, { value, getSnapshot });\n // Whenever getSnapshot or subscribe changes, we need to check in the\n // commit phase if there was an interleaved mutation. In concurrent mode\n // this can happen all the time, but even in synchronous mode, an earlier\n // effect may have mutated the store.\n if (checkIfSnapshotChanged(inst)) {\n // Force a re-render.\n forceUpdate({inst});\n }\n }, [subscribe, value, getSnapshot]);\n } else {\n Object.assign(inst, { value, getSnapshot });\n }\n\n React.useEffect(() => {\n // Check for changes right before subscribing. Subsequent changes will be\n // detected in the subscription handler.\n if (checkIfSnapshotChanged(inst)) {\n // Force a re-render.\n forceUpdate({inst});\n }\n\n // Subscribe to the store and return a clean-up function.\n return subscribe(function handleStoreChange() {\n // TODO: Because there is no cross-renderer API for batching updates, it's\n // up to the consumer of this library to wrap their subscription event\n // with unstable_batchedUpdates. Should we try to detect when this isn't\n // the case and print a warning in development?\n\n // The store changed. Check if the snapshot changed since the last time we\n // read from the store.\n if (checkIfSnapshotChanged(inst)) {\n // Force a re-render.\n forceUpdate({inst});\n }\n });\n }, [subscribe]);\n\n return value;\n});\n\nfunction checkIfSnapshotChanged<Snapshot>({\n value,\n getSnapshot,\n}: {\n value: Snapshot;\n getSnapshot: () => Snapshot;\n}): boolean {\n try {\n return value !== getSnapshot();\n } catch {\n return true;\n }\n}\n"]}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var globals = require('../../utilities/globals');
|
|
6
|
+
|
|
7
|
+
exports.DocumentType = void 0;
|
|
8
|
+
(function (DocumentType) {
|
|
9
|
+
DocumentType[DocumentType["Query"] = 0] = "Query";
|
|
10
|
+
DocumentType[DocumentType["Mutation"] = 1] = "Mutation";
|
|
11
|
+
DocumentType[DocumentType["Subscription"] = 2] = "Subscription";
|
|
12
|
+
})(exports.DocumentType || (exports.DocumentType = {}));
|
|
13
|
+
var cache = new Map();
|
|
14
|
+
function operationName(type) {
|
|
15
|
+
var name;
|
|
16
|
+
switch (type) {
|
|
17
|
+
case exports.DocumentType.Query:
|
|
18
|
+
name = 'Query';
|
|
19
|
+
break;
|
|
20
|
+
case exports.DocumentType.Mutation:
|
|
21
|
+
name = 'Mutation';
|
|
22
|
+
break;
|
|
23
|
+
case exports.DocumentType.Subscription:
|
|
24
|
+
name = 'Subscription';
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
return name;
|
|
28
|
+
}
|
|
29
|
+
function parser(document) {
|
|
30
|
+
var cached = cache.get(document);
|
|
31
|
+
if (cached)
|
|
32
|
+
return cached;
|
|
33
|
+
var variables, type, name;
|
|
34
|
+
__DEV__ ? globals.invariant(!!document && !!document.kind, "Argument of ".concat(document, " passed to parser was not a valid GraphQL ") +
|
|
35
|
+
"DocumentNode. You may need to use 'graphql-tag' or another method " +
|
|
36
|
+
"to convert your operation into a document") : globals.invariant(!!document && !!document.kind, 30);
|
|
37
|
+
var fragments = [];
|
|
38
|
+
var queries = [];
|
|
39
|
+
var mutations = [];
|
|
40
|
+
var subscriptions = [];
|
|
41
|
+
for (var _i = 0, _a = document.definitions; _i < _a.length; _i++) {
|
|
42
|
+
var x = _a[_i];
|
|
43
|
+
if (x.kind === 'FragmentDefinition') {
|
|
44
|
+
fragments.push(x);
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (x.kind === 'OperationDefinition') {
|
|
48
|
+
switch (x.operation) {
|
|
49
|
+
case 'query':
|
|
50
|
+
queries.push(x);
|
|
51
|
+
break;
|
|
52
|
+
case 'mutation':
|
|
53
|
+
mutations.push(x);
|
|
54
|
+
break;
|
|
55
|
+
case 'subscription':
|
|
56
|
+
subscriptions.push(x);
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
__DEV__ ? globals.invariant(!fragments.length ||
|
|
62
|
+
(queries.length || mutations.length || subscriptions.length), "Passing only a fragment to 'graphql' is not yet supported. " +
|
|
63
|
+
"You must include a query, subscription or mutation as well") : globals.invariant(!fragments.length ||
|
|
64
|
+
(queries.length || mutations.length || subscriptions.length), 31);
|
|
65
|
+
__DEV__ ? globals.invariant(queries.length + mutations.length + subscriptions.length <= 1, "react-apollo only supports a query, subscription, or a mutation per HOC. " +
|
|
66
|
+
"".concat(document, " had ").concat(queries.length, " queries, ").concat(subscriptions.length, " ") +
|
|
67
|
+
"subscriptions and ".concat(mutations.length, " mutations. ") +
|
|
68
|
+
"You can use 'compose' to join multiple operation types to a component") : globals.invariant(queries.length + mutations.length + subscriptions.length <= 1, 32);
|
|
69
|
+
type = queries.length ? exports.DocumentType.Query : exports.DocumentType.Mutation;
|
|
70
|
+
if (!queries.length && !mutations.length)
|
|
71
|
+
type = exports.DocumentType.Subscription;
|
|
72
|
+
var definitions = queries.length
|
|
73
|
+
? queries
|
|
74
|
+
: mutations.length
|
|
75
|
+
? mutations
|
|
76
|
+
: subscriptions;
|
|
77
|
+
__DEV__ ? globals.invariant(definitions.length === 1, "react-apollo only supports one definition per HOC. ".concat(document, " had ") +
|
|
78
|
+
"".concat(definitions.length, " definitions. ") +
|
|
79
|
+
"You can use 'compose' to join multiple operation types to a component") : globals.invariant(definitions.length === 1, 33);
|
|
80
|
+
var definition = definitions[0];
|
|
81
|
+
variables = definition.variableDefinitions || [];
|
|
82
|
+
if (definition.name && definition.name.kind === 'Name') {
|
|
83
|
+
name = definition.name.value;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
name = 'data';
|
|
87
|
+
}
|
|
88
|
+
var payload = { name: name, type: type, variables: variables };
|
|
89
|
+
cache.set(document, payload);
|
|
90
|
+
return payload;
|
|
91
|
+
}
|
|
92
|
+
function verifyDocumentType(document, type) {
|
|
93
|
+
var operation = parser(document);
|
|
94
|
+
var requiredOperationName = operationName(type);
|
|
95
|
+
var usedOperationName = operationName(operation.type);
|
|
96
|
+
__DEV__ ? globals.invariant(operation.type === type, "Running a ".concat(requiredOperationName, " requires a graphql ") +
|
|
97
|
+
"".concat(requiredOperationName, ", but a ").concat(usedOperationName, " was used instead.")) : globals.invariant(operation.type === type, 34);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
exports.operationName = operationName;
|
|
101
|
+
exports.parser = parser;
|
|
102
|
+
exports.verifyDocumentType = verifyDocumentType;
|
|
103
|
+
//# sourceMappingURL=parser.cjs.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
require('../utilities/globals');
|
|
6
|
+
var context = require('./context');
|
|
7
|
+
var hooks = require('./hooks');
|
|
8
|
+
var parser = require('./parser');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
exports.ApolloConsumer = context.ApolloConsumer;
|
|
13
|
+
exports.ApolloProvider = context.ApolloProvider;
|
|
14
|
+
exports.getApolloContext = context.getApolloContext;
|
|
15
|
+
exports.resetApolloContext = context.resetApolloContext;
|
|
16
|
+
exports.DocumentType = parser.DocumentType;
|
|
17
|
+
exports.operationName = parser.operationName;
|
|
18
|
+
exports.parser = parser.parser;
|
|
19
|
+
for (var k in hooks) {
|
|
20
|
+
if (k !== 'default' && !exports.hasOwnProperty(k)) exports[k] = hooks[k];
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=react.cjs.map
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var tslib = require('tslib');
|
|
6
|
+
var React = require('react');
|
|
7
|
+
var context = require('../context');
|
|
8
|
+
|
|
9
|
+
function _interopNamespace(e) {
|
|
10
|
+
if (e && e.__esModule) return e;
|
|
11
|
+
var n = Object.create(null);
|
|
12
|
+
if (e) {
|
|
13
|
+
for (var k in e) {
|
|
14
|
+
n[k] = e[k];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
n["default"] = e;
|
|
18
|
+
return Object.freeze(n);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
22
|
+
|
|
23
|
+
function makeDefaultQueryInfo() {
|
|
24
|
+
return {
|
|
25
|
+
seen: false,
|
|
26
|
+
observable: null
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
var RenderPromises = (function () {
|
|
30
|
+
function RenderPromises() {
|
|
31
|
+
this.queryPromises = new Map();
|
|
32
|
+
this.queryInfoTrie = new Map();
|
|
33
|
+
this.stopped = false;
|
|
34
|
+
}
|
|
35
|
+
RenderPromises.prototype.stop = function () {
|
|
36
|
+
if (!this.stopped) {
|
|
37
|
+
this.queryPromises.clear();
|
|
38
|
+
this.queryInfoTrie.clear();
|
|
39
|
+
this.stopped = true;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
RenderPromises.prototype.registerSSRObservable = function (observable) {
|
|
43
|
+
if (this.stopped)
|
|
44
|
+
return;
|
|
45
|
+
this.lookupQueryInfo(observable.options).observable = observable;
|
|
46
|
+
};
|
|
47
|
+
RenderPromises.prototype.getSSRObservable = function (props) {
|
|
48
|
+
return this.lookupQueryInfo(props).observable;
|
|
49
|
+
};
|
|
50
|
+
RenderPromises.prototype.addQueryPromise = function (queryInstance, finish) {
|
|
51
|
+
if (!this.stopped) {
|
|
52
|
+
var info = this.lookupQueryInfo(queryInstance.getOptions());
|
|
53
|
+
if (!info.seen) {
|
|
54
|
+
this.queryPromises.set(queryInstance.getOptions(), new Promise(function (resolve) {
|
|
55
|
+
resolve(queryInstance.fetchData());
|
|
56
|
+
}));
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return finish ? finish() : null;
|
|
61
|
+
};
|
|
62
|
+
RenderPromises.prototype.addObservableQueryPromise = function (obsQuery) {
|
|
63
|
+
return this.addQueryPromise({
|
|
64
|
+
getOptions: function () { return obsQuery.options; },
|
|
65
|
+
fetchData: function () { return new Promise(function (resolve) {
|
|
66
|
+
var sub = obsQuery.subscribe({
|
|
67
|
+
next: function (result) {
|
|
68
|
+
if (!result.loading) {
|
|
69
|
+
resolve();
|
|
70
|
+
sub.unsubscribe();
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
error: function () {
|
|
74
|
+
resolve();
|
|
75
|
+
sub.unsubscribe();
|
|
76
|
+
},
|
|
77
|
+
complete: function () {
|
|
78
|
+
resolve();
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
}); },
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
RenderPromises.prototype.hasPromises = function () {
|
|
85
|
+
return this.queryPromises.size > 0;
|
|
86
|
+
};
|
|
87
|
+
RenderPromises.prototype.consumeAndAwaitPromises = function () {
|
|
88
|
+
var _this = this;
|
|
89
|
+
var promises = [];
|
|
90
|
+
this.queryPromises.forEach(function (promise, queryInstance) {
|
|
91
|
+
_this.lookupQueryInfo(queryInstance).seen = true;
|
|
92
|
+
promises.push(promise);
|
|
93
|
+
});
|
|
94
|
+
this.queryPromises.clear();
|
|
95
|
+
return Promise.all(promises);
|
|
96
|
+
};
|
|
97
|
+
RenderPromises.prototype.lookupQueryInfo = function (props) {
|
|
98
|
+
var queryInfoTrie = this.queryInfoTrie;
|
|
99
|
+
var query = props.query, variables = props.variables;
|
|
100
|
+
var varMap = queryInfoTrie.get(query) || new Map();
|
|
101
|
+
if (!queryInfoTrie.has(query))
|
|
102
|
+
queryInfoTrie.set(query, varMap);
|
|
103
|
+
var variablesString = JSON.stringify(variables);
|
|
104
|
+
var info = varMap.get(variablesString) || makeDefaultQueryInfo();
|
|
105
|
+
if (!varMap.has(variablesString))
|
|
106
|
+
varMap.set(variablesString, info);
|
|
107
|
+
return info;
|
|
108
|
+
};
|
|
109
|
+
return RenderPromises;
|
|
110
|
+
}());
|
|
111
|
+
|
|
112
|
+
function getDataFromTree(tree, context) {
|
|
113
|
+
if (context === void 0) { context = {}; }
|
|
114
|
+
return getMarkupFromTree({
|
|
115
|
+
tree: tree,
|
|
116
|
+
context: context,
|
|
117
|
+
renderFunction: require('react-dom/server').renderToStaticMarkup
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
function getMarkupFromTree(_a) {
|
|
121
|
+
var tree = _a.tree, _b = _a.context, context$1 = _b === void 0 ? {} : _b, _c = _a.renderFunction, renderFunction = _c === void 0 ? require('react-dom/server').renderToStaticMarkup : _c;
|
|
122
|
+
var renderPromises = new RenderPromises();
|
|
123
|
+
function process() {
|
|
124
|
+
var ApolloContext = context.getApolloContext();
|
|
125
|
+
return new Promise(function (resolve) {
|
|
126
|
+
var element = React__namespace.createElement(ApolloContext.Provider, { value: tslib.__assign(tslib.__assign({}, context$1), { renderPromises: renderPromises }) }, tree);
|
|
127
|
+
resolve(renderFunction(element));
|
|
128
|
+
}).then(function (html) {
|
|
129
|
+
return renderPromises.hasPromises()
|
|
130
|
+
? renderPromises.consumeAndAwaitPromises().then(process)
|
|
131
|
+
: html;
|
|
132
|
+
}).finally(function () {
|
|
133
|
+
renderPromises.stop();
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
return Promise.resolve().then(process);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function renderToStringWithData(component) {
|
|
140
|
+
return getMarkupFromTree({
|
|
141
|
+
tree: component,
|
|
142
|
+
renderFunction: require('react-dom/server').renderToString
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
exports.RenderPromises = RenderPromises;
|
|
147
|
+
exports.getDataFromTree = getDataFromTree;
|
|
148
|
+
exports.getMarkupFromTree = getMarkupFromTree;
|
|
149
|
+
exports.renderToStringWithData = renderToStringWithData;
|
|
150
|
+
//# sourceMappingURL=ssr.cjs.map
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var tslib = require('tslib');
|
|
6
|
+
var globals = require('../../utilities/globals');
|
|
7
|
+
var graphql = require('graphql');
|
|
8
|
+
var equality = require('@wry/equality');
|
|
9
|
+
var core = require('../../link/core');
|
|
10
|
+
var utilities = require('../../utilities');
|
|
11
|
+
var core$1 = require('../../core');
|
|
12
|
+
var cache = require('../../cache');
|
|
13
|
+
|
|
14
|
+
function requestToKey(request, addTypename) {
|
|
15
|
+
var queryString = request.query &&
|
|
16
|
+
graphql.print(addTypename ? utilities.addTypenameToDocument(request.query) : request.query);
|
|
17
|
+
var requestKey = { query: queryString };
|
|
18
|
+
return JSON.stringify(requestKey);
|
|
19
|
+
}
|
|
20
|
+
var MockLink = (function (_super) {
|
|
21
|
+
tslib.__extends(MockLink, _super);
|
|
22
|
+
function MockLink(mockedResponses, addTypename) {
|
|
23
|
+
if (addTypename === void 0) { addTypename = true; }
|
|
24
|
+
var _this = _super.call(this) || this;
|
|
25
|
+
_this.addTypename = true;
|
|
26
|
+
_this.mockedResponsesByKey = {};
|
|
27
|
+
_this.addTypename = addTypename;
|
|
28
|
+
if (mockedResponses) {
|
|
29
|
+
mockedResponses.forEach(function (mockedResponse) {
|
|
30
|
+
_this.addMockedResponse(mockedResponse);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return _this;
|
|
34
|
+
}
|
|
35
|
+
MockLink.prototype.addMockedResponse = function (mockedResponse) {
|
|
36
|
+
var normalizedMockedResponse = this.normalizeMockedResponse(mockedResponse);
|
|
37
|
+
var key = requestToKey(normalizedMockedResponse.request, this.addTypename);
|
|
38
|
+
var mockedResponses = this.mockedResponsesByKey[key];
|
|
39
|
+
if (!mockedResponses) {
|
|
40
|
+
mockedResponses = [];
|
|
41
|
+
this.mockedResponsesByKey[key] = mockedResponses;
|
|
42
|
+
}
|
|
43
|
+
mockedResponses.push(normalizedMockedResponse);
|
|
44
|
+
};
|
|
45
|
+
MockLink.prototype.request = function (operation) {
|
|
46
|
+
var _this = this;
|
|
47
|
+
this.operation = operation;
|
|
48
|
+
var key = requestToKey(operation, this.addTypename);
|
|
49
|
+
var unmatchedVars = [];
|
|
50
|
+
var requestVariables = operation.variables || {};
|
|
51
|
+
var mockedResponses = this.mockedResponsesByKey[key];
|
|
52
|
+
var responseIndex = mockedResponses ? mockedResponses.findIndex(function (res, index) {
|
|
53
|
+
var mockedResponseVars = res.request.variables || {};
|
|
54
|
+
if (equality.equal(requestVariables, mockedResponseVars)) {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
unmatchedVars.push(mockedResponseVars);
|
|
58
|
+
return false;
|
|
59
|
+
}) : -1;
|
|
60
|
+
var response = responseIndex >= 0
|
|
61
|
+
? mockedResponses[responseIndex]
|
|
62
|
+
: void 0;
|
|
63
|
+
var configError;
|
|
64
|
+
if (!response) {
|
|
65
|
+
configError = new Error("No more mocked responses for the query: ".concat(graphql.print(operation.query), "\nExpected variables: ").concat(utilities.stringifyForDisplay(operation.variables), "\n").concat(unmatchedVars.length > 0 ? "\nFailed to match ".concat(unmatchedVars.length, " mock").concat(unmatchedVars.length === 1 ? "" : "s", " for this query, which had the following variables:\n").concat(unmatchedVars.map(function (d) { return " ".concat(utilities.stringifyForDisplay(d)); }).join('\n'), "\n") : ""));
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
mockedResponses.splice(responseIndex, 1);
|
|
69
|
+
var newData = response.newData;
|
|
70
|
+
if (newData) {
|
|
71
|
+
response.result = newData();
|
|
72
|
+
mockedResponses.push(response);
|
|
73
|
+
}
|
|
74
|
+
if (!response.result && !response.error) {
|
|
75
|
+
configError = new Error("Mocked response should contain either result or error: ".concat(key));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return new utilities.Observable(function (observer) {
|
|
79
|
+
var timer = setTimeout(function () {
|
|
80
|
+
if (configError) {
|
|
81
|
+
try {
|
|
82
|
+
if (_this.onError(configError, observer) !== false) {
|
|
83
|
+
throw configError;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
observer.error(error);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else if (response) {
|
|
91
|
+
if (response.error) {
|
|
92
|
+
observer.error(response.error);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
if (response.result) {
|
|
96
|
+
observer.next(typeof response.result === 'function'
|
|
97
|
+
? response.result()
|
|
98
|
+
: response.result);
|
|
99
|
+
}
|
|
100
|
+
observer.complete();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}, response && response.delay || 0);
|
|
104
|
+
return function () {
|
|
105
|
+
clearTimeout(timer);
|
|
106
|
+
};
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
MockLink.prototype.normalizeMockedResponse = function (mockedResponse) {
|
|
110
|
+
var newMockedResponse = utilities.cloneDeep(mockedResponse);
|
|
111
|
+
var queryWithoutConnection = utilities.removeConnectionDirectiveFromDocument(newMockedResponse.request.query);
|
|
112
|
+
__DEV__ ? globals.invariant(queryWithoutConnection, "query is required") : globals.invariant(queryWithoutConnection, 35);
|
|
113
|
+
newMockedResponse.request.query = queryWithoutConnection;
|
|
114
|
+
var query = utilities.removeClientSetsFromDocument(newMockedResponse.request.query);
|
|
115
|
+
if (query) {
|
|
116
|
+
newMockedResponse.request.query = query;
|
|
117
|
+
}
|
|
118
|
+
return newMockedResponse;
|
|
119
|
+
};
|
|
120
|
+
return MockLink;
|
|
121
|
+
}(core.ApolloLink));
|
|
122
|
+
function mockSingleLink() {
|
|
123
|
+
var mockedResponses = [];
|
|
124
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
125
|
+
mockedResponses[_i] = arguments[_i];
|
|
126
|
+
}
|
|
127
|
+
var maybeTypename = mockedResponses[mockedResponses.length - 1];
|
|
128
|
+
var mocks = mockedResponses.slice(0, mockedResponses.length - 1);
|
|
129
|
+
if (typeof maybeTypename !== 'boolean') {
|
|
130
|
+
mocks = mockedResponses;
|
|
131
|
+
maybeTypename = true;
|
|
132
|
+
}
|
|
133
|
+
return new MockLink(mocks, maybeTypename);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
var MockSubscriptionLink = (function (_super) {
|
|
137
|
+
tslib.__extends(MockSubscriptionLink, _super);
|
|
138
|
+
function MockSubscriptionLink() {
|
|
139
|
+
var _this = _super.call(this) || this;
|
|
140
|
+
_this.unsubscribers = [];
|
|
141
|
+
_this.setups = [];
|
|
142
|
+
_this.observers = [];
|
|
143
|
+
return _this;
|
|
144
|
+
}
|
|
145
|
+
MockSubscriptionLink.prototype.request = function (operation) {
|
|
146
|
+
var _this = this;
|
|
147
|
+
this.operation = operation;
|
|
148
|
+
return new utilities.Observable(function (observer) {
|
|
149
|
+
_this.setups.forEach(function (x) { return x(); });
|
|
150
|
+
_this.observers.push(observer);
|
|
151
|
+
return function () {
|
|
152
|
+
_this.unsubscribers.forEach(function (x) { return x(); });
|
|
153
|
+
};
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
MockSubscriptionLink.prototype.simulateResult = function (result, complete) {
|
|
157
|
+
var _this = this;
|
|
158
|
+
if (complete === void 0) { complete = false; }
|
|
159
|
+
setTimeout(function () {
|
|
160
|
+
var observers = _this.observers;
|
|
161
|
+
if (!observers.length)
|
|
162
|
+
throw new Error('subscription torn down');
|
|
163
|
+
observers.forEach(function (observer) {
|
|
164
|
+
if (result.result && observer.next)
|
|
165
|
+
observer.next(result.result);
|
|
166
|
+
if (result.error && observer.error)
|
|
167
|
+
observer.error(result.error);
|
|
168
|
+
if (complete && observer.complete)
|
|
169
|
+
observer.complete();
|
|
170
|
+
});
|
|
171
|
+
}, result.delay || 0);
|
|
172
|
+
};
|
|
173
|
+
MockSubscriptionLink.prototype.simulateComplete = function () {
|
|
174
|
+
var observers = this.observers;
|
|
175
|
+
if (!observers.length)
|
|
176
|
+
throw new Error('subscription torn down');
|
|
177
|
+
observers.forEach(function (observer) {
|
|
178
|
+
if (observer.complete)
|
|
179
|
+
observer.complete();
|
|
180
|
+
});
|
|
181
|
+
};
|
|
182
|
+
MockSubscriptionLink.prototype.onSetup = function (listener) {
|
|
183
|
+
this.setups = this.setups.concat([listener]);
|
|
184
|
+
};
|
|
185
|
+
MockSubscriptionLink.prototype.onUnsubscribe = function (listener) {
|
|
186
|
+
this.unsubscribers = this.unsubscribers.concat([listener]);
|
|
187
|
+
};
|
|
188
|
+
return MockSubscriptionLink;
|
|
189
|
+
}(core.ApolloLink));
|
|
190
|
+
function mockObservableLink() {
|
|
191
|
+
return new MockSubscriptionLink();
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function createMockClient(data, query, variables) {
|
|
195
|
+
if (variables === void 0) { variables = {}; }
|
|
196
|
+
return new core$1.ApolloClient({
|
|
197
|
+
link: mockSingleLink({
|
|
198
|
+
request: { query: query, variables: variables },
|
|
199
|
+
result: { data: data },
|
|
200
|
+
}).setOnError(function (error) { throw error; }),
|
|
201
|
+
cache: new cache.InMemoryCache({ addTypename: false }),
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function subscribeAndCount(reject, observable, cb) {
|
|
206
|
+
var queue = Promise.resolve();
|
|
207
|
+
var handleCount = 0;
|
|
208
|
+
var subscription = utilities.asyncMap(observable, function (result) {
|
|
209
|
+
return queue = queue.then(function () {
|
|
210
|
+
return cb(++handleCount, result);
|
|
211
|
+
}).catch(error);
|
|
212
|
+
}).subscribe({ error: error });
|
|
213
|
+
function error(e) {
|
|
214
|
+
subscription.unsubscribe();
|
|
215
|
+
reject(e);
|
|
216
|
+
}
|
|
217
|
+
return subscription;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function wrap(key) {
|
|
221
|
+
return function (message, callback, timeout) { return (key ? it[key] : it)(message, function () {
|
|
222
|
+
var _this = this;
|
|
223
|
+
return new Promise(function (resolve, reject) { return callback.call(_this, resolve, reject); });
|
|
224
|
+
}, timeout); };
|
|
225
|
+
}
|
|
226
|
+
var wrappedIt = wrap();
|
|
227
|
+
var itAsync = Object.assign(function () {
|
|
228
|
+
var args = [];
|
|
229
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
230
|
+
args[_i] = arguments[_i];
|
|
231
|
+
}
|
|
232
|
+
return wrappedIt.apply(this, args);
|
|
233
|
+
}, {
|
|
234
|
+
only: wrap("only"),
|
|
235
|
+
skip: wrap("skip"),
|
|
236
|
+
todo: wrap("todo"),
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
function wrapTestFunction(fn, consoleMethodName) {
|
|
240
|
+
return function () {
|
|
241
|
+
var _this = this;
|
|
242
|
+
var args = arguments;
|
|
243
|
+
var spy = jest.spyOn(console, consoleMethodName);
|
|
244
|
+
spy.mockImplementation(function () { });
|
|
245
|
+
return new Promise(function (resolve) {
|
|
246
|
+
resolve(fn === null || fn === void 0 ? void 0 : fn.apply(_this, args));
|
|
247
|
+
}).finally(function () {
|
|
248
|
+
expect(spy).toMatchSnapshot();
|
|
249
|
+
spy.mockReset();
|
|
250
|
+
});
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
function withErrorSpy(it) {
|
|
254
|
+
var args = [];
|
|
255
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
256
|
+
args[_i - 1] = arguments[_i];
|
|
257
|
+
}
|
|
258
|
+
args[1] = wrapTestFunction(args[1], "error");
|
|
259
|
+
return it.apply(void 0, args);
|
|
260
|
+
}
|
|
261
|
+
function withWarningSpy(it) {
|
|
262
|
+
var args = [];
|
|
263
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
264
|
+
args[_i - 1] = arguments[_i];
|
|
265
|
+
}
|
|
266
|
+
args[1] = wrapTestFunction(args[1], "warn");
|
|
267
|
+
return it.apply(void 0, args);
|
|
268
|
+
}
|
|
269
|
+
function withLogSpy(it) {
|
|
270
|
+
var args = [];
|
|
271
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
272
|
+
args[_i - 1] = arguments[_i];
|
|
273
|
+
}
|
|
274
|
+
args[1] = wrapTestFunction(args[1], "log");
|
|
275
|
+
return it.apply(void 0, args);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
exports.MockLink = MockLink;
|
|
279
|
+
exports.MockSubscriptionLink = MockSubscriptionLink;
|
|
280
|
+
exports.createMockClient = createMockClient;
|
|
281
|
+
exports.itAsync = itAsync;
|
|
282
|
+
exports.mockObservableLink = mockObservableLink;
|
|
283
|
+
exports.mockSingleLink = mockSingleLink;
|
|
284
|
+
exports.subscribeAndCount = subscribeAndCount;
|
|
285
|
+
exports.withErrorSpy = withErrorSpy;
|
|
286
|
+
exports.withLogSpy = withLogSpy;
|
|
287
|
+
exports.withWarningSpy = withWarningSpy;
|
|
288
|
+
//# sourceMappingURL=core.cjs.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
require('../utilities/globals');
|
|
6
|
+
var tslib = require('tslib');
|
|
7
|
+
var React = require('react');
|
|
8
|
+
var core$1 = require('../core');
|
|
9
|
+
var cache = require('../cache');
|
|
10
|
+
var context = require('../react/context');
|
|
11
|
+
var core = require('./core');
|
|
12
|
+
|
|
13
|
+
function _interopNamespace(e) {
|
|
14
|
+
if (e && e.__esModule) return e;
|
|
15
|
+
var n = Object.create(null);
|
|
16
|
+
if (e) {
|
|
17
|
+
for (var k in e) {
|
|
18
|
+
n[k] = e[k];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
n["default"] = e;
|
|
22
|
+
return Object.freeze(n);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
26
|
+
|
|
27
|
+
var MockedProvider = (function (_super) {
|
|
28
|
+
tslib.__extends(MockedProvider, _super);
|
|
29
|
+
function MockedProvider(props) {
|
|
30
|
+
var _this = _super.call(this, props) || this;
|
|
31
|
+
var _a = _this.props, mocks = _a.mocks, addTypename = _a.addTypename, defaultOptions = _a.defaultOptions, cache$1 = _a.cache, resolvers = _a.resolvers, link = _a.link;
|
|
32
|
+
var client = new core$1.ApolloClient({
|
|
33
|
+
cache: cache$1 || new cache.InMemoryCache({ addTypename: addTypename }),
|
|
34
|
+
defaultOptions: defaultOptions,
|
|
35
|
+
link: link || new core.MockLink(mocks || [], addTypename),
|
|
36
|
+
resolvers: resolvers,
|
|
37
|
+
});
|
|
38
|
+
_this.state = { client: client };
|
|
39
|
+
return _this;
|
|
40
|
+
}
|
|
41
|
+
MockedProvider.prototype.render = function () {
|
|
42
|
+
var _a = this.props, children = _a.children, childProps = _a.childProps;
|
|
43
|
+
return React__namespace.isValidElement(children) ? (React__namespace.createElement(context.ApolloProvider, { client: this.state.client }, React__namespace.cloneElement(React__namespace.Children.only(children), tslib.__assign({}, childProps)))) : null;
|
|
44
|
+
};
|
|
45
|
+
MockedProvider.prototype.componentWillUnmount = function () {
|
|
46
|
+
this.state.client.stop();
|
|
47
|
+
};
|
|
48
|
+
MockedProvider.defaultProps = {
|
|
49
|
+
addTypename: true
|
|
50
|
+
};
|
|
51
|
+
return MockedProvider;
|
|
52
|
+
}(React__namespace.Component));
|
|
53
|
+
|
|
54
|
+
exports.MockedProvider = MockedProvider;
|
|
55
|
+
for (var k in core) {
|
|
56
|
+
if (k !== 'default' && !exports.hasOwnProperty(k)) exports[k] = core[k];
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=testing.cjs.map
|