@lewebsimple/nuxt-graphql 0.6.2 → 0.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.
- package/dist/module.json +1 -1
- package/dist/module.mjs +1 -3
- package/dist/runtime/app/composables/useAsyncGraphQLQuery.d.ts +4 -4
- package/dist/runtime/app/composables/useAsyncGraphQLQuery.js +2 -2
- package/dist/runtime/app/composables/useGraphQLCache.client.d.ts +1 -9
- package/dist/runtime/app/lib/cache.d.ts +1 -6
- package/dist/runtime/app/plugins/execute-graphql.d.ts +0 -7
- package/dist/runtime/shared/lib/types.d.ts +14 -0
- package/package.json +2 -2
package/dist/module.json
CHANGED
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.
|
|
206
|
+
const version = "0.6.4";
|
|
207
207
|
|
|
208
208
|
async function getDocuments(documentsGlob) {
|
|
209
209
|
try {
|
|
@@ -234,7 +234,6 @@ async function getOperationsTemplate({ loadSchema, loadDocuments, documentGlob }
|
|
|
234
234
|
avoidOptionals: true,
|
|
235
235
|
defaultScalarType: "never",
|
|
236
236
|
enumsAsTypes: true,
|
|
237
|
-
immutableTypes: true,
|
|
238
237
|
maybeValue: "T | null",
|
|
239
238
|
preResolveTypes: false,
|
|
240
239
|
strictScalars: true,
|
|
@@ -247,7 +246,6 @@ async function getOperationsTemplate({ loadSchema, loadDocuments, documentGlob }
|
|
|
247
246
|
defaultScalarType: "never",
|
|
248
247
|
enumsAsTypes: true,
|
|
249
248
|
exportFragmentSpreadSubTypes: true,
|
|
250
|
-
immutableTypes: true,
|
|
251
249
|
inlineFragmentTypes: "combine",
|
|
252
250
|
maybeValue: "T | null",
|
|
253
251
|
operationResultSuffix: "Result",
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type AsyncData, type AsyncDataOptions } from "#app";
|
|
2
2
|
import type { QueryName, ResultOf, VariablesOf } from "#graphql/registry";
|
|
3
3
|
import { type MaybeRefOrGetter } from "#imports";
|
|
4
|
-
import type { IsEmptyObject } from "../../shared/lib/types.js";
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
import type { CacheConfig, IsEmptyObject } from "../../shared/lib/types.js";
|
|
5
|
+
type UseAsyncGraphQLQueryOptions<TName extends QueryName, TTransformed = ResultOf<TName>> = Omit<AsyncDataOptions<ResultOf<TName>>, "transform"> & {
|
|
6
|
+
transform?: (input: ResultOf<TName>) => TTransformed;
|
|
7
7
|
cache?: Partial<CacheConfig>;
|
|
8
8
|
};
|
|
9
9
|
/**
|
|
@@ -13,5 +13,5 @@ type UseAsyncGraphQLQueryOptions<TName extends QueryName> = AsyncDataOptions<Res
|
|
|
13
13
|
* @param args Operation variables (if any) and optional HTTP headers.
|
|
14
14
|
* @returns Nuxt AsyncData wrapper for the query result.
|
|
15
15
|
*/
|
|
16
|
-
export declare function useAsyncGraphQLQuery<TName extends QueryName
|
|
16
|
+
export declare function useAsyncGraphQLQuery<TName extends QueryName, TTransformed = ResultOf<TName>>(operationName: TName, ...args: IsEmptyObject<VariablesOf<TName>> extends true ? [variables?: MaybeRefOrGetter<VariablesOf<TName>>, options?: UseAsyncGraphQLQueryOptions<TName, TTransformed>] : [variables: MaybeRefOrGetter<VariablesOf<TName>>, options?: UseAsyncGraphQLQueryOptions<TName, TTransformed>]): AsyncData<TTransformed | null, Error | undefined>;
|
|
17
17
|
export {};
|
|
@@ -10,7 +10,7 @@ export function useAsyncGraphQLQuery(operationName, ...args) {
|
|
|
10
10
|
const document = getOperationDocument(operationName);
|
|
11
11
|
const isClient = import.meta.client;
|
|
12
12
|
const { public: { graphql } } = useRuntimeConfig();
|
|
13
|
-
const { cache, ...asyncDataOptions } = options ?? {};
|
|
13
|
+
const { cache, transform, ...asyncDataOptions } = options ?? {};
|
|
14
14
|
const cacheConfig = resolveCacheConfig(graphql.cacheConfig, cache);
|
|
15
15
|
const cacheKey = computed(() => getCacheKeyParts(cacheConfig, operationName, toValue(variables)).key);
|
|
16
16
|
const inFlight = getInFlightRequests();
|
|
@@ -81,5 +81,5 @@ export function useAsyncGraphQLQuery(operationName, ...args) {
|
|
|
81
81
|
throw new Error(`Unknown cache policy: ${cacheConfig.policy}`);
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
|
-
return useAsyncData(cacheKey, asyncDataHandler, asyncDataOptions);
|
|
84
|
+
return useAsyncData(cacheKey, asyncDataHandler, { ...asyncDataOptions, transform });
|
|
85
85
|
}
|
|
@@ -1,21 +1,13 @@
|
|
|
1
1
|
import type { QueryName } from "#graphql/registry";
|
|
2
|
-
import { type CacheConfig } from "../lib/cache.js";
|
|
3
2
|
/**
|
|
4
3
|
* GraphQL cache helper composable.
|
|
5
4
|
*
|
|
6
5
|
* @returns Cache config and invalidation helper.
|
|
7
6
|
*/
|
|
8
7
|
export declare function useGraphQLCache(): {
|
|
9
|
-
readonly cacheConfig: CacheConfig;
|
|
8
|
+
readonly cacheConfig: import("../../shared/lib/types.js").CacheConfig;
|
|
10
9
|
readonly invalidate: (options?: {
|
|
11
10
|
operation: QueryName;
|
|
12
11
|
variables?: unknown;
|
|
13
12
|
}) => Promise<void>;
|
|
14
13
|
};
|
|
15
|
-
declare module "nuxt/schema" {
|
|
16
|
-
interface PublicRuntimeConfig {
|
|
17
|
-
graphql: {
|
|
18
|
-
cacheConfig: CacheConfig;
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
policy: "no-cache" | "cache-first" | "network-first" | "swr";
|
|
3
|
-
ttl?: number;
|
|
4
|
-
keyPrefix: string;
|
|
5
|
-
keyVersion: string | number;
|
|
6
|
-
};
|
|
1
|
+
import type { CacheConfig } from "../../shared/lib/types.js";
|
|
7
2
|
/**
|
|
8
3
|
* Resolve cache config from default value with user overrides.
|
|
9
4
|
*
|
|
@@ -13,4 +13,18 @@ export type ExecuteGraphQLResult<TResult> = {
|
|
|
13
13
|
data: null;
|
|
14
14
|
error: NormalizedError;
|
|
15
15
|
};
|
|
16
|
+
export type CacheConfig = {
|
|
17
|
+
policy: "no-cache" | "cache-first" | "network-first" | "swr";
|
|
18
|
+
ttl?: number;
|
|
19
|
+
keyPrefix: string;
|
|
20
|
+
keyVersion: string | number;
|
|
21
|
+
};
|
|
16
22
|
export type IsEmptyObject<T> = [T] extends [never] ? true : T extends object ? keyof T extends never ? true : false : false;
|
|
23
|
+
declare module "nuxt/schema" {
|
|
24
|
+
interface PublicRuntimeConfig {
|
|
25
|
+
graphql: {
|
|
26
|
+
cacheConfig: CacheConfig;
|
|
27
|
+
ssrForwardHeaders: string[];
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lewebsimple/nuxt-graphql",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.4",
|
|
4
4
|
"description": "Opinionated Nuxt module for using GraphQL",
|
|
5
|
-
"repository": "
|
|
5
|
+
"repository": "lewebsimple/nuxt-graphql",
|
|
6
6
|
"license": "AGPL-3.0-only",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"exports": {
|