@apollo/client 3.5.10 → 3.6.4

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.
Files changed (144) hide show
  1. package/LICENSE +1 -1
  2. package/apollo-client.cjs +509 -341
  3. package/apollo-client.cjs.map +1 -1
  4. package/apollo-client.min.cjs +1 -1
  5. package/cache/cache.cjs.native.js +2289 -0
  6. package/core/ApolloClient.d.ts +2 -3
  7. package/core/ApolloClient.d.ts.map +1 -1
  8. package/core/ApolloClient.js +4 -8
  9. package/core/ApolloClient.js.map +1 -1
  10. package/core/ObservableQuery.d.ts +10 -4
  11. package/core/ObservableQuery.d.ts.map +1 -1
  12. package/core/ObservableQuery.js +97 -45
  13. package/core/ObservableQuery.js.map +1 -1
  14. package/core/QueryInfo.d.ts.map +1 -1
  15. package/core/QueryInfo.js +4 -2
  16. package/core/QueryInfo.js.map +1 -1
  17. package/core/QueryManager.d.ts +5 -2
  18. package/core/QueryManager.d.ts.map +1 -1
  19. package/core/QueryManager.js +29 -23
  20. package/core/QueryManager.js.map +1 -1
  21. package/core/core.cjs +138 -85
  22. package/core/core.cjs.map +1 -1
  23. package/core/core.cjs.native.js +2141 -0
  24. package/core/index.d.ts +1 -1
  25. package/core/index.d.ts.map +1 -1
  26. package/core/index.js +1 -1
  27. package/core/index.js.map +1 -1
  28. package/core/watchQueryOptions.d.ts +9 -1
  29. package/core/watchQueryOptions.d.ts.map +1 -1
  30. package/core/watchQueryOptions.js.map +1 -1
  31. package/errors/errors.cjs.native.js +48 -0
  32. package/invariantErrorCodes.js +1 -1
  33. package/link/batch/batch.cjs +47 -37
  34. package/link/batch/batch.cjs.map +1 -1
  35. package/link/batch/batch.cjs.native.js +161 -0
  36. package/link/batch/batching.d.ts +2 -6
  37. package/link/batch/batching.d.ts.map +1 -1
  38. package/link/batch/batching.js +47 -37
  39. package/link/batch/batching.js.map +1 -1
  40. package/link/batch-http/batch-http.cjs.native.js +127 -0
  41. package/link/context/context.cjs.native.js +38 -0
  42. package/link/core/core.cjs.native.js +121 -0
  43. package/link/error/error.cjs.native.js +90 -0
  44. package/link/http/http.cjs.native.js +320 -0
  45. package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
  46. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  47. package/link/persisted-queries/index.d.ts +2 -1
  48. package/link/persisted-queries/index.d.ts.map +1 -1
  49. package/link/persisted-queries/index.js +26 -13
  50. package/link/persisted-queries/index.js.map +1 -1
  51. package/link/persisted-queries/persisted-queries.cjs +25 -12
  52. package/link/persisted-queries/persisted-queries.cjs.map +1 -1
  53. package/link/persisted-queries/persisted-queries.cjs.native.js +174 -0
  54. package/link/retry/retry.cjs.native.js +170 -0
  55. package/link/schema/schema.cjs.native.js +56 -0
  56. package/link/subscriptions/subscriptions.cjs.native.js +45 -0
  57. package/link/utils/utils.cjs.native.js +115 -0
  58. package/link/ws/ws.cjs.native.js +28 -0
  59. package/main.cjs.native.js +16 -0
  60. package/package.json +28 -26
  61. package/react/components/components.cjs.native.js +79 -0
  62. package/react/context/ApolloConsumer.js +2 -2
  63. package/react/context/ApolloProvider.js +2 -2
  64. package/react/context/context.cjs +4 -4
  65. package/react/context/context.cjs.map +1 -1
  66. package/react/context/context.cjs.native.js +67 -0
  67. package/react/hoc/hoc.cjs.native.js +325 -0
  68. package/react/hooks/hooks.cjs +351 -247
  69. package/react/hooks/hooks.cjs.map +1 -1
  70. package/react/hooks/hooks.cjs.native.js +604 -0
  71. package/react/hooks/index.d.ts +1 -1
  72. package/react/hooks/index.d.ts.map +1 -1
  73. package/react/hooks/index.js +1 -1
  74. package/react/hooks/index.js.map +1 -1
  75. package/react/hooks/useLazyQuery.d.ts +2 -2
  76. package/react/hooks/useLazyQuery.d.ts.map +1 -1
  77. package/react/hooks/useLazyQuery.js +22 -21
  78. package/react/hooks/useLazyQuery.js.map +1 -1
  79. package/react/hooks/useMutation.d.ts.map +1 -1
  80. package/react/hooks/useMutation.js +6 -3
  81. package/react/hooks/useMutation.js.map +1 -1
  82. package/react/hooks/useQuery.d.ts +36 -2
  83. package/react/hooks/useQuery.d.ts.map +1 -1
  84. package/react/hooks/useQuery.js +238 -204
  85. package/react/hooks/useQuery.js.map +1 -1
  86. package/react/hooks/useSubscription.d.ts.map +1 -1
  87. package/react/hooks/useSubscription.js +17 -7
  88. package/react/hooks/useSubscription.js.map +1 -1
  89. package/react/hooks/useSyncExternalStore.d.ts +4 -0
  90. package/react/hooks/useSyncExternalStore.d.ts.map +1 -0
  91. package/react/hooks/useSyncExternalStore.js +48 -0
  92. package/react/hooks/useSyncExternalStore.js.map +1 -0
  93. package/react/parser/index.d.ts.map +1 -1
  94. package/react/parser/index.js +24 -10
  95. package/react/parser/index.js.map +1 -1
  96. package/react/parser/parser.cjs +24 -10
  97. package/react/parser/parser.cjs.map +1 -1
  98. package/react/parser/parser.cjs.native.js +103 -0
  99. package/react/react.cjs.native.js +22 -0
  100. package/react/ssr/RenderPromises.d.ts +3 -2
  101. package/react/ssr/RenderPromises.d.ts.map +1 -1
  102. package/react/ssr/RenderPromises.js +25 -3
  103. package/react/ssr/RenderPromises.js.map +1 -1
  104. package/react/ssr/ssr.cjs +25 -3
  105. package/react/ssr/ssr.cjs.map +1 -1
  106. package/react/ssr/ssr.cjs.native.js +150 -0
  107. package/react/types/types.d.ts +10 -11
  108. package/react/types/types.d.ts.map +1 -1
  109. package/react/types/types.js.map +1 -1
  110. package/testing/core/core.cjs.native.js +288 -0
  111. package/testing/core/mocking/mockFetch.js +1 -1
  112. package/testing/core/mocking/mockFetch.js.map +1 -1
  113. package/testing/core/mocking/mockQueryManager.js +1 -1
  114. package/testing/core/mocking/mockWatchQuery.js +1 -1
  115. package/testing/core/wrap.js +1 -1
  116. package/testing/testing.cjs.native.js +58 -0
  117. package/utilities/common/canUse.d.ts +2 -0
  118. package/utilities/common/canUse.d.ts.map +1 -1
  119. package/utilities/common/canUse.js +6 -2
  120. package/utilities/common/canUse.js.map +1 -1
  121. package/utilities/common/mergeOptions.d.ts +5 -0
  122. package/utilities/common/mergeOptions.d.ts.map +1 -0
  123. package/utilities/common/mergeOptions.js +8 -0
  124. package/utilities/common/mergeOptions.js.map +1 -0
  125. package/utilities/globals/global.js +1 -2
  126. package/utilities/globals/globals.cjs.native.js +56 -0
  127. package/utilities/graphql/transform.d.ts +2 -2
  128. package/utilities/graphql/transform.d.ts.map +1 -1
  129. package/utilities/graphql/transform.js +1 -1
  130. package/utilities/graphql/transform.js.map +1 -1
  131. package/utilities/index.d.ts +1 -0
  132. package/utilities/index.d.ts.map +1 -1
  133. package/utilities/index.js +1 -0
  134. package/utilities/index.js.map +1 -1
  135. package/utilities/observables/Concast.d.ts.map +1 -1
  136. package/utilities/observables/Concast.js +5 -2
  137. package/utilities/observables/Concast.js.map +1 -1
  138. package/utilities/policies/pagination.d.ts.map +1 -1
  139. package/utilities/policies/pagination.js +9 -7
  140. package/utilities/policies/pagination.js.map +1 -1
  141. package/utilities/utilities.cjs +29 -12
  142. package/utilities/utilities.cjs.map +1 -1
  143. package/utilities/utilities.cjs.native.js +1284 -0
  144. package/version.js +1 -1
@@ -23,6 +23,12 @@ export function useSubscription(subscription, options) {
23
23
  context: options === null || options === void 0 ? void 0 : options.context,
24
24
  });
25
25
  }), observable = _b[0], setObservable = _b[1];
26
+ var canResetObservableRef = useRef(false);
27
+ useEffect(function () {
28
+ return function () {
29
+ canResetObservableRef.current = true;
30
+ };
31
+ }, []);
26
32
  var ref = useRef({ client: client, subscription: subscription, options: options });
27
33
  useEffect(function () {
28
34
  var _a, _b, _c, _d;
@@ -31,7 +37,7 @@ export function useSubscription(subscription, options) {
31
37
  shouldResubscribe = !!shouldResubscribe(options);
32
38
  }
33
39
  if (options === null || options === void 0 ? void 0 : options.skip) {
34
- if (!(options === null || options === void 0 ? void 0 : options.skip) !== !((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.skip)) {
40
+ if (!(options === null || options === void 0 ? void 0 : options.skip) !== !((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.skip) || canResetObservableRef.current) {
35
41
  setResult({
36
42
  loading: false,
37
43
  data: void 0,
@@ -39,13 +45,16 @@ export function useSubscription(subscription, options) {
39
45
  variables: options === null || options === void 0 ? void 0 : options.variables,
40
46
  });
41
47
  setObservable(null);
48
+ canResetObservableRef.current = false;
42
49
  }
43
50
  }
44
- else if (shouldResubscribe !== false && (client !== ref.current.client ||
45
- subscription !== ref.current.subscription ||
46
- (options === null || options === void 0 ? void 0 : options.fetchPolicy) !== ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
47
- !(options === null || options === void 0 ? void 0 : options.skip) !== !((_c = ref.current.options) === null || _c === void 0 ? void 0 : _c.skip) ||
48
- !equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) {
51
+ else if ((shouldResubscribe !== false &&
52
+ (client !== ref.current.client ||
53
+ subscription !== ref.current.subscription ||
54
+ (options === null || options === void 0 ? void 0 : options.fetchPolicy) !== ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
55
+ !(options === null || options === void 0 ? void 0 : options.skip) !== !((_c = ref.current.options) === null || _c === void 0 ? void 0 : _c.skip) ||
56
+ !equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) ||
57
+ canResetObservableRef.current) {
49
58
  setResult({
50
59
  loading: true,
51
60
  data: void 0,
@@ -58,9 +67,10 @@ export function useSubscription(subscription, options) {
58
67
  fetchPolicy: options === null || options === void 0 ? void 0 : options.fetchPolicy,
59
68
  context: options === null || options === void 0 ? void 0 : options.context,
60
69
  }));
70
+ canResetObservableRef.current = false;
61
71
  }
62
72
  Object.assign(ref.current, { client: client, subscription: subscription, options: options });
63
- }, [client, subscription, options]);
73
+ }, [client, subscription, options, canResetObservableRef.current]);
64
74
  useEffect(function () {
65
75
  if (!observable) {
66
76
  return;
@@ -1 +1 @@
1
- {"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G;oBACxC,MAAM,QAAA;oBACN,gBAAgB,EAAE,MAAM;iBACzB,CAAC,CAAC;YACL,CAAC;YACD,KAAK,YAAC,KAAK;gBACT,SAAS,CAAC;oBACR,OAAO,EAAE,KAAK;oBACd,IAAI,EAAE,KAAK,CAAC;oBACZ,KAAK,OAAA;oBACL,SAAS,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS;iBAC9B,CAAC,CAAC;YACL,CAAC;YACD,QAAQ;;gBACN,MAAA,MAAA,GAAG,CAAC,OAAO,CAAC,OAAO,0CAAE,sBAAsB,kDAAI,CAAC;YAClD,CAAC;SACF,CAAC,CAAC;QAEH,OAAO;YACL,YAAY,CAAC,WAAW,EAAE,CAAC;QAC7B,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;IAEjB,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import '../../utilities/globals';\nimport { useState, useRef, useEffect } from 'react';\nimport { DocumentNode } from 'graphql';\nimport { TypedDocumentNode } from '@graphql-typed-document-node/core';\nimport { equal } from '@wry/equality';\n\nimport { DocumentType, verifyDocumentType } from '../parser';\nimport {\n SubscriptionHookOptions,\n SubscriptionResult\n} from '../types/types';\nimport { OperationVariables } from '../../core';\nimport { useApolloClient } from './useApolloClient';\n\nexport function useSubscription<TData = any, TVariables = OperationVariables>(\n subscription: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: SubscriptionHookOptions<TData, TVariables>,\n) {\n const client = useApolloClient(options?.client);\n verifyDocumentType(subscription, DocumentType.Subscription);\n const [result, setResult] = useState<SubscriptionResult<TData>>({\n loading: !options?.skip,\n error: void 0,\n data: void 0,\n variables: options?.variables,\n });\n\n const [observable, setObservable] = useState(() => {\n if (options?.skip) {\n return null;\n }\n\n return client.subscribe({\n query: subscription,\n variables: options?.variables,\n fetchPolicy: options?.fetchPolicy,\n context: options?.context,\n });\n });\n\n const ref = useRef({ client, subscription, options });\n useEffect(() => {\n let shouldResubscribe = options?.shouldResubscribe;\n if (typeof shouldResubscribe === 'function') {\n shouldResubscribe = !!shouldResubscribe(options!);\n }\n\n if (options?.skip) {\n if (!options?.skip !== !ref.current.options?.skip) {\n setResult({\n loading: false,\n data: void 0,\n error: void 0,\n variables: options?.variables,\n });\n setObservable(null);\n }\n } else if (\n shouldResubscribe !== false && (\n client !== ref.current.client ||\n subscription !== ref.current.subscription ||\n options?.fetchPolicy !== ref.current.options?.fetchPolicy ||\n !options?.skip !== !ref.current.options?.skip ||\n !equal(options?.variables, ref.current.options?.variables)\n )\n ) {\n setResult({\n loading: true,\n data: void 0,\n error: void 0,\n variables: options?.variables,\n });\n setObservable(client.subscribe({\n query: subscription,\n variables: options?.variables,\n fetchPolicy: options?.fetchPolicy,\n context: options?.context,\n }));\n }\n\n Object.assign(ref.current, { client, subscription, options });\n }, [client, subscription, options]);\n\n useEffect(() => {\n if (!observable) {\n return;\n }\n\n const subscription = observable.subscribe({\n next(fetchResult) {\n const result = {\n loading: false,\n // TODO: fetchResult.data can be null but SubscriptionResult.data\n // expects TData | undefined only\n data: fetchResult.data!,\n error: void 0,\n variables: options?.variables,\n };\n setResult(result);\n\n ref.current.options?.onSubscriptionData?.({\n client,\n subscriptionData: result\n });\n },\n error(error) {\n setResult({\n loading: false,\n data: void 0,\n error,\n variables: options?.variables,\n });\n },\n complete() {\n ref.current.options?.onSubscriptionComplete?.();\n },\n });\n\n return () => {\n subscription.unsubscribe();\n };\n }, [observable]);\n\n return result;\n}\n"]}
1
+ {"version":3,"file":"useSubscription.js","sourceRoot":"","sources":["../../../src/react/hooks/useSubscription.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGpD,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAM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,CAAC,CAAC;gBAElB,MAAA,MAAA,GAAG,CAAC,OAAO,CAAC,OAAO,0CAAE,kBAAkB,mDAAG;oBACxC,MAAM,QAAA;oBACN,gBAAgB,EAAE,MAAM;iBACzB,CAAC,CAAC;YACL,CAAC;YACD,KAAK,YAAC,KAAK;gBACT,SAAS,CAAC;oBACR,OAAO,EAAE,KAAK;oBACd,IAAI,EAAE,KAAK,CAAC;oBACZ,KAAK,OAAA;oBACL,SAAS,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS;iBAC9B,CAAC,CAAC;YACL,CAAC;YACD,QAAQ;;gBACN,MAAA,MAAA,GAAG,CAAC,OAAO,CAAC,OAAO,0CAAE,sBAAsB,kDAAI,CAAC;YAClD,CAAC;SACF,CAAC,CAAC;QAEH,OAAO;YACL,YAAY,CAAC,WAAW,EAAE,CAAC;QAC7B,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;IAEjB,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import '../../utilities/globals';\nimport { useState, useRef, useEffect } from 'react';\nimport { DocumentNode } from 'graphql';\nimport { TypedDocumentNode } from '@graphql-typed-document-node/core';\nimport { equal } from '@wry/equality';\n\nimport { DocumentType, verifyDocumentType } from '../parser';\nimport {\n SubscriptionHookOptions,\n SubscriptionResult\n} from '../types/types';\nimport { OperationVariables } from '../../core';\nimport { useApolloClient } from './useApolloClient';\n\nexport function useSubscription<TData = any, TVariables = OperationVariables>(\n subscription: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: SubscriptionHookOptions<TData, TVariables>,\n) {\n const client = useApolloClient(options?.client);\n verifyDocumentType(subscription, DocumentType.Subscription);\n const [result, setResult] = useState<SubscriptionResult<TData>>({\n loading: !options?.skip,\n error: void 0,\n data: void 0,\n variables: options?.variables,\n });\n\n const [observable, setObservable] = useState(() => {\n if (options?.skip) {\n return null;\n }\n\n return client.subscribe({\n query: subscription,\n variables: options?.variables,\n fetchPolicy: options?.fetchPolicy,\n context: options?.context,\n });\n });\n\n const canResetObservableRef = useRef(false);\n useEffect(() => {\n return () => {\n canResetObservableRef.current = true;\n };\n }, []);\n\n const ref = useRef({ client, subscription, options });\n useEffect(() => {\n let shouldResubscribe = options?.shouldResubscribe;\n if (typeof shouldResubscribe === 'function') {\n shouldResubscribe = !!shouldResubscribe(options!);\n }\n\n if (options?.skip) {\n if (!options?.skip !== !ref.current.options?.skip || canResetObservableRef.current) {\n setResult({\n loading: false,\n data: void 0,\n error: void 0,\n variables: options?.variables,\n });\n setObservable(null);\n canResetObservableRef.current = false;\n }\n } else if (\n (shouldResubscribe !== false &&\n (client !== ref.current.client ||\n subscription !== ref.current.subscription ||\n options?.fetchPolicy !== ref.current.options?.fetchPolicy ||\n !options?.skip !== !ref.current.options?.skip ||\n !equal(options?.variables, ref.current.options?.variables))) ||\n canResetObservableRef.current\n ) {\n setResult({\n loading: true,\n data: void 0,\n error: void 0,\n variables: options?.variables,\n });\n setObservable(client.subscribe({\n query: subscription,\n variables: options?.variables,\n fetchPolicy: options?.fetchPolicy,\n context: options?.context,\n }));\n canResetObservableRef.current = false;\n }\n\n Object.assign(ref.current, { client, subscription, options });\n }, [client, subscription, options, canResetObservableRef.current]);\n\n useEffect(() => {\n if (!observable) {\n return;\n }\n\n const subscription = observable.subscribe({\n next(fetchResult) {\n const result = {\n loading: false,\n // TODO: fetchResult.data can be null but SubscriptionResult.data\n // expects TData | undefined only\n data: fetchResult.data!,\n error: void 0,\n variables: options?.variables,\n };\n setResult(result);\n\n ref.current.options?.onSubscriptionData?.({\n client,\n subscriptionData: result\n });\n },\n error(error) {\n setResult({\n loading: false,\n data: void 0,\n error,\n variables: options?.variables,\n });\n },\n complete() {\n ref.current.options?.onSubscriptionComplete?.();\n },\n });\n\n return () => {\n subscription.unsubscribe();\n };\n }, [observable]);\n\n return result;\n}\n"]}
@@ -0,0 +1,4 @@
1
+ declare type RealUseSESHookType = typeof import("use-sync-external-store").useSyncExternalStore;
2
+ export declare const useSyncExternalStore: RealUseSESHookType;
3
+ export {};
4
+ //# sourceMappingURL=useSyncExternalStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSyncExternalStore.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useSyncExternalStore.ts"],"names":[],"mappings":"AAOA,aAAK,kBAAkB,GAKrB,cAAc,yBAAyB,EAAE,oBAAoB,CAAC;AAYhE,eAAO,MAAM,oBAAoB,EAAE,kBAyFjC,CAAC"}
@@ -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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/parser/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,YAAY,EAEZ,sBAAsB,EAEvB,MAAM,SAAS,CAAC;AAEjB,oBAAY,YAAY;IACtB,KAAK,IAAA;IACL,QAAQ,IAAA;IACR,YAAY,IAAA;CACb;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,YAAY,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,aAAa,CAAC,sBAAsB,CAAC,CAAC;CAClD;AAID,wBAAgB,aAAa,CAAC,IAAI,EAAE,YAAY,UAc/C;AAGD,wBAAgB,MAAM,CAAC,QAAQ,EAAE,YAAY,GAAG,mBAAmB,CA2ElE;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,YAAY,EAAE,IAAI,EAAE,YAAY,QAS5E"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/parser/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,YAAY,EAEZ,sBAAsB,EAEvB,MAAM,SAAS,CAAC;AAEjB,oBAAY,YAAY;IACtB,KAAK,IAAA;IACL,QAAQ,IAAA;IACR,YAAY,IAAA;CACb;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,YAAY,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,aAAa,CAAC,sBAAsB,CAAC,CAAC;CAClD;AAID,wBAAgB,aAAa,CAAC,IAAI,EAAE,YAAY,UAc/C;AAGD,wBAAgB,MAAM,CAAC,QAAQ,EAAE,YAAY,GAAG,mBAAmB,CAkFlE;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,YAAY,EAAE,IAAI,EAAE,YAAY,QAS5E"}
@@ -29,16 +29,30 @@ export function parser(document) {
29
29
  __DEV__ ? invariant(!!document && !!document.kind, "Argument of ".concat(document, " passed to parser was not a valid GraphQL ") +
30
30
  "DocumentNode. You may need to use 'graphql-tag' or another method " +
31
31
  "to convert your operation into a document") : invariant(!!document && !!document.kind, 30);
32
- var fragments = document.definitions.filter(function (x) { return x.kind === 'FragmentDefinition'; });
33
- var queries = document.definitions.filter(function (x) {
34
- return x.kind === 'OperationDefinition' && x.operation === 'query';
35
- });
36
- var mutations = document.definitions.filter(function (x) {
37
- return x.kind === 'OperationDefinition' && x.operation === 'mutation';
38
- });
39
- var subscriptions = document.definitions.filter(function (x) {
40
- return x.kind === 'OperationDefinition' && x.operation === 'subscription';
41
- });
32
+ var fragments = [];
33
+ var queries = [];
34
+ var mutations = [];
35
+ var subscriptions = [];
36
+ for (var _i = 0, _a = document.definitions; _i < _a.length; _i++) {
37
+ var x = _a[_i];
38
+ if (x.kind === 'FragmentDefinition') {
39
+ fragments.push(x);
40
+ continue;
41
+ }
42
+ if (x.kind === 'OperationDefinition') {
43
+ switch (x.operation) {
44
+ case 'query':
45
+ queries.push(x);
46
+ break;
47
+ case 'mutation':
48
+ mutations.push(x);
49
+ break;
50
+ case 'subscription':
51
+ subscriptions.push(x);
52
+ break;
53
+ }
54
+ }
55
+ }
42
56
  __DEV__ ? invariant(!fragments.length ||
43
57
  (queries.length || mutations.length || subscriptions.length), "Passing only a fragment to 'graphql' is not yet supported. " +
44
58
  "You must include a query, subscription or mutation as well") : invariant(!fragments.length ||
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/react/parser/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AASpD,MAAM,CAAN,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,iDAAK,CAAA;IACL,uDAAQ,CAAA;IACR,+DAAY,CAAA;AACd,CAAC,EAJW,YAAY,KAAZ,YAAY,QAIvB;AAQD,IAAM,KAAK,GAAG,IAAI,GAAG,EAAE,CAAC;AAExB,MAAM,UAAU,aAAa,CAAC,IAAkB;IAC9C,IAAI,IAAI,CAAC;IACT,QAAQ,IAAI,EAAE;QACZ,KAAK,YAAY,CAAC,KAAK;YACrB,IAAI,GAAG,OAAO,CAAC;YACf,MAAM;QACR,KAAK,YAAY,CAAC,QAAQ;YACxB,IAAI,GAAG,UAAU,CAAC;YAClB,MAAM;QACR,KAAK,YAAY,CAAC,YAAY;YAC5B,IAAI,GAAG,cAAc,CAAC;YACtB,MAAM;KACT;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAGD,MAAM,UAAU,MAAM,CAAC,QAAsB;IAC3C,IAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACnC,IAAI,MAAM;QAAE,OAAO,MAAM,CAAC;IAE1B,IAAI,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC;IAE1B,SAAS,CACP,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,QAAQ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SAAS,CAAC,IAAI,KAAK,IAAI,EACvB,oBAAa,qBAAqB,yBAAsB;QACtD,UAAG,qBAAqB,qBAAW,iBAAiB,uBAAoB,CAC3E,CAAC;AACJ,CAAC","sourcesContent":["import { invariant } from '../../utilities/globals';\n\nimport {\n DocumentNode,\n DefinitionNode,\n VariableDefinitionNode,\n OperationDefinitionNode\n} from 'graphql';\n\nexport enum DocumentType {\n Query,\n Mutation,\n Subscription\n}\n\nexport interface IDocumentDefinition {\n type: DocumentType;\n name: string;\n variables: ReadonlyArray<VariableDefinitionNode>;\n}\n\nconst cache = new Map();\n\nexport function operationName(type: DocumentType) {\n let name;\n switch (type) {\n case DocumentType.Query:\n name = 'Query';\n break;\n case DocumentType.Mutation:\n name = 'Mutation';\n break;\n case DocumentType.Subscription:\n name = 'Subscription';\n break;\n }\n return name;\n}\n\n// This parser is mostly used to safety check incoming documents.\nexport function parser(document: DocumentNode): IDocumentDefinition {\n const cached = cache.get(document);\n if (cached) return cached;\n\n let variables, type, name;\n\n invariant(\n !!document && !!document.kind,\n `Argument of ${document} passed to parser was not a valid GraphQL ` +\n `DocumentNode. You may need to use 'graphql-tag' or another method ` +\n `to convert your operation into a document`\n );\n\n const fragments = document.definitions.filter(\n (x: DefinitionNode) => x.kind === 'FragmentDefinition'\n );\n\n const queries = document.definitions.filter(\n (x: DefinitionNode) =>\n x.kind === 'OperationDefinition' && x.operation === 'query'\n );\n\n const mutations = document.definitions.filter(\n (x: DefinitionNode) =>\n x.kind === 'OperationDefinition' && x.operation === 'mutation'\n );\n\n const subscriptions = document.definitions.filter(\n (x: DefinitionNode) =>\n x.kind === 'OperationDefinition' && x.operation === 'subscription'\n );\n\n invariant(\n !fragments.length ||\n (queries.length || mutations.length || subscriptions.length),\n `Passing only a fragment to 'graphql' is not yet supported. ` +\n `You must include a query, subscription or mutation as well`\n );\n\n invariant(\n queries.length + mutations.length + subscriptions.length <= 1,\n `react-apollo only supports a query, subscription, or a mutation per HOC. ` +\n `${document} had ${queries.length} queries, ${subscriptions.length} ` +\n `subscriptions and ${mutations.length} mutations. ` +\n `You can use 'compose' to join multiple operation types to a component`\n );\n\n type = queries.length ? DocumentType.Query : DocumentType.Mutation;\n if (!queries.length && !mutations.length) type = DocumentType.Subscription;\n\n const definitions = queries.length\n ? queries\n : mutations.length\n ? mutations\n : subscriptions;\n\n invariant(\n definitions.length === 1,\n `react-apollo only supports one definition per HOC. ${document} had ` +\n `${definitions.length} definitions. ` +\n `You can use 'compose' to join multiple operation types to a component`\n );\n\n const definition = definitions[0] as OperationDefinitionNode;\n variables = definition.variableDefinitions || [];\n\n if (definition.name && definition.name.kind === 'Name') {\n name = definition.name.value;\n } else {\n name = 'data'; // fallback to using data if no name\n }\n\n const payload = { name, type, variables };\n cache.set(document, payload);\n return payload;\n}\n\nexport function verifyDocumentType(document: DocumentNode, type: DocumentType) {\n const operation = parser(document);\n const requiredOperationName = operationName(type);\n const usedOperationName = operationName(operation.type);\n invariant(\n operation.type === type,\n `Running a ${requiredOperationName} requires a graphql ` +\n `${requiredOperationName}, but a ${usedOperationName} was used instead.`\n );\n}\n\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/react/parser/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AASpD,MAAM,CAAN,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,iDAAK,CAAA;IACL,uDAAQ,CAAA;IACR,+DAAY,CAAA;AACd,CAAC,EAJW,YAAY,KAAZ,YAAY,QAIvB;AAQD,IAAM,KAAK,GAAG,IAAI,GAAG,EAAE,CAAC;AAExB,MAAM,UAAU,aAAa,CAAC,IAAkB;IAC9C,IAAI,IAAI,CAAC;IACT,QAAQ,IAAI,EAAE;QACZ,KAAK,YAAY,CAAC,KAAK;YACrB,IAAI,GAAG,OAAO,CAAC;YACf,MAAM;QACR,KAAK,YAAY,CAAC,QAAQ;YACxB,IAAI,GAAG,UAAU,CAAC;YAClB,MAA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AAI,MAAA,EAAE,SAAS,WAAA,EAAE,CAAC;IAC1C,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC7B,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,QAAsB,EAAE,IAAkB;IAC3E,IAAM,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;IACnC,IAAM,qBAAqB,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;IAClD,IAAM,iBAAiB,GAAG,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IACxD,SAAS,CACP,SAAS,CAAC,IAAI,KAAK,IAAI,EACvB,oBAAa,qBAAqB,yBAAsB;QACtD,UAAG,qBAAqB,qBAAW,iBAAiB,uBAAoB,CAC3E,CAAC;AACJ,CAAC","sourcesContent":["import { invariant } from '../../utilities/globals';\n\nimport {\n DocumentNode,\n DefinitionNode,\n VariableDefinitionNode,\n OperationDefinitionNode\n} from 'graphql';\n\nexport enum DocumentType {\n Query,\n Mutation,\n Subscription\n}\n\nexport interface IDocumentDefinition {\n type: DocumentType;\n name: string;\n variables: ReadonlyArray<VariableDefinitionNode>;\n}\n\nconst cache = new Map();\n\nexport function operationName(type: DocumentType) {\n let name;\n switch (type) {\n case DocumentType.Query:\n name = 'Query';\n break;\n case DocumentType.Mutation:\n name = 'Mutation';\n break;\n case DocumentType.Subscription:\n name = 'Subscription';\n break;\n }\n return name;\n}\n\n// This parser is mostly used to safety check incoming documents.\nexport function parser(document: DocumentNode): IDocumentDefinition {\n const cached = cache.get(document);\n if (cached) return cached;\n\n let variables, type, name;\n\n invariant(\n !!document && !!document.kind,\n `Argument of ${document} passed to parser was not a valid GraphQL ` +\n `DocumentNode. You may need to use 'graphql-tag' or another method ` +\n `to convert your operation into a document`\n );\n\n const fragments: DefinitionNode[] = []\n const queries: DefinitionNode[] = []\n const mutations: DefinitionNode[] = []\n const subscriptions: DefinitionNode[] = []\n\n for (const x of document.definitions) {\n if (x.kind === 'FragmentDefinition') {\n fragments.push(x);\n continue\n }\n\n if (x.kind === 'OperationDefinition') {\n switch (x.operation) {\n case 'query':\n queries.push(x);\n break;\n case 'mutation':\n mutations.push(x);\n break;\n case 'subscription':\n subscriptions.push(x);\n break;\n }\n }\n }\n\n invariant(\n !fragments.length ||\n (queries.length || mutations.length || subscriptions.length),\n `Passing only a fragment to 'graphql' is not yet supported. ` +\n `You must include a query, subscription or mutation as well`\n );\n\n invariant(\n queries.length + mutations.length + subscriptions.length <= 1,\n `react-apollo only supports a query, subscription, or a mutation per HOC. ` +\n `${document} had ${queries.length} queries, ${subscriptions.length} ` +\n `subscriptions and ${mutations.length} mutations. ` +\n `You can use 'compose' to join multiple operation types to a component`\n );\n\n type = queries.length ? DocumentType.Query : DocumentType.Mutation;\n if (!queries.length && !mutations.length) type = DocumentType.Subscription;\n\n const definitions = queries.length\n ? queries\n : mutations.length\n ? mutations\n : subscriptions;\n\n invariant(\n definitions.length === 1,\n `react-apollo only supports one definition per HOC. ${document} had ` +\n `${definitions.length} definitions. ` +\n `You can use 'compose' to join multiple operation types to a component`\n );\n\n const definition = definitions[0] as OperationDefinitionNode;\n variables = definition.variableDefinitions || [];\n\n if (definition.name && definition.name.kind === 'Name') {\n name = definition.name.value;\n } else {\n name = 'data'; // fallback to using data if no name\n }\n\n const payload = { name, type, variables };\n cache.set(document, payload);\n return payload;\n}\n\nexport function verifyDocumentType(document: DocumentNode, type: DocumentType) {\n const operation = parser(document);\n const requiredOperationName = operationName(type);\n const usedOperationName = operationName(operation.type);\n invariant(\n operation.type === type,\n `Running a ${requiredOperationName} requires a graphql ` +\n `${requiredOperationName}, but a ${usedOperationName} was used instead.`\n );\n}\n\n"]}
@@ -34,16 +34,30 @@ function parser(document) {
34
34
  __DEV__ ? globals.invariant(!!document && !!document.kind, "Argument of ".concat(document, " passed to parser was not a valid GraphQL ") +
35
35
  "DocumentNode. You may need to use 'graphql-tag' or another method " +
36
36
  "to convert your operation into a document") : globals.invariant(!!document && !!document.kind, 30);
37
- var fragments = document.definitions.filter(function (x) { return x.kind === 'FragmentDefinition'; });
38
- var queries = document.definitions.filter(function (x) {
39
- return x.kind === 'OperationDefinition' && x.operation === 'query';
40
- });
41
- var mutations = document.definitions.filter(function (x) {
42
- return x.kind === 'OperationDefinition' && x.operation === 'mutation';
43
- });
44
- var subscriptions = document.definitions.filter(function (x) {
45
- return x.kind === 'OperationDefinition' && x.operation === 'subscription';
46
- });
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
+ }
47
61
  __DEV__ ? globals.invariant(!fragments.length ||
48
62
  (queries.length || mutations.length || subscriptions.length), "Passing only a fragment to 'graphql' is not yet supported. " +
49
63
  "You must include a query, subscription or mutation as well") : globals.invariant(!fragments.length ||
@@ -1 +1 @@
1
- {"version":3,"file":"parser.cjs","sources":["index.js"],"sourcesContent":["import { invariant } from '../../utilities/globals';\nexport var DocumentType;\n(function (DocumentType) {\n DocumentType[DocumentType[\"Query\"] = 0] = \"Query\";\n DocumentType[DocumentType[\"Mutation\"] = 1] = \"Mutation\";\n DocumentType[DocumentType[\"Subscription\"] = 2] = \"Subscription\";\n})(DocumentType || (DocumentType = {}));\nvar cache = new Map();\nexport function operationName(type) {\n var name;\n switch (type) {\n case DocumentType.Query:\n name = 'Query';\n break;\n case DocumentType.Mutation:\n name = 'Mutation';\n break;\n case DocumentType.Subscription:\n name = 'Subscription';\n break;\n }\n return name;\n}\nexport function parser(document) {\n var cached = cache.get(document);\n if (cached)\n return cached;\n var variables, type, name;\n __DEV__ ? invariant(!!document && !!document.kind, \"Argument of \".concat(document, \" passed to parser was not a valid GraphQL \") +\n \"DocumentNode. You may need to use 'graphql-tag' or another method \" +\n \"to convert your operation into a document\") : invariant(!!document && !!document.kind, 30);\n var fragments = document.definitions.filter(function (x) { return x.kind === 'FragmentDefinition'; });\n var queries = document.definitions.filter(function (x) {\n return x.kind === 'OperationDefinition' && x.operation === 'query';\n });\n var mutations = document.definitions.filter(function (x) {\n return x.kind === 'OperationDefinition' && x.operation === 'mutation';\n });\n var subscriptions = document.definitions.filter(function (x) {\n return x.kind === 'OperationDefinition' && x.operation === 'subscription';\n });\n __DEV__ ? invariant(!fragments.length ||\n (queries.length || mutations.length || subscriptions.length), \"Passing only a fragment to 'graphql' is not yet supported. \" +\n \"You must include a query, subscription or mutation as well\") : invariant(!fragments.length ||\n (queries.length || mutations.length || subscriptions.length), 31);\n __DEV__ ? invariant(queries.length + mutations.length + subscriptions.length <= 1, \"react-apollo only supports a query, subscription, or a mutation per HOC. \" +\n \"\".concat(document, \" had \").concat(queries.length, \" queries, \").concat(subscriptions.length, \" \") +\n \"subscriptions and \".concat(mutations.length, \" mutations. \") +\n \"You can use 'compose' to join multiple operation types to a component\") : invariant(queries.length + mutations.length + subscriptions.length <= 1, 32);\n type = queries.length ? DocumentType.Query : DocumentType.Mutation;\n if (!queries.length && !mutations.length)\n type = DocumentType.Subscription;\n var definitions = queries.length\n ? queries\n : mutations.length\n ? mutations\n : subscriptions;\n __DEV__ ? invariant(definitions.length === 1, \"react-apollo only supports one definition per HOC. \".concat(document, \" had \") +\n \"\".concat(definitions.length, \" definitions. \") +\n \"You can use 'compose' to join multiple operation types to a component\") : invariant(definitions.length === 1, 33);\n var definition = definitions[0];\n variables = definition.variableDefinitions || [];\n if (definition.name && definition.name.kind === 'Name') {\n name = definition.name.value;\n }\n else {\n name = 'data';\n }\n var payload = { name: name, type: type, variables: variables };\n cache.set(document, payload);\n return payload;\n}\nexport function verifyDocumentType(document, type) {\n var operation = parser(document);\n var requiredOperationName = operationName(type);\n var usedOperationName = operationName(operation.type);\n __DEV__ ? invariant(operation.type === type, \"Running a \".concat(requiredOperationName, \" requires a graphql \") +\n \"\".concat(requiredOperationName, \", but a \").concat(usedOperationName, \" was used instead.\")) : invariant(operation.type === type, 34);\n}\n//# sourceMappingURL=index.js.map"],"names":["DocumentType","invariant"],"mappings":";;;;;;AACWA,8BAAa;AACxB,CAAC,UAAU,YAAY,EAAE;AACzB,IAAI,YAAY,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC;AACtD,IAAI,YAAY,CAAC,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC;AAC5D,IAAI,YAAY,CAAC,YAAY,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,GAAG,cAAc,CAAC;AACpE,CAAC,EAAEA,oBAAY,KAAKA,oBAAY,GAAG,EAAE,CAAC,CAAC,CAAC;AACxC,IAAI,KAAK,GAAG,IAAI,GAAG,EAAE,CAAC;AACf,SAAS,aAAa,CAAC,IAAI,EAAE;AACpC,IAAI,IAAI,IAAI,CAAC;AACb,IAAI,QAAQ,IAAI;AAChB,QAAQ,KAAKA,oBAAY,CAAC,KAAK;AAC/B,YAAY,IAAI,GAAG,OAAO,CAAC;AAC3B,YAAY,MAAM;AAClB,QAAQ,KAAKA,oBAAY,CAAC,QAAQ;AAClC,YAAY,IAAI,GAAG,UAAU,CAAC;AAC9B,YAAY,MAAM;AAClB,QAAQ,KAAKA,oBAAY,CAAC,YAAY;AACtC,YAAY,IAAI,GAAG,cAAc,CAAC;AAClC,YAAY,MAAM;AAClB,KAAK;AACL,IAAI,OAAO,IAAI,CAAC;AAChB,CAAC;AACM,SAAS,MAAM,CAAC,QAAQ,EAAE;AACjC,IAAI,IAAI,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAA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AAC,MAAM,CAAC,qBAAqB,EAAE,UAAU,CAAC,CAAC,MAAM,CAAC,iBAAiB,EAAE,oBAAoB,CAAC,CAAC,GAAGA,iBAAS,CAAC,SAAS,CAAC,IAAI,KAAK,IAAI,EAAE,EAAE,CAAC,CAAC;AAC/I;;;;;;"}
1
+ {"version":3,"file":"parser.cjs","sources":["index.js"],"sourcesContent":["import { invariant } from '../../utilities/globals';\nexport var DocumentType;\n(function (DocumentType) {\n DocumentType[DocumentType[\"Query\"] = 0] = \"Query\";\n DocumentType[DocumentType[\"Mutation\"] = 1] = \"Mutation\";\n DocumentType[DocumentType[\"Subscription\"] = 2] = \"Subscription\";\n})(DocumentType || (DocumentType = {}));\nvar cache = new Map();\nexport function operationName(type) {\n var name;\n switch (type) {\n case DocumentType.Query:\n name = 'Query';\n break;\n case DocumentType.Mutation:\n name = 'Mutation';\n break;\n case DocumentType.Subscription:\n name = 'Subscription';\n break;\n }\n return name;\n}\nexport function parser(document) {\n var cached = cache.get(document);\n if (cached)\n return cached;\n var variables, type, name;\n __DEV__ ? invariant(!!document && !!document.kind, \"Argument of \".concat(document, \" passed to parser was not a valid GraphQL \") +\n \"DocumentNode. You may need to use 'graphql-tag' or another method \" +\n \"to convert your operation into a document\") : invariant(!!document && !!document.kind, 30);\n var fragments = [];\n var queries = [];\n var mutations = [];\n var subscriptions = [];\n for (var _i = 0, _a = document.definitions; _i < _a.length; _i++) {\n var x = _a[_i];\n if (x.kind === 'FragmentDefinition') {\n fragments.push(x);\n continue;\n }\n if (x.kind === 'OperationDefinition') {\n switch (x.operation) {\n case 'query':\n queries.push(x);\n break;\n case 'mutation':\n mutations.push(x);\n break;\n case 'subscription':\n subscriptions.push(x);\n break;\n }\n }\n }\n __DEV__ ? invariant(!fragments.length ||\n (queries.length || mutations.length || subscriptions.length), \"Passing only a fragment to 'graphql' is not yet supported. \" +\n \"You must include a query, subscription or mutation as well\") : invariant(!fragments.length ||\n (queries.length || mutations.length || subscriptions.length), 31);\n __DEV__ ? invariant(queries.length + mutations.length + subscriptions.length <= 1, \"react-apollo only supports a query, subscription, or a mutation per HOC. \" +\n \"\".concat(document, \" had \").concat(queries.length, \" queries, \").concat(subscriptions.length, \" \") +\n \"subscriptions and \".concat(mutations.length, \" mutations. \") +\n \"You can use 'compose' to join multiple operation types to a component\") : invariant(queries.length + mutations.length + subscriptions.length <= 1, 32);\n type = queries.length ? DocumentType.Query : DocumentType.Mutation;\n if (!queries.length && !mutations.length)\n type = DocumentType.Subscription;\n var definitions = queries.length\n ? queries\n : mutations.length\n ? mutations\n : subscriptions;\n __DEV__ ? invariant(definitions.length === 1, \"react-apollo only supports one definition per HOC. \".concat(document, \" had \") +\n \"\".concat(definitions.length, \" definitions. \") +\n \"You can use 'compose' to join multiple operation types to a component\") : invariant(definitions.length === 1, 33);\n var definition = definitions[0];\n variables = definition.variableDefinitions || [];\n if (definition.name && definition.name.kind === 'Name') {\n name = definition.name.value;\n }\n else {\n name = 'data';\n }\n var payload = { name: name, type: type, variables: variables };\n cache.set(document, payload);\n return payload;\n}\nexport function verifyDocumentType(document, type) {\n var operation = parser(document);\n var requiredOperationName = operationName(type);\n var usedOperationName = operationName(operation.type);\n __DEV__ ? invariant(operation.type === type, \"Running a \".concat(requiredOperationName, \" requires a graphql \") +\n \"\".concat(requiredOperationName, \", but a \").concat(usedOperationName, \" was used instead.\")) : invariant(operation.type === type, 34);\n}\n//# sourceMappingURL=index.js.map"],"names":["DocumentType","invariant"],"mappings":";;;;;;AACWA,8BAAa;AACxB,CAAC,UAAU,YAAY,EAAE;AACzB,IAAI,YAAY,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC;AACtD,IAAI,YAAY,CAAC,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC;AAC5D,IAAI,YAAY,CAAC,YAAY,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,GAAG,cAAc,CAAC;AACpE,CAAC,EAAE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IAAI,UAAU,CAAC,IAAI,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE;AAC5D,QAAQ,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC;AACrC,KAAK;AACL,SAAS;AACT,QAAQ,IAAI,GAAG,MAAM,CAAC;AACtB,KAAK;AACL,IAAI,IAAI,OAAO,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC;AACnE,IAAI,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AACjC,IAAI,OAAO,OAAO,CAAC;AACnB,CAAC;AACM,SAAS,kBAAkB,CAAC,QAAQ,EAAE,IAAI,EAAE;AACnD,IAAI,IAAI,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;AACrC,IAAI,IAAI,qBAAqB,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;AACpD,IAAI,IAAI,iBAAiB,GAAG,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AAC1D,IAAI,OAAO,GAAGA,iBAAS,CAAC,SAAS,CAAC,IAAI,KAAK,IAAI,EAAE,YAAY,CAAC,MAAM,CAAC,qBAAqB,EAAE,sBAAsB,CAAC;AACnH,QAAQ,EAAE,CAAC,MAAM,CAAC,qBAAqB,EAAE,UAAU,CAAC,CAAC,MAAM,CAAC,iBAAiB,EAAE,oBAAoB,CAAC,CAAC,GAAGA,iBAAS,CAAC,SAAS,CAAC,IAAI,KAAK,IAAI,EAAE,EAAE,CAAC,CAAC;AAC/I;;;;;;"}
@@ -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
@@ -10,9 +10,10 @@ export declare class RenderPromises {
10
10
  private queryInfoTrie;
11
11
  private stopped;
12
12
  stop(): void;
13
- registerSSRObservable<TData, TVariables>(observable: ObservableQuery<any, TVariables>, props: QueryDataOptions<TData, TVariables>): void;
13
+ registerSSRObservable<TData, TVariables>(observable: ObservableQuery<any, TVariables>): void;
14
14
  getSSRObservable<TData, TVariables>(props: QueryDataOptions<TData, TVariables>): ObservableQuery<any, TVariables> | null;
15
- addQueryPromise(queryInstance: QueryData, finish: () => React.ReactNode): React.ReactNode;
15
+ addQueryPromise(queryInstance: QueryData, finish?: () => React.ReactNode): React.ReactNode;
16
+ addObservableQueryPromise<TData, TVariables>(obsQuery: ObservableQuery<TData, TVariables>): import("react").ReactNode;
16
17
  hasPromises(): boolean;
17
18
  consumeAndAwaitPromises(): Promise<any[]>;
18
19
  private lookupQueryInfo;
@@ -1 +1 @@
1
- {"version":3,"file":"RenderPromises.d.ts","sourceRoot":"","sources":["../../../src/react/ssr/RenderPromises.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAIlD,UAAU,SAAS;IACjB,UAAU,IAAI,GAAG,CAAC;IAClB,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B;AAcD,qBAAa,cAAc;IAEzB,OAAO,CAAC,aAAa,CAAuD;IAM5E,OAAO,CAAC,aAAa,CAAmD;IAExE,OAAO,CAAC,OAAO,CAAS;IACjB,IAAI;IASJ,qBAAqB,CAAC,KAAK,EAAE,UAAU,EAC5C,UAAU,EAAE,eAAe,CAAC,GAAG,EAAE,UAAU,CAAC,E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AAU,CAAC;IA0BvC,WAAW;IAIX,uBAAuB;IAmB9B,OAAO,CAAC,eAAe;CAYxB"}
@@ -17,10 +17,10 @@ var RenderPromises = (function () {
17
17
  this.stopped = true;
18
18
  }
19
19
  };
20
- RenderPromises.prototype.registerSSRObservable = function (observable, props) {
20
+ RenderPromises.prototype.registerSSRObservable = function (observable) {
21
21
  if (this.stopped)
22
22
  return;
23
- this.lookupQueryInfo(props).observable = observable;
23
+ this.lookupQueryInfo(observable.options).observable = observable;
24
24
  };
25
25
  RenderPromises.prototype.getSSRObservable = function (props) {
26
26
  return this.lookupQueryInfo(props).observable;
@@ -35,7 +35,29 @@ var RenderPromises = (function () {
35
35
  return null;
36
36
  }
37
37
  }
38
- return finish();
38
+ return finish ? finish() : null;
39
+ };
40
+ RenderPromises.prototype.addObservableQueryPromise = function (obsQuery) {
41
+ return this.addQueryPromise({
42
+ getOptions: function () { return obsQuery.options; },
43
+ fetchData: function () { return new Promise(function (resolve) {
44
+ var sub = obsQuery.subscribe({
45
+ next: function (result) {
46
+ if (!result.loading) {
47
+ resolve();
48
+ sub.unsubscribe();
49
+ }
50
+ },
51
+ error: function () {
52
+ resolve();
53
+ sub.unsubscribe();
54
+ },
55
+ complete: function () {
56
+ resolve();
57
+ },
58
+ });
59
+ }); },
60
+ });
39
61
  };
40
62
  RenderPromises.prototype.hasPromises = function () {
41
63
  return this.queryPromises.size > 0;
@@ -1 +1 @@
1
- {"version":3,"file":"RenderPromises.js","sourceRoot":"","sources":["../../../src/react/ssr/RenderPromises.ts"],"names":[],"mappings":"AAiBA,SAAS,oBAAoB;IAC3B,OAAO;QACL,IAAI,EAAE,KAAK;QACX,UAAU,EAAE,IAAI;KACjB,CAAC;AACJ,CAAC;AAED;IAAA;QAEU,kBAAa,GAAG,IAAI,GAAG,EAA4C,CAAC;QAMpE,kBAAa,GAAG,IAAI,GAAG,EAAwC,CAAC;QAEhE,YAAO,GAAG,KAAK,CAAC;IAiF1B,CAAC;IAhFQ,6BAAI,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,CAAC,aAAa,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC;YAChD,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACzB,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;QAC3B,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC/B,CAAC;IAEO,wCAAe,GAAvB,UACE,KAA0C;QAElC,IAAA,aAAa,GAAK,IAAI,cAAT,CAAU;QACvB,IAAA,KAAK,GAAgB,KAAK,MAArB,EAAE,SAAS,GAAK,KAAK,UAAV,CAAW;QACnC,IAAM,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,IAAI,GAAG,EAAqB,CAAC;QACxE,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC;YAAE,aAAa,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAChE,IAAM,eAAe,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAClD,IAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,oBAAoB,EAAE,CAAC;QACnE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC;YAAE,MAAM,CAAC,GAAG,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC;QACpE,OAAO,IAAI,CAAC;IACd,CAAC;IACH,qBAAC;AAAD,CAAC,AA3FD,IA2FC","sourcesContent":["import { DocumentNode } from 'graphql';\n\nimport { ObservableQuery } from '../../core';\nimport { QueryDataOptions } from '../types/types';\n\n// TODO: A vestigial interface from when hooks were implemented with utility\n// classes, which should be deleted in the future.\ninterface QueryData {\n getOptions(): any;\n fetchData(): Promise<void>;\n}\n\ntype QueryInfo = {\n seen: boolean;\n observable: ObservableQuery<any, any> | null;\n};\n\nfunction makeDefaultQueryInfo(): QueryInfo {\n return {\n seen: false,\n observable: null\n };\n}\n\nexport class RenderPromises {\n // Map from Query component instances to pending fetchData promises.\n private queryPromises = new Map<QueryDataOptions<any, any>, Promise<any>>();\n\n // Two-layered map from (query document, stringified variables) to QueryInfo\n // objects. These QueryInfo objects are intended to survive through the whole\n // getMarkupFromTree process, whereas specific Query instances do not survive\n // beyond a single call to renderToStaticMarkup.\n private queryInfoTrie = new Map<DocumentNode, Map<string, QueryInfo>>();\n\n private stopped = false;\n public stop() {\n if (!this.stopped) {\n this.queryPromises.clear();\n this.queryInfoTrie.clear();\n this.stopped = true;\n }\n }\n\n // Registers the server side rendered observable.\n public registerSSRObservable<TData, TVariables>(\n observable: ObservableQuery<any, TVariables>,\n props: QueryDataOptions<TData, TVariables>\n ) {\n if (this.stopped) return;\n this.lookupQueryInfo(props).observable = observable;\n }\n\n // Get's the cached observable that matches the SSR Query instances query and variables.\n public getSSRObservable<TData, TVariables>(\n props: QueryDataOptions<TData, TVariables>\n ): ObservableQuery<any, TVariables> | null {\n return this.lookupQueryInfo(props).observable;\n }\n\n public addQueryPromise(\n queryInstance: QueryData,\n finish: () => React.ReactNode\n ): React.ReactNode {\n if (!this.stopped) {\n const info = this.lookupQueryInfo(queryInstance.getOptions());\n if (!info.seen) {\n this.queryPromises.set(\n queryInstance.getOptions(),\n new Promise(resolve => {\n resolve(queryInstance.fetchData());\n })\n );\n // Render null to abandon this subtree for this rendering, so that we\n // can wait for the data to arrive.\n return null;\n }\n }\n return finish();\n }\n\n public hasPromises() {\n return this.queryPromises.size > 0;\n }\n\n public consumeAndAwaitPromises() {\n const promises: Promise<any>[] = [];\n this.queryPromises.forEach((promise, queryInstance) => {\n // Make sure we never try to call fetchData for this query document and\n // these variables again. Since the queryInstance objects change with\n // every rendering, deduplicating them by query and variables is the\n // best we can do. If a different Query component happens to have the\n // same query document and variables, it will be immediately rendered\n // by calling finish() in addQueryPromise, which could result in the\n // rendering of an unwanted loading state, but that's not nearly as bad\n // as getting stuck in an infinite rendering loop because we kept calling\n // queryInstance.fetchData for the same Query component indefinitely.\n this.lookupQueryInfo(queryInstance).seen = true;\n promises.push(promise);\n });\n this.queryPromises.clear();\n return Promise.all(promises);\n }\n\n private lookupQueryInfo<TData, TVariables>(\n props: QueryDataOptions<TData, TVariables>\n ): QueryInfo {\n const { queryInfoTrie } = this;\n const { query, variables } = props;\n const varMap = queryInfoTrie.get(query) || new Map<string, QueryInfo>();\n if (!queryInfoTrie.has(query)) queryInfoTrie.set(query, varMap);\n const variablesString = JSON.stringify(variables);\n const info = varMap.get(variablesString) || makeDefaultQueryInfo();\n if (!varMap.has(variablesString)) varMap.set(variablesString, info);\n return info;\n }\n}\n"]}
1
+ {"version":3,"file":"RenderPromises.js","sourceRoot":"","sources":["../../../src/react/ssr/RenderPromises.ts"],"names":[],"mappings":"AAiBA,SAAS,oBAAoB;IAC3B,OAAO;QACL,IAAI,EAAE,KAAK;QACX,UAAU,EAAE,IAAI;KACjB,CAAC;AACJ,CAAC;AAED;IAAA;QAEU,kBAAa,GAAG,IAAI,GAAG,EAA4C,CAAC;QAMpE,kBAAa,GAAG,IAAI,GAAG,EAAwC,CAAC;QAEhE,YAAO,GAAG,KAAK,CAAC;IA2G1B,CAAC;IA1GQ,6BAAI,GAAX;QACE,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;YACjB,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;YAC3B,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;YAC3B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;SACrB;IACH,CAAC;IAGM,8CAAqB,GAA5B,UACE,UAA4C;QAE5C,IAAI,IAAI,CAAC,OAAO;YAAE,OAAO;QACzB,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,UAAU,GAAG,UAAU,CAAC;IACnE,CAAC;IAGM,yCAAgB,GAAvB,UACE,KAA0C;QAE1C,OAAO,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,UAAU,CAAC;IAChD,CAAC;IA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,gDAAuB,GAA9B;QAAA,iBAiBC;QAhBC,IAAM,QAAQ,GAAmB,EAAE,CAAC;QACpC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,UAAC,OAAO,EAAE,aAAa;YAUhD,KAAI,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC;YAChD,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACzB,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;QAC3B,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC/B,CAAC;IAEO,wCAAe,GAAvB,UACE,KAA0C;QAElC,IAAA,aAAa,GAAK,IAAI,cAAT,CAAU;QACvB,IAAA,KAAK,GAAgB,KAAK,MAArB,EAAE,SAAS,GAAK,KAAK,UAAV,CAAW;QACnC,IAAM,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,IAAI,GAAG,EAAqB,CAAC;QACxE,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC;YAAE,aAAa,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAChE,IAAM,eAAe,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAClD,IAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,oBAAoB,EAAE,CAAC;QACnE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC;YAAE,MAAM,CAAC,GAAG,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC;QACpE,OAAO,IAAI,CAAC;IACd,CAAC;IACH,qBAAC;AAAD,CAAC,AArHD,IAqHC","sourcesContent":["import { DocumentNode } from 'graphql';\n\nimport { ObservableQuery } from '../../core';\nimport { QueryDataOptions } from '../types/types';\n\n// TODO: A vestigial interface from when hooks were implemented with utility\n// classes, which should be deleted in the future.\ninterface QueryData {\n getOptions(): any;\n fetchData(): Promise<void>;\n}\n\ntype QueryInfo = {\n seen: boolean;\n observable: ObservableQuery<any, any> | null;\n};\n\nfunction makeDefaultQueryInfo(): QueryInfo {\n return {\n seen: false,\n observable: null\n };\n}\n\nexport class RenderPromises {\n // Map from Query component instances to pending fetchData promises.\n private queryPromises = new Map<QueryDataOptions<any, any>, Promise<any>>();\n\n // Two-layered map from (query document, stringified variables) to QueryInfo\n // objects. These QueryInfo objects are intended to survive through the whole\n // getMarkupFromTree process, whereas specific Query instances do not survive\n // beyond a single call to renderToStaticMarkup.\n private queryInfoTrie = new Map<DocumentNode, Map<string, QueryInfo>>();\n\n private stopped = false;\n public stop() {\n if (!this.stopped) {\n this.queryPromises.clear();\n this.queryInfoTrie.clear();\n this.stopped = true;\n }\n }\n\n // Registers the server side rendered observable.\n public registerSSRObservable<TData, TVariables>(\n observable: ObservableQuery<any, TVariables>,\n ) {\n if (this.stopped) return;\n this.lookupQueryInfo(observable.options).observable = observable;\n }\n\n // Get's the cached observable that matches the SSR Query instances query and variables.\n public getSSRObservable<TData, TVariables>(\n props: QueryDataOptions<TData, TVariables>\n ): ObservableQuery<any, TVariables> | null {\n return this.lookupQueryInfo(props).observable;\n }\n\n public addQueryPromise(\n queryInstance: QueryData,\n finish?: () => React.ReactNode,\n ): React.ReactNode {\n if (!this.stopped) {\n const info = this.lookupQueryInfo(queryInstance.getOptions());\n if (!info.seen) {\n this.queryPromises.set(\n queryInstance.getOptions(),\n new Promise(resolve => {\n resolve(queryInstance.fetchData());\n })\n );\n // Render null to abandon this subtree for this rendering, so that we\n // can wait for the data to arrive.\n return null;\n }\n }\n return finish ? finish() : null;\n }\n\n public addObservableQueryPromise<TData, TVariables>(\n obsQuery: ObservableQuery<TData, TVariables>,\n ) {\n return this.addQueryPromise({\n // The only options which seem to actually be used by the\n // RenderPromises class are query and variables.\n getOptions: () => obsQuery.options,\n fetchData: () => new Promise<void>((resolve) => {\n const sub = obsQuery.subscribe({\n next(result) {\n if (!result.loading) {\n resolve()\n sub.unsubscribe();\n }\n },\n error() {\n resolve();\n sub.unsubscribe();\n },\n complete() {\n resolve();\n },\n });\n }),\n });\n }\n\n public hasPromises() {\n return this.queryPromises.size > 0;\n }\n\n public consumeAndAwaitPromises() {\n const promises: Promise<any>[] = [];\n this.queryPromises.forEach((promise, queryInstance) => {\n // Make sure we never try to call fetchData for this query document and\n // these variables again. Since the queryInstance objects change with\n // every rendering, deduplicating them by query and variables is the\n // best we can do. If a different Query component happens to have the\n // same query document and variables, it will be immediately rendered\n // by calling finish() in addQueryPromise, which could result in the\n // rendering of an unwanted loading state, but that's not nearly as bad\n // as getting stuck in an infinite rendering loop because we kept calling\n // queryInstance.fetchData for the same Query component indefinitely.\n this.lookupQueryInfo(queryInstance).seen = true;\n promises.push(promise);\n });\n this.queryPromises.clear();\n return Promise.all(promises);\n }\n\n private lookupQueryInfo<TData, TVariables>(\n props: QueryDataOptions<TData, TVariables>\n ): QueryInfo {\n const { queryInfoTrie } = this;\n const { query, variables } = props;\n const varMap = queryInfoTrie.get(query) || new Map<string, QueryInfo>();\n if (!queryInfoTrie.has(query)) queryInfoTrie.set(query, varMap);\n const variablesString = JSON.stringify(variables);\n const info = varMap.get(variablesString) || makeDefaultQueryInfo();\n if (!varMap.has(variablesString)) varMap.set(variablesString, info);\n return info;\n }\n}\n"]}