@lewebsimple/nuxt-graphql 0.7.7 → 0.7.9
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/README.md +1 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +15 -4
- package/dist/runtime/app/composables/useGraphQLLoadMore.d.ts +5 -5
- package/dist/runtime/app/composables/useGraphQLMutation.d.ts +2 -2
- package/dist/runtime/app/plugins/graphql-sse.client.d.ts +1 -5
- package/dist/runtime/app/plugins/graphql.d.ts +1 -5
- package/dist/runtime/server/lib/yoga.js +17 -2
- package/dist/runtime/server/utils/execute-schema.d.ts +5 -0
- package/dist/runtime/server/utils/execute-schema.js +7 -2
- package/package.json +29 -28
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ Opinionated Nuxt module that wires a typed GraphQL server + client into your app
|
|
|
24
24
|
Install the module and its dependencies in your project:
|
|
25
25
|
|
|
26
26
|
```bash
|
|
27
|
-
pnpm add @lewebsimple/nuxt-graphql zod
|
|
27
|
+
pnpm add @lewebsimple/nuxt-graphql @lewebsimple/graphql-codegen-zod graphql zod
|
|
28
28
|
```
|
|
29
29
|
|
|
30
30
|
### Configuration
|
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.9";
|
|
20
20
|
|
|
21
21
|
const buildCache = /* @__PURE__ */ new Map();
|
|
22
22
|
function getCachedLoader(baseKey, loader) {
|
|
@@ -374,6 +374,14 @@ function getSchemaTemplate({ localPaths, remotePaths }) {
|
|
|
374
374
|
schemaRefs.push(`mergeSchemas({ schemas: [${localSchemaRefs.join(", ")}] })`);
|
|
375
375
|
}
|
|
376
376
|
schemaRefs.push(...remoteSchemaRefs);
|
|
377
|
+
if (localPaths.length === 0 && remotePaths.length === 1) {
|
|
378
|
+
return [
|
|
379
|
+
...imports,
|
|
380
|
+
"",
|
|
381
|
+
`export const schema = remoteSchema0.schema;`,
|
|
382
|
+
`export const executor = remoteSchema0.executor;`
|
|
383
|
+
].join("\n");
|
|
384
|
+
}
|
|
377
385
|
let schemaRef;
|
|
378
386
|
if (schemaRefs.length === 0) {
|
|
379
387
|
imports.unshift(`import { buildSchema } from "graphql";`);
|
|
@@ -382,12 +390,13 @@ function getSchemaTemplate({ localPaths, remotePaths }) {
|
|
|
382
390
|
schemaRef = schemaRefs[0];
|
|
383
391
|
} else {
|
|
384
392
|
imports.unshift(`import { stitchSchemas } from "@graphql-tools/stitch";`);
|
|
385
|
-
schemaRef = `stitchSchemas({ subschemas: [${schemaRefs.join(", ")}] })`;
|
|
393
|
+
schemaRef = `stitchSchemas({ subschemas: [${schemaRefs.join(", ")}], mergeTypes: false })`;
|
|
386
394
|
}
|
|
387
395
|
return [
|
|
388
396
|
...imports,
|
|
389
397
|
"",
|
|
390
|
-
`export const schema = ${schemaRef}
|
|
398
|
+
`export const schema = ${schemaRef};`,
|
|
399
|
+
`export const executor = undefined;`
|
|
391
400
|
].join("\n");
|
|
392
401
|
}
|
|
393
402
|
async function loadLocalSchema(path, nuxt) {
|
|
@@ -529,8 +538,10 @@ const module$1 = defineNuxtModule({
|
|
|
529
538
|
logger.warn("No GraphQL schemas loaded: using default empty schema.");
|
|
530
539
|
}
|
|
531
540
|
schema = buildSchema("type Query { _empty: String }");
|
|
541
|
+
} else if (schemas.length === 1) {
|
|
542
|
+
schema = schemas[0];
|
|
532
543
|
} else {
|
|
533
|
-
schema = stitchSchemas({ subschemas: schemas });
|
|
544
|
+
schema = stitchSchemas({ subschemas: schemas, mergeTypes: false });
|
|
534
545
|
if (!schema) {
|
|
535
546
|
throw new Error("Failed to load GraphQL schema");
|
|
536
547
|
}
|
|
@@ -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: any;
|
|
20
|
+
pending: any;
|
|
21
|
+
error: any;
|
|
22
|
+
hasNextPage: any;
|
|
23
|
+
isLoadingMore: any;
|
|
24
24
|
loadMore: () => void;
|
|
25
25
|
reset: () => void;
|
|
26
26
|
}>;
|
|
@@ -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: any;
|
|
54
|
+
mutate: (variables: VariablesInputOf<TName>) => Promise<any>;
|
|
55
55
|
};
|
|
@@ -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:
|
|
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 {
|
|
@@ -5,11 +5,7 @@ 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:
|
|
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
|
-
}>;
|
|
8
|
+
declare const _default: any;
|
|
13
9
|
export default _default;
|
|
14
10
|
type ExecuteGraphQL = <TName extends OperationName>(input: ExecuteGraphQLInput<TName>) => Promise<ExecuteGraphQLResult<TName>>;
|
|
15
11
|
declare module "#app/nuxt" {
|
|
@@ -1,13 +1,28 @@
|
|
|
1
|
-
import { schema } from "#graphql/schema";
|
|
1
|
+
import { executor, schema } from "#graphql/schema";
|
|
2
2
|
import { createYoga } from "graphql-yoga";
|
|
3
3
|
let yoga = null;
|
|
4
|
+
function passthroughPlugin() {
|
|
5
|
+
return {
|
|
6
|
+
onExecute({ setExecuteFn }) {
|
|
7
|
+
setExecuteFn(async ({ document, variableValues, operationName, contextValue }) => {
|
|
8
|
+
return await executor({
|
|
9
|
+
document,
|
|
10
|
+
variables: variableValues ?? void 0,
|
|
11
|
+
operationName: operationName ?? void 0,
|
|
12
|
+
context: contextValue
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
}
|
|
4
18
|
export function getYogaInstance() {
|
|
5
19
|
if (!yoga) {
|
|
6
20
|
yoga = createYoga({
|
|
7
21
|
graphqlEndpoint: "/api/graphql",
|
|
8
22
|
graphiql: import.meta.dev,
|
|
9
23
|
fetchAPI: globalThis,
|
|
10
|
-
schema
|
|
24
|
+
schema,
|
|
25
|
+
plugins: executor ? [passthroughPlugin()] : []
|
|
11
26
|
});
|
|
12
27
|
if (!yoga) {
|
|
13
28
|
throw new Error("Failed to create Yoga instance");
|
|
@@ -4,6 +4,11 @@ import { type OperationName } from "../../shared/utils/registry.js";
|
|
|
4
4
|
/**
|
|
5
5
|
* Execute a typed / validated GraphQL operation against the schema.
|
|
6
6
|
*
|
|
7
|
+
* In passthrough mode (single remote subschema, no local schema), execution
|
|
8
|
+
* is forwarded directly to the remote executor — `graphql.execute` is skipped
|
|
9
|
+
* along with the schema's resolver walk. Otherwise the operation runs against
|
|
10
|
+
* the local executable schema in-process.
|
|
11
|
+
*
|
|
7
12
|
* @param event Current request event.
|
|
8
13
|
* @param input Operation input payload.
|
|
9
14
|
* @returns Typed operation result or normalized error.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createContext } from "#graphql/context";
|
|
2
|
-
import { schema } from "#graphql/schema";
|
|
2
|
+
import { executor, schema } from "#graphql/schema";
|
|
3
3
|
import { execute } from "graphql";
|
|
4
4
|
import { normalizeError } from "../../shared/utils/error.js";
|
|
5
5
|
import {
|
|
@@ -12,7 +12,12 @@ export async function executeSchemaOperation(event, { operationName, variables }
|
|
|
12
12
|
const document = getOperationDocument(operationName);
|
|
13
13
|
const variableValues = parseOperationVariables(operationName, variables);
|
|
14
14
|
const contextValue = await createContext(event);
|
|
15
|
-
const result = await
|
|
15
|
+
const result = executor ? await executor({
|
|
16
|
+
document,
|
|
17
|
+
variables: variableValues,
|
|
18
|
+
operationName,
|
|
19
|
+
context: contextValue
|
|
20
|
+
}) : await execute({ schema, document, variableValues, operationName, contextValue });
|
|
16
21
|
if (result.errors?.length) {
|
|
17
22
|
return { data: null, error: normalizeError(result.errors) };
|
|
18
23
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lewebsimple/nuxt-graphql",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.9",
|
|
4
4
|
"description": "Opinionated Nuxt module for using GraphQL",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"repository": "lewebsimple/nuxt-graphql",
|
|
@@ -26,46 +26,47 @@
|
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@graphql-codegen/core": "^5.0.
|
|
29
|
+
"@graphql-codegen/core": "^5.0.2",
|
|
30
30
|
"@graphql-codegen/typed-document-node": "6.1.6",
|
|
31
|
-
"@graphql-codegen/typescript": "^5.0.
|
|
32
|
-
"@graphql-codegen/typescript-operations": "^5.0
|
|
33
|
-
"@graphql-tools/code-file-loader": "^8.1.
|
|
34
|
-
"@graphql-tools/graphql-file-loader": "^8.1.
|
|
35
|
-
"@graphql-tools/load": "^8.1.
|
|
36
|
-
"@graphql-tools/schema": "^10.0.
|
|
37
|
-
"@graphql-tools/stitch": "^10.1.
|
|
31
|
+
"@graphql-codegen/typescript": "^5.0.10",
|
|
32
|
+
"@graphql-codegen/typescript-operations": "^5.1.0",
|
|
33
|
+
"@graphql-tools/code-file-loader": "^8.1.32",
|
|
34
|
+
"@graphql-tools/graphql-file-loader": "^8.1.14",
|
|
35
|
+
"@graphql-tools/load": "^8.1.10",
|
|
36
|
+
"@graphql-tools/schema": "^10.0.33",
|
|
37
|
+
"@graphql-tools/stitch": "^10.1.19",
|
|
38
38
|
"@graphql-typed-document-node/core": "^3.2.0",
|
|
39
|
-
"@
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"es-toolkit": "^1.45.1",
|
|
39
|
+
"@nuxt/kit": "^4.4.6",
|
|
40
|
+
"defu": "^6.1.7",
|
|
41
|
+
"es-toolkit": "^1.46.1",
|
|
43
42
|
"graphql-sse": "^2.6.0",
|
|
44
|
-
"graphql-yoga": "^5.
|
|
45
|
-
"jiti": "^2.
|
|
43
|
+
"graphql-yoga": "^5.21.0",
|
|
44
|
+
"jiti": "^2.7.0",
|
|
46
45
|
"ohash": "^2.0.11",
|
|
47
46
|
"picocolors": "^1.1.1",
|
|
48
|
-
"picomatch": "^4.0.
|
|
47
|
+
"picomatch": "^4.0.4"
|
|
49
48
|
},
|
|
50
49
|
"devDependencies": {
|
|
51
|
-
"@graphql-codegen/plugin-helpers": "^
|
|
50
|
+
"@graphql-codegen/plugin-helpers": "^7.0.1",
|
|
51
|
+
"@lewebsimple/graphql-codegen-zod": "^0.2.5",
|
|
52
52
|
"@nuxt/devtools": "^3.2.4",
|
|
53
53
|
"@nuxt/module-builder": "^1.0.2",
|
|
54
|
-
"@nuxt/schema": "^4.4.
|
|
55
|
-
"@nuxt/test-utils": "^4.0.
|
|
54
|
+
"@nuxt/schema": "^4.4.6",
|
|
55
|
+
"@nuxt/test-utils": "^4.0.3",
|
|
56
56
|
"@types/node": "latest",
|
|
57
|
-
"@types/picomatch": "^4.0.
|
|
57
|
+
"@types/picomatch": "^4.0.3",
|
|
58
58
|
"changelogen": "^0.6.2",
|
|
59
|
-
"graphql": "^16.
|
|
60
|
-
"nuxt": "^4.4.
|
|
61
|
-
"oxfmt": "^0.
|
|
62
|
-
"oxlint": "^1.
|
|
63
|
-
"typescript": "
|
|
64
|
-
"vitest": "^4.1.
|
|
65
|
-
"vue-tsc": "^3.
|
|
66
|
-
"zod": "^4.3
|
|
59
|
+
"graphql": "^16.14.0",
|
|
60
|
+
"nuxt": "^4.4.6",
|
|
61
|
+
"oxfmt": "^0.51.0",
|
|
62
|
+
"oxlint": "^1.66.0",
|
|
63
|
+
"typescript": "^6.0.3",
|
|
64
|
+
"vitest": "^4.1.7",
|
|
65
|
+
"vue-tsc": "^3.3.1",
|
|
66
|
+
"zod": "^4.4.3"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
+
"@lewebsimple/graphql-codegen-zod": "^0.2",
|
|
69
70
|
"graphql": "^16",
|
|
70
71
|
"zod": "^4"
|
|
71
72
|
},
|