@lewebsimple/nuxt-graphql 0.7.11 → 0.7.12
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/dist/module.json +1 -1
- package/dist/module.mjs +1 -1
- package/dist/runtime/app/composables/useGraphQLLoadMore.d.ts +5 -5
- package/dist/runtime/app/composables/useGraphQLLoadMore.js +22 -13
- package/dist/runtime/app/composables/useGraphQLMutation.d.ts +2 -2
- package/dist/runtime/app/plugins/graphql-sse.client.d.ts +5 -1
- package/dist/runtime/app/plugins/graphql.d.ts +5 -1
- package/package.json +1 -1
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -16,7 +16,7 @@ import zodPreset from '@lewebsimple/graphql-codegen-zod';
|
|
|
16
16
|
import { createRequire } from 'node:module';
|
|
17
17
|
import { resolveCacheConfig } from '../dist/runtime/app/lib/cache-config.js';
|
|
18
18
|
|
|
19
|
-
const version = "0.7.
|
|
19
|
+
const version = "0.7.12";
|
|
20
20
|
|
|
21
21
|
const buildCache = /* @__PURE__ */ new Map();
|
|
22
22
|
function getCachedLoader(baseKey, loader) {
|
|
@@ -16,11 +16,11 @@ type Connection<TItem> = {
|
|
|
16
16
|
* @returns An object containing the items, loading state, error state, and pagination functions.
|
|
17
17
|
*/
|
|
18
18
|
export declare function useGraphQLLoadMore<TName extends QueryName, TConnection extends Connection<unknown>>(operationName: TName, variables: MaybeRefOrGetter<Omit<VariablesOf<TName>, "after">>, getConnection: (data?: ResultOf<TName>) => TConnection | null | undefined): Promise<{
|
|
19
|
-
items:
|
|
20
|
-
pending:
|
|
21
|
-
error:
|
|
22
|
-
hasNextPage:
|
|
23
|
-
isLoadingMore:
|
|
19
|
+
items: import("vue").ShallowRef<TConnection["nodes"][number][], TConnection["nodes"][number][]>;
|
|
20
|
+
pending: import("vue").Ref<boolean, boolean>;
|
|
21
|
+
error: import("vue").Ref<import("../../shared/utils/error.js").NormalizedError | undefined, import("../../shared/utils/error.js").NormalizedError | undefined>;
|
|
22
|
+
hasNextPage: import("vue").ComputedRef<boolean>;
|
|
23
|
+
isLoadingMore: import("vue").Ref<boolean, boolean>;
|
|
24
24
|
loadMore: () => void;
|
|
25
25
|
reset: () => void;
|
|
26
26
|
}>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { hash } from "ohash";
|
|
2
|
-
import { computed, ref, shallowRef, toValue,
|
|
2
|
+
import { computed, ref, shallowRef, toValue, watch } from "vue";
|
|
3
3
|
import { useAsyncGraphQLQuery } from "./useAsyncGraphQLQuery.js";
|
|
4
4
|
export async function useGraphQLLoadMore(operationName, variables, getConnection) {
|
|
5
5
|
const after = ref(null);
|
|
@@ -16,20 +16,29 @@ export async function useGraphQLLoadMore(operationName, variables, getConnection
|
|
|
16
16
|
const connection = computed(() => getConnection(query.data.value));
|
|
17
17
|
const hasNextPage = computed(() => connection.value?.pageInfo?.hasNextPage ?? false);
|
|
18
18
|
const endCursor = computed(() => connection.value?.pageInfo?.endCursor ?? null);
|
|
19
|
+
items.value = connection.value?.nodes ?? [];
|
|
19
20
|
let lastInputHash = baseVariablesHash.value;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (after.value === null) {
|
|
27
|
-
items.value = newItems;
|
|
28
|
-
} else if (isLoadingMore.value) {
|
|
29
|
-
items.value = [...items.value, ...newItems];
|
|
30
|
-
}
|
|
31
|
-
isLoadingMore.value = false;
|
|
21
|
+
watch(baseVariablesHash, (newHash) => {
|
|
22
|
+
if (newHash === lastInputHash) return;
|
|
23
|
+
lastInputHash = newHash;
|
|
24
|
+
after.value = null;
|
|
25
|
+
lastRequestedCursor.value = null;
|
|
26
|
+
items.value = [];
|
|
32
27
|
});
|
|
28
|
+
watch(
|
|
29
|
+
() => query.pending.value,
|
|
30
|
+
(pending, wasPending) => {
|
|
31
|
+
if (pending || !wasPending) return;
|
|
32
|
+
const newItems = connection.value?.nodes ?? [];
|
|
33
|
+
if (after.value === null) {
|
|
34
|
+
items.value = newItems;
|
|
35
|
+
} else if (isLoadingMore.value) {
|
|
36
|
+
items.value = [...items.value, ...newItems];
|
|
37
|
+
}
|
|
38
|
+
isLoadingMore.value = false;
|
|
39
|
+
},
|
|
40
|
+
{ flush: "post" }
|
|
41
|
+
);
|
|
33
42
|
function loadMore() {
|
|
34
43
|
const cursor = endCursor.value;
|
|
35
44
|
if (isLoadingMore.value || !hasNextPage.value || !cursor || cursor === lastRequestedCursor.value) {
|
|
@@ -50,6 +50,6 @@ export type MutationHooks<TName extends MutationName, TContext = unknown> = {
|
|
|
50
50
|
* @returns Mutation executor and pending state.
|
|
51
51
|
*/
|
|
52
52
|
export declare function useGraphQLMutation<TName extends MutationName, TContext = unknown>(operationName: TName, hooks?: MutationHooks<TName, TContext>): {
|
|
53
|
-
pending:
|
|
54
|
-
mutate: (variables: VariablesInputOf<TName>) => Promise<
|
|
53
|
+
pending: import("vue").ComputedRef<boolean>;
|
|
54
|
+
mutate: (variables: VariablesInputOf<TName>) => Promise<ExecuteGraphQLResult<TName>>;
|
|
55
55
|
};
|
|
@@ -4,7 +4,11 @@ import { type Client as SSEClient } from "graphql-sse";
|
|
|
4
4
|
*
|
|
5
5
|
* @returns Nuxt plugin with SSE client provider.
|
|
6
6
|
*/
|
|
7
|
-
declare const _default:
|
|
7
|
+
declare const _default: import("#app").Plugin<{
|
|
8
|
+
getGraphQLSSEClient: () => SSEClient;
|
|
9
|
+
}> & import("#app").ObjectPlugin<{
|
|
10
|
+
getGraphQLSSEClient: () => SSEClient;
|
|
11
|
+
}>;
|
|
8
12
|
export default _default;
|
|
9
13
|
declare module "#app/nuxt" {
|
|
10
14
|
interface NuxtApp {
|
|
@@ -5,7 +5,11 @@ import type { OperationName } from "../../shared/utils/registry.js";
|
|
|
5
5
|
*
|
|
6
6
|
* @returns Nuxt plugin with GraphQL operation executor.
|
|
7
7
|
*/
|
|
8
|
-
declare const _default:
|
|
8
|
+
declare const _default: import("#app").Plugin<{
|
|
9
|
+
executeOperation: <TName extends OperationName>(input: ExecuteGraphQLInput<TName>) => Promise<ExecuteGraphQLResult<TName>>;
|
|
10
|
+
}> & import("#app").ObjectPlugin<{
|
|
11
|
+
executeOperation: <TName extends OperationName>(input: ExecuteGraphQLInput<TName>) => Promise<ExecuteGraphQLResult<TName>>;
|
|
12
|
+
}>;
|
|
9
13
|
export default _default;
|
|
10
14
|
type ExecuteGraphQL = <TName extends OperationName>(input: ExecuteGraphQLInput<TName>) => Promise<ExecuteGraphQLResult<TName>>;
|
|
11
15
|
declare module "#app/nuxt" {
|