@octanejs/apollo-client 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +49 -0
- package/README.md +97 -0
- package/package.json +77 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +3 -0
- package/src/react/context/ApolloContext.d.ts +8 -0
- package/src/react/context/ApolloContext.js +21 -0
- package/src/react/context/ApolloProvider.d.ts +9 -0
- package/src/react/context/ApolloProvider.js +15 -0
- package/src/react/hooks/constants.d.ts +2 -0
- package/src/react/hooks/constants.js +1 -0
- package/src/react/hooks/internal/__use.d.ts +3 -0
- package/src/react/hooks/internal/__use.js +9 -0
- package/src/react/hooks/internal/index.d.ts +5 -0
- package/src/react/hooks/internal/index.js +6 -0
- package/src/react/hooks/internal/site.d.ts +2 -0
- package/src/react/hooks/internal/site.js +20 -0
- package/src/react/hooks/internal/useDeepMemo.d.ts +5 -0
- package/src/react/hooks/internal/useDeepMemo.js +11 -0
- package/src/react/hooks/internal/useIsomorphicLayoutEffect.d.ts +2 -0
- package/src/react/hooks/internal/useIsomorphicLayoutEffect.js +8 -0
- package/src/react/hooks/internal/useRenderGuard.d.ts +1 -0
- package/src/react/hooks/internal/useRenderGuard.js +14 -0
- package/src/react/hooks/internal/useSuspenseHookCacheKey.d.ts +13 -0
- package/src/react/hooks/internal/useSuspenseHookCacheKey.js +19 -0
- package/src/react/hooks/internal/validateSuspenseHookOptions.d.ts +4 -0
- package/src/react/hooks/internal/validateSuspenseHookOptions.js +16 -0
- package/src/react/hooks/internal/wrapHook.d.ts +77 -0
- package/src/react/hooks/internal/wrapHook.js +64 -0
- package/src/react/hooks/useApolloClient.d.ts +17 -0
- package/src/react/hooks/useApolloClient.js +27 -0
- package/src/react/hooks/useBackgroundQuery.d.ts +3061 -0
- package/src/react/hooks/useBackgroundQuery.js +88 -0
- package/src/react/hooks/useFragment.d.ts +205 -0
- package/src/react/hooks/useFragment.js +75 -0
- package/src/react/hooks/useLazyQuery.d.ts +947 -0
- package/src/react/hooks/useLazyQuery.js +156 -0
- package/src/react/hooks/useLoadableQuery.d.ts +955 -0
- package/src/react/hooks/useLoadableQuery.js +98 -0
- package/src/react/hooks/useMutation.d.ts +585 -0
- package/src/react/hooks/useMutation.js +121 -0
- package/src/react/hooks/useQuery.d.ts +1401 -0
- package/src/react/hooks/useQuery.js +234 -0
- package/src/react/hooks/useQueryRefHandlers.d.ts +85 -0
- package/src/react/hooks/useQueryRefHandlers.js +79 -0
- package/src/react/hooks/useReactiveVar.d.ts +21 -0
- package/src/react/hooks/useReactiveVar.js +41 -0
- package/src/react/hooks/useReadQuery.d.ts +104 -0
- package/src/react/hooks/useReadQuery.js +83 -0
- package/src/react/hooks/useSubscription.d.ts +289 -0
- package/src/react/hooks/useSubscription.js +258 -0
- package/src/react/hooks/useSuspenseFragment.d.ts +154 -0
- package/src/react/hooks/useSuspenseFragment.js +50 -0
- package/src/react/hooks/useSuspenseQuery.d.ts +1629 -0
- package/src/react/hooks/useSuspenseQuery.js +130 -0
- package/src/react/hooks/useSyncExternalStore.d.ts +2 -0
- package/src/react/hooks/useSyncExternalStore.js +125 -0
- package/src/react/index.d.ts +68 -0
- package/src/react/index.js +18 -0
- package/src/react/internal/cache/FragmentReference.d.ts +41 -0
- package/src/react/internal/cache/FragmentReference.js +117 -0
- package/src/react/internal/cache/QueryReference.d.ts +180 -0
- package/src/react/internal/cache/QueryReference.js +310 -0
- package/src/react/internal/cache/SuspenseCache.d.ts +38 -0
- package/src/react/internal/cache/SuspenseCache.js +39 -0
- package/src/react/internal/cache/getSuspenseCache.d.ts +26 -0
- package/src/react/internal/cache/getSuspenseCache.js +8 -0
- package/src/react/internal/cache/types.d.ts +13 -0
- package/src/react/internal/cache/types.js +1 -0
- package/src/react/internal/index.d.ts +16 -0
- package/src/react/internal/index.js +10 -0
- package/src/react/internal/types.d.ts +15 -0
- package/src/react/internal/types.js +1 -0
- package/src/react/query-preloader/createQueryPreloader.d.ts +630 -0
- package/src/react/query-preloader/createQueryPreloader.js +89 -0
- package/src/react/types/deprecated.d.ts +140 -0
- package/src/react/types/deprecated.js +1 -0
- package/src/react/types/types.documentation.d.ts +551 -0
- package/src/react/types/types.documentation.js +1 -0
- package/src/testing/index.d.ts +1 -0
- package/src/testing/index.js +1 -0
- package/src/testing/react/MockedProvider.d.ts +21 -0
- package/src/testing/react/MockedProvider.js +53 -0
- package/src/testing/react/index.d.ts +2 -0
- package/src/testing/react/index.js +1 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as React from 'octane';
|
|
2
|
+
import { canonicalStringify } from '@apollo/client/cache';
|
|
3
|
+
import { getSuspenseCache } from '@octanejs/apollo-client/react/internal';
|
|
4
|
+
import { __use } from './internal/__use.js';
|
|
5
|
+
import { useDeepMemo, wrapHook } from './internal/index.js';
|
|
6
|
+
import { useApolloClient } from './useApolloClient.js';
|
|
7
|
+
export function useSuspenseFragment(options, site) {
|
|
8
|
+
'use no memo';
|
|
9
|
+
return wrapHook(
|
|
10
|
+
'useSuspenseFragment',
|
|
11
|
+
useSuspenseFragment_,
|
|
12
|
+
useApolloClient(typeof options === 'object' ? options.client : undefined),
|
|
13
|
+
)(options, site);
|
|
14
|
+
}
|
|
15
|
+
function useSuspenseFragment_(options, site) {
|
|
16
|
+
const client = useApolloClient(options.client);
|
|
17
|
+
const { from, variables } = options;
|
|
18
|
+
const { cache } = client;
|
|
19
|
+
const ids = useDeepMemo(() => {
|
|
20
|
+
return Array.isArray(from) ? from.map((id) => toStringId(cache, id)) : toStringId(cache, from);
|
|
21
|
+
}, [cache, from]);
|
|
22
|
+
const idString = React.useMemo(() => (Array.isArray(ids) ? ids.join(',') : ids), [ids]);
|
|
23
|
+
const fragmentRef = getSuspenseCache(client).getFragmentRef(
|
|
24
|
+
[options.fragment, canonicalStringify(variables), idString],
|
|
25
|
+
client,
|
|
26
|
+
{ ...options, variables: variables, from: ids },
|
|
27
|
+
);
|
|
28
|
+
let [current, setPromise] = React.useState([fragmentRef.key, fragmentRef.promise]);
|
|
29
|
+
React.useEffect(() => {
|
|
30
|
+
const dispose = fragmentRef.retain();
|
|
31
|
+
const removeListener = fragmentRef.listen((promise) => {
|
|
32
|
+
setPromise([fragmentRef.key, promise]);
|
|
33
|
+
});
|
|
34
|
+
return () => {
|
|
35
|
+
dispose();
|
|
36
|
+
removeListener();
|
|
37
|
+
};
|
|
38
|
+
}, [fragmentRef]);
|
|
39
|
+
if (current[0] !== fragmentRef.key) {
|
|
40
|
+
// eslint-disable-next-line react-hooks/immutability
|
|
41
|
+
current[0] = fragmentRef.key;
|
|
42
|
+
// eslint-disable-next-line react-hooks/immutability
|
|
43
|
+
current[1] = fragmentRef.promise;
|
|
44
|
+
}
|
|
45
|
+
const data = __use(current[1], site);
|
|
46
|
+
return { data };
|
|
47
|
+
}
|
|
48
|
+
function toStringId(cache, from) {
|
|
49
|
+
return typeof from === 'string' ? from : from === null ? null : cache.identify(from);
|
|
50
|
+
}
|