@lewebsimple/nuxt-graphql 0.6.8 → 0.6.10

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lewebsimple/nuxt-graphql",
3
3
  "configKey": "graphql",
4
- "version": "0.6.8",
4
+ "version": "0.6.10",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -203,7 +203,7 @@ function addUniversalTemplate({ filename, getContents, emitTs }) {
203
203
  return modulePath;
204
204
  }
205
205
 
206
- const version = "0.6.8";
206
+ const version = "0.6.10";
207
207
 
208
208
  async function getDocuments(documentsGlob) {
209
209
  try {
@@ -231,7 +231,12 @@ async function getOperationsTemplate({ loadSchema, loadDocuments, documentGlob }
231
231
  plugins: [
232
232
  {
233
233
  typescript: {
234
- avoidOptionals: true,
234
+ avoidOptionals: {
235
+ field: true,
236
+ object: true,
237
+ inputValue: false,
238
+ defaultValue: false
239
+ },
235
240
  defaultScalarType: "never",
236
241
  enumsAsTypes: true,
237
242
  maybeValue: "T | undefined",
@@ -242,7 +247,12 @@ async function getOperationsTemplate({ loadSchema, loadDocuments, documentGlob }
242
247
  },
243
248
  {
244
249
  typescriptOperations: {
245
- avoidOptionals: true,
250
+ avoidOptionals: {
251
+ field: true,
252
+ object: true,
253
+ inputValue: false,
254
+ defaultValue: false
255
+ },
246
256
  defaultScalarType: "never",
247
257
  enumsAsTypes: true,
248
258
  exportFragmentSpreadSubTypes: true,
@@ -5,7 +5,7 @@ import type { QueryName } from "#graphql/registry";
5
5
  * @returns Cache config and invalidation helper.
6
6
  */
7
7
  export declare function useGraphQLCache(): {
8
- readonly cacheConfig: import("../../shared/lib/types.js").CacheConfig;
8
+ readonly cacheConfig: any;
9
9
  readonly invalidate: (options?: {
10
10
  operation: QueryName;
11
11
  variables?: unknown;
@@ -0,0 +1,20 @@
1
+ import type { QueryName, ResultOf, VariablesOf } from "#graphql/registry";
2
+ import { type ComputedRef, type MaybeRef, type Ref } from "#imports";
3
+ type PageInfoFragment = {
4
+ hasNextPage: boolean;
5
+ endCursor: string | undefined;
6
+ };
7
+ type Connection<TItem> = {
8
+ nodes: TItem[];
9
+ pageInfo: PageInfoFragment;
10
+ };
11
+ export declare function useGraphQLLoadMore<TQueryName extends QueryName, TConnection extends Connection<unknown>>(queryName: TQueryName, inputVars: MaybeRef<Omit<VariablesOf<TQueryName>, "after">>, getConnection: (data?: ResultOf<TQueryName>) => TConnection | undefined): Promise<{
12
+ items: Ref<TConnection["nodes"][number][], TConnection["nodes"][number][]>;
13
+ pending: any;
14
+ error: any;
15
+ reset: (clearProducts?: boolean) => void;
16
+ hasNextPage: ComputedRef<boolean>;
17
+ isLoadingMore: Ref<boolean, boolean>;
18
+ loadMore: () => void;
19
+ }>;
20
+ export {};
@@ -0,0 +1,60 @@
1
+ import { computed, ref, shallowRef, toValue, useAsyncGraphQLQuery, watch } from "#imports";
2
+ import { hash } from "ohash";
3
+ export async function useGraphQLLoadMore(queryName, inputVars, getConnection) {
4
+ const after = ref(null);
5
+ const addedCursors = /* @__PURE__ */ new Set();
6
+ const queryInput = computed(() => toValue(inputVars));
7
+ const queryInputHash = computed(() => hash(queryInput.value));
8
+ const queryVars = computed(() => ({
9
+ ...queryInput.value,
10
+ after: after.value
11
+ }));
12
+ const query = await useAsyncGraphQLQuery(
13
+ queryName,
14
+ queryVars,
15
+ {}
16
+ );
17
+ const items = shallowRef(getConnection(query.data.value)?.nodes || []);
18
+ const isLoadingMore = ref(false);
19
+ const hasNextPage = computed(
20
+ () => getConnection(query.data.value)?.pageInfo?.hasNextPage ?? false
21
+ );
22
+ const endCursor = computed(() => getConnection(query.data.value)?.pageInfo?.endCursor ?? null);
23
+ function reset(clearProducts = false) {
24
+ after.value = null;
25
+ addedCursors.clear();
26
+ if (clearProducts) {
27
+ items.value = [];
28
+ }
29
+ }
30
+ watch(
31
+ () => getConnection(query.data.value),
32
+ (connection) => {
33
+ const newItems = connection?.nodes || [];
34
+ if (after.value === null) {
35
+ items.value = newItems;
36
+ } else {
37
+ items.value = [...items.value, ...newItems];
38
+ }
39
+ isLoadingMore.value = false;
40
+ }
41
+ );
42
+ watch(queryInputHash, () => reset());
43
+ function loadMore() {
44
+ if (isLoadingMore.value || !hasNextPage.value || !endCursor.value || addedCursors.has(endCursor.value)) {
45
+ return;
46
+ }
47
+ addedCursors.add(endCursor.value);
48
+ isLoadingMore.value = true;
49
+ after.value = endCursor.value;
50
+ }
51
+ return {
52
+ items,
53
+ pending: query.pending,
54
+ error: query.error,
55
+ reset,
56
+ hasNextPage,
57
+ isLoadingMore,
58
+ loadMore
59
+ };
60
+ }
@@ -1,9 +1,5 @@
1
1
  import type { ExecuteGraphQLInput, ExecuteGraphQLResult, GraphQLVariables } from "../../shared/lib/types.js";
2
- declare const _default: import("#app").Plugin<{
3
- executeGraphQL: <TResult = unknown, TVariables extends GraphQLVariables = GraphQLVariables>({ query, variables, operationName }: ExecuteGraphQLInput<TVariables>) => Promise<ExecuteGraphQLResult<TResult>>;
4
- }> & import("#app").ObjectPlugin<{
5
- executeGraphQL: <TResult = unknown, TVariables extends GraphQLVariables = GraphQLVariables>({ query, variables, operationName }: ExecuteGraphQLInput<TVariables>) => Promise<ExecuteGraphQLResult<TResult>>;
6
- }>;
2
+ declare const _default: any;
7
3
  export default _default;
8
4
  type ExecuteGraphQL = <TResult = unknown, TVariables extends GraphQLVariables = GraphQLVariables>(input: ExecuteGraphQLInput<TVariables>) => Promise<ExecuteGraphQLResult<TResult>>;
9
5
  declare module "#app/nuxt" {
@@ -4,11 +4,7 @@ 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: import("#app").Plugin<{
8
- getGraphQLSSEClient: () => SSEClient;
9
- }> & import("#app").ObjectPlugin<{
10
- getGraphQLSSEClient: () => SSEClient;
11
- }>;
7
+ declare const _default: any;
12
8
  export default _default;
13
9
  declare module "#app/nuxt" {
14
10
  interface NuxtApp {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lewebsimple/nuxt-graphql",
3
- "version": "0.6.8",
3
+ "version": "0.6.10",
4
4
  "description": "Opinionated Nuxt module for using GraphQL",
5
5
  "repository": "lewebsimple/nuxt-graphql",
6
6
  "license": "AGPL-3.0-only",
@@ -33,8 +33,8 @@
33
33
  "@graphql-tools/graphql-file-loader": "^8.1.9",
34
34
  "@graphql-tools/load": "^8.1.8",
35
35
  "@graphql-tools/schema": "^10.0.31",
36
- "@graphql-tools/stitch": "^10.1.8",
37
- "@nuxt/kit": "^4.3.0",
36
+ "@graphql-tools/stitch": "^10.1.10",
37
+ "@nuxt/kit": "^4.3.1",
38
38
  "defu": "^6.1.4",
39
39
  "graphql": "^16.12.0",
40
40
  "graphql-sse": "^2.6.0",
@@ -45,14 +45,14 @@
45
45
  },
46
46
  "devDependencies": {
47
47
  "@nuxt/devtools": "^3.1.1",
48
- "@nuxt/eslint-config": "^1.13.0",
48
+ "@nuxt/eslint-config": "^1.15.1",
49
49
  "@nuxt/module-builder": "^1.0.2",
50
- "@nuxt/schema": "^4.3.0",
50
+ "@nuxt/schema": "^4.3.1",
51
51
  "@nuxt/test-utils": "^3.23.0",
52
52
  "@types/node": "latest",
53
53
  "changelogen": "^0.6.2",
54
54
  "eslint": "^9.39.2",
55
- "nuxt": "^4.3.0",
55
+ "nuxt": "^4.3.1",
56
56
  "typescript": "~5.9.3",
57
57
  "vitest": "^4.0.18",
58
58
  "vue-tsc": "^3.2.4"