@lewebsimple/nuxt-graphql 0.1.11 → 0.1.13
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.d.mts +2 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +8 -6
- package/dist/runtime/composables/useGraphQLCache.d.ts +5 -0
- package/dist/runtime/composables/useGraphQLMutation.d.ts +6 -0
- package/dist/runtime/composables/useGraphQLQuery.d.ts +7 -0
- package/dist/runtime/composables/useGraphQLSubscription.d.ts +7 -0
- package/dist/runtime/server/utils/graphql-client.d.ts +1 -2
- package/dist/runtime/server/utils/{useGraphQLMutation.d.ts → useServerGraphQLMutation.d.ts} +8 -1
- package/dist/runtime/server/utils/{useGraphQLMutation.js → useServerGraphQLMutation.js} +1 -1
- package/dist/runtime/server/utils/useServerGraphQLQuery.d.ts +12 -0
- package/dist/runtime/server/utils/{useGraphQLQuery.js → useServerGraphQLQuery.js} +1 -1
- package/dist/runtime/types/graphql-client.d.ts +3 -1
- package/dist/runtime/utils/graphql-cache.d.ts +12 -2
- package/dist/runtime/utils/graphql-error.d.ts +1 -2
- package/package.json +8 -6
- package/dist/runtime/server/utils/useGraphQLQuery.d.ts +0 -4
package/dist/module.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
2
|
import { GraphQLCacheConfig } from '../dist/runtime/utils/graphql-cache.js';
|
|
3
|
+
import { CodegenConfig } from '@graphql-codegen/cli';
|
|
3
4
|
|
|
4
5
|
interface ModuleOptions {
|
|
5
6
|
endpoint?: string;
|
|
@@ -12,6 +13,7 @@ interface ModuleOptions {
|
|
|
12
13
|
input: string;
|
|
13
14
|
output: string;
|
|
14
15
|
}>;
|
|
16
|
+
generates?: CodegenConfig["generates"];
|
|
15
17
|
};
|
|
16
18
|
}
|
|
17
19
|
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -175,7 +175,7 @@ function formatDefinitions(defs) {
|
|
|
175
175
|
return defs.map((def) => `${colorOf(def)}${def.name}${reset}`).join(`${dim} / ${reset}`);
|
|
176
176
|
}
|
|
177
177
|
async function runCodegen(options) {
|
|
178
|
-
const { sdl, documents, operationsFile, schemasFile, scalars } = options;
|
|
178
|
+
const { sdl, documents, operationsFile, schemasFile, scalars, generates: customGenerates } = options;
|
|
179
179
|
if (documents.length === 0) {
|
|
180
180
|
logger.warn("No GraphQL documents found");
|
|
181
181
|
return;
|
|
@@ -232,6 +232,9 @@ async function runCodegen(options) {
|
|
|
232
232
|
scalarSchemas: zodScalars
|
|
233
233
|
}
|
|
234
234
|
};
|
|
235
|
+
if (customGenerates) {
|
|
236
|
+
Object.assign(generates, customGenerates);
|
|
237
|
+
}
|
|
235
238
|
}
|
|
236
239
|
await generate({ schema: sdl, documents, generates, silent: true, errorsOnly: true }, true);
|
|
237
240
|
logger.success(`Generated types for ${documents.length} document(s)`);
|
|
@@ -300,10 +303,8 @@ const module$1 = defineNuxtModule({
|
|
|
300
303
|
nuxt.options.alias["#graphql/registry"] = registryFile;
|
|
301
304
|
nuxt.options.alias["#graphql/schemas"] = schemasFile;
|
|
302
305
|
const schemaOutput = options.codegen?.schemaOutput ?? "server/graphql/schema.graphql";
|
|
303
|
-
if (schemaOutput) {
|
|
304
|
-
|
|
305
|
-
logger.warn(`Schema output '${schemaOutput}' should have .graphql extension.`);
|
|
306
|
-
}
|
|
306
|
+
if (schemaOutput && !schemaOutput.endsWith(".graphql")) {
|
|
307
|
+
logger.warn(`Schema output '${schemaOutput}' should have .graphql extension.`);
|
|
307
308
|
}
|
|
308
309
|
const schemaFile = join(rootDir, schemaOutput);
|
|
309
310
|
const generate = async () => {
|
|
@@ -323,7 +324,8 @@ const module$1 = defineNuxtModule({
|
|
|
323
324
|
documents,
|
|
324
325
|
operationsFile,
|
|
325
326
|
schemasFile,
|
|
326
|
-
scalars: options.codegen?.scalars
|
|
327
|
+
scalars: options.codegen?.scalars,
|
|
328
|
+
generates: options.codegen?.generates
|
|
327
329
|
});
|
|
328
330
|
if (writeFileIfChanged(schemaFile, sdl)) {
|
|
329
331
|
logger.info(`GraphQL schema saved to ${cyan}${schemaOutput}${reset}`);
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import type { QueryName, QueryVariables } from "#graphql/registry";
|
|
2
|
+
/**
|
|
3
|
+
* GraphQL cache management composable
|
|
4
|
+
*
|
|
5
|
+
* @returns Object with enabled flag and invalidate function
|
|
6
|
+
*/
|
|
2
7
|
export declare function useGraphQLCache(): {
|
|
3
8
|
enabled: any;
|
|
4
9
|
invalidate: <N extends QueryName>(operationName?: N, variables?: QueryVariables<N>) => Promise<void>;
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { type MutationName, type MutationResult, type MutationVariables } from "#graphql/registry";
|
|
2
2
|
import type { IsEmptyObject } from "../utils/helpers.js";
|
|
3
|
+
/**
|
|
4
|
+
* Client-side GraphQL mutation composable
|
|
5
|
+
*
|
|
6
|
+
* @param operationName Mutation operation name
|
|
7
|
+
* @returns Object with mutate function and pending state
|
|
8
|
+
*/
|
|
3
9
|
export declare function useGraphQLMutation<N extends MutationName>(operationName: N): {
|
|
4
10
|
mutate: (...args: IsEmptyObject<MutationVariables<N>> extends true ? [variables?: MutationVariables<N>, headers?: HeadersInit] : [variables: MutationVariables<N>, headers?: HeadersInit]) => Promise<{
|
|
5
11
|
data: MutationResult<N> | null;
|
|
@@ -6,4 +6,11 @@ export interface UseGraphQLQueryOptions<T> extends AsyncDataOptions<T> {
|
|
|
6
6
|
cache?: CacheOptions | false;
|
|
7
7
|
headers?: HeadersInit;
|
|
8
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Client-side GraphQL query composable with caching and deduplication
|
|
11
|
+
*
|
|
12
|
+
* @param operationName Query operation name
|
|
13
|
+
* @param args Variables and optional configuration
|
|
14
|
+
* @returns AsyncData object with query result
|
|
15
|
+
*/
|
|
9
16
|
export declare function useGraphQLQuery<N extends QueryName>(operationName: N, ...args: IsEmptyObject<QueryVariables<N>> extends true ? [variables?: QueryVariables<N>, options?: UseGraphQLQueryOptions<QueryResult<N>>] : [variables: QueryVariables<N>, options?: UseGraphQLQueryOptions<QueryResult<N>>]): AsyncData<QueryResult<N>, Error | null>;
|
|
@@ -8,4 +8,11 @@ export type UseGraphQLSubscriptionReturn<N extends SubscriptionName> = {
|
|
|
8
8
|
start: () => void;
|
|
9
9
|
stop: () => void;
|
|
10
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* Client-side GraphQL subscription composable using SSE
|
|
13
|
+
*
|
|
14
|
+
* @param operationName Subscription operation name
|
|
15
|
+
* @param args Variables (can be reactive)
|
|
16
|
+
* @returns Object with data, error, start, and stop
|
|
17
|
+
*/
|
|
11
18
|
export declare function useGraphQLSubscription<N extends SubscriptionName>(operationName: N, ...args: IsEmptyObject<SubscriptionVariables<N>> extends true ? [variables?: MaybeRefOrGetter<SubscriptionVariables<N>>] : [variables: MaybeRefOrGetter<SubscriptionVariables<N>>]): UseGraphQLSubscriptionReturn<N>;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { H3Event } from "h3";
|
|
2
2
|
import { GraphQLClient } from "graphql-request";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Get or create a server-side GraphQL client for an H3 event
|
|
5
5
|
*
|
|
6
6
|
* @param event H3 event
|
|
7
|
-
*
|
|
8
7
|
* @returns GraphQL client instance
|
|
9
8
|
*/
|
|
10
9
|
export declare function getGraphQLClient(event: H3Event): GraphQLClient;
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import type { H3Event } from "h3";
|
|
2
2
|
import { type MutationName, type MutationResult, type MutationVariables } from "#graphql/registry";
|
|
3
3
|
import type { IsEmptyObject } from "../../utils/helpers.js";
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Server-side GraphQL mutation composable
|
|
6
|
+
*
|
|
7
|
+
* @param event H3 event
|
|
8
|
+
* @param operationName Mutation operation name
|
|
9
|
+
* @returns Object with mutate function
|
|
10
|
+
*/
|
|
11
|
+
export declare function useServerGraphQLMutation<N extends MutationName>(event: H3Event, operationName: N): Promise<{
|
|
5
12
|
mutate: (...args: IsEmptyObject<MutationVariables<N>> extends true ? [variables?: MutationVariables<N>, headers?: HeadersInit] : [variables: MutationVariables<N>, headers?: HeadersInit]) => Promise<{
|
|
6
13
|
data: MutationResult<N> | null;
|
|
7
14
|
error: Error | null;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getGraphQLClient } from "./graphql-client.js";
|
|
2
2
|
import { mutations } from "#graphql/registry";
|
|
3
|
-
export async function
|
|
3
|
+
export async function useServerGraphQLMutation(event, operationName) {
|
|
4
4
|
const client = getGraphQLClient(event);
|
|
5
5
|
async function mutate(...args) {
|
|
6
6
|
try {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { H3Event } from "h3";
|
|
2
|
+
import { type QueryName, type QueryResult, type QueryVariables } from "#graphql/registry";
|
|
3
|
+
import type { IsEmptyObject } from "../../utils/helpers.js";
|
|
4
|
+
/**
|
|
5
|
+
* Server-side GraphQL query composable
|
|
6
|
+
*
|
|
7
|
+
* @param event H3 event
|
|
8
|
+
* @param operationName Query operation name
|
|
9
|
+
* @param args Variables and optional headers
|
|
10
|
+
* @returns Query result
|
|
11
|
+
*/
|
|
12
|
+
export declare function useServerGraphQLQuery<N extends QueryName>(event: H3Event, operationName: N, ...args: IsEmptyObject<QueryVariables<N>> extends true ? [variables?: QueryVariables<N>, headers?: HeadersInit] : [variables: QueryVariables<N>, headers?: HeadersInit]): Promise<QueryResult<N>>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getGraphQLClient } from "./graphql-client.js";
|
|
2
2
|
import { queries } from "#graphql/registry";
|
|
3
|
-
export async function
|
|
3
|
+
export async function useServerGraphQLQuery(event, operationName, ...args) {
|
|
4
4
|
const client = getGraphQLClient(event);
|
|
5
5
|
const [variables, headers] = args;
|
|
6
6
|
return client.request(queries[operationName], variables, headers);
|
|
@@ -2,17 +2,19 @@ import type { GraphQLClient } from "graphql-request";
|
|
|
2
2
|
import type { Client as SSEClient } from "graphql-sse";
|
|
3
3
|
import type { GraphQLClientError } from "../utils/graphql-error";
|
|
4
4
|
|
|
5
|
+
// Extend NuxtApp with GraphQL clients
|
|
5
6
|
declare module "#app" {
|
|
6
7
|
interface NuxtApp {
|
|
7
8
|
$graphql: () => GraphQLClient;
|
|
8
9
|
$graphqlSSE: () => SSEClient;
|
|
9
10
|
}
|
|
11
|
+
|
|
10
12
|
interface RuntimeNuxtHooks {
|
|
11
|
-
"graphql:headers": (headers: Record<string, string>) => void | Promise<void>;
|
|
12
13
|
"graphql:error": (error: GraphQLClientError) => void;
|
|
13
14
|
}
|
|
14
15
|
}
|
|
15
16
|
|
|
17
|
+
// Extend Nuxt runtime config with GraphQL options
|
|
16
18
|
declare module "nuxt/schema" {
|
|
17
19
|
interface PublicRuntimeConfig {
|
|
18
20
|
graphql: {
|
|
@@ -15,11 +15,21 @@ export declare function dedupeGet(operationName: string, variables: unknown): Pr
|
|
|
15
15
|
export declare function dedupeSet(operationName: string, variables: unknown, promise: Promise<unknown>): void;
|
|
16
16
|
/**
|
|
17
17
|
* Register a refresh callback for a query
|
|
18
|
+
*
|
|
19
|
+
* @param operationName GraphQL operation name
|
|
20
|
+
* @param variables Query variables
|
|
21
|
+
* @param refresh Callback to execute on cache invalidation
|
|
22
|
+
* @returns Unregister function
|
|
18
23
|
*/
|
|
19
24
|
export declare function registerRefresh(operationName: string, variables: unknown, refresh: () => void): () => void;
|
|
20
25
|
/**
|
|
21
|
-
* Invalidate cached queries and trigger
|
|
22
|
-
*
|
|
26
|
+
* Invalidate cached queries and trigger refresh callbacks
|
|
27
|
+
*
|
|
28
|
+
* @param operationName Optional operation name to filter invalidation
|
|
29
|
+
* @param variables Optional variables to target specific query
|
|
30
|
+
*
|
|
31
|
+
* Usage:
|
|
32
|
+
* - No args: invalidate all queries
|
|
23
33
|
* - operationName only: invalidate all queries with that name
|
|
24
34
|
* - operationName + variables: invalidate specific query
|
|
25
35
|
*/
|
|
@@ -6,8 +6,7 @@ export declare class GraphQLClientError extends Error {
|
|
|
6
6
|
/**
|
|
7
7
|
* Wrap a generic error into a GraphQLClientError
|
|
8
8
|
*
|
|
9
|
-
* @param error Generic error
|
|
10
|
-
*
|
|
9
|
+
* @param error Generic error from various sources
|
|
11
10
|
* @returns Wrapped GraphQLClientError
|
|
12
11
|
*/
|
|
13
12
|
export declare function wrapError(error: unknown): GraphQLClientError;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lewebsimple/nuxt-graphql",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.13",
|
|
4
4
|
"description": "Opinionated Nuxt module for using GraphQL",
|
|
5
5
|
"repository": "lewebsimple/nuxt-graphql",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,13 +31,14 @@
|
|
|
31
31
|
"lint": "eslint .",
|
|
32
32
|
"test": "vitest run",
|
|
33
33
|
"test:watch": "vitest watch",
|
|
34
|
+
"test:coverage": "vitest run --coverage",
|
|
34
35
|
"test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit"
|
|
35
36
|
},
|
|
36
37
|
"dependencies": {
|
|
37
|
-
"@graphql-codegen/cli": "^
|
|
38
|
-
"@graphql-codegen/typed-document-node": "^
|
|
39
|
-
"@graphql-codegen/typescript": "^
|
|
40
|
-
"@graphql-codegen/typescript-operations": "^
|
|
38
|
+
"@graphql-codegen/cli": "^6.1.0",
|
|
39
|
+
"@graphql-codegen/typed-document-node": "^6.1.5",
|
|
40
|
+
"@graphql-codegen/typescript": "^5.0.7",
|
|
41
|
+
"@graphql-codegen/typescript-operations": "^5.0.7",
|
|
41
42
|
"@graphql-typed-document-node/core": "^3.2.0",
|
|
42
43
|
"@nuxt/kit": "^4.2.2",
|
|
43
44
|
"graphql": "^16.12.0",
|
|
@@ -58,6 +59,7 @@
|
|
|
58
59
|
"@nuxt/schema": "^4.2.2",
|
|
59
60
|
"@nuxt/test-utils": "^3.21.0",
|
|
60
61
|
"@types/node": "latest",
|
|
62
|
+
"@vitest/coverage-v8": "^4.0.16",
|
|
61
63
|
"changelogen": "^0.6.2",
|
|
62
64
|
"eslint": "^9.39.2",
|
|
63
65
|
"nuxt": "^4.2.2",
|
|
@@ -73,4 +75,4 @@
|
|
|
73
75
|
"chore": false
|
|
74
76
|
}
|
|
75
77
|
}
|
|
76
|
-
}
|
|
78
|
+
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { H3Event } from "h3";
|
|
2
|
-
import { type QueryName, type QueryResult, type QueryVariables } from "#graphql/registry";
|
|
3
|
-
import type { IsEmptyObject } from "../../utils/helpers.js";
|
|
4
|
-
export declare function useGraphQLQuery<N extends QueryName>(event: H3Event, operationName: N, ...args: IsEmptyObject<QueryVariables<N>> extends true ? [variables?: QueryVariables<N>, headers?: HeadersInit] : [variables: QueryVariables<N>, headers?: HeadersInit]): Promise<QueryResult<N>>;
|