@lewebsimple/nuxt-graphql 0.7.8 → 0.7.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 +1 -1
- package/dist/module.mjs +31 -7
- 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 +13 -2
- package/package.json +28 -28
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.10";
|
|
20
20
|
|
|
21
21
|
const buildCache = /* @__PURE__ */ new Map();
|
|
22
22
|
function getCachedLoader(baseKey, loader) {
|
|
@@ -340,7 +340,7 @@ function getRemoteSchemaTemplate({
|
|
|
340
340
|
const hookRefs = hooks.map((_, index) => `hook${index}`);
|
|
341
341
|
return `
|
|
342
342
|
import { getRemoteExecutor } from "#graphql/runtime/remote-executor";
|
|
343
|
-
import { buildSchema } from "graphql";
|
|
343
|
+
import { buildSchema, type GraphQLSchema } from "graphql";
|
|
344
344
|
${hookImports.join("\n")}
|
|
345
345
|
|
|
346
346
|
const executor = getRemoteExecutor({
|
|
@@ -349,8 +349,18 @@ const executor = getRemoteExecutor({
|
|
|
349
349
|
hooks: [${hookRefs.join(", ")}],
|
|
350
350
|
});
|
|
351
351
|
|
|
352
|
+
// SDL is held as a string literal and only parsed on first access. This keeps
|
|
353
|
+
// \`buildSchema\` out of the module-evaluation phase, which matters on
|
|
354
|
+
// Cloudflare Workers where the startup CPU budget is ~200ms (free) / 400ms
|
|
355
|
+
// (paid) \u2014 easy to exceed when the remote schema is large (WPGraphQL +
|
|
356
|
+
// WooCommerce + ACF, etc.).
|
|
357
|
+
const SDL = ${JSON.stringify(sdl)};
|
|
358
|
+
let _schema: GraphQLSchema | undefined;
|
|
359
|
+
|
|
352
360
|
export const schema = {
|
|
353
|
-
schema:
|
|
361
|
+
get schema(): GraphQLSchema {
|
|
362
|
+
return (_schema ??= buildSchema(SDL));
|
|
363
|
+
},
|
|
354
364
|
executor,
|
|
355
365
|
};
|
|
356
366
|
`.trim();
|
|
@@ -374,20 +384,32 @@ function getSchemaTemplate({ localPaths, remotePaths }) {
|
|
|
374
384
|
schemaRefs.push(`mergeSchemas({ schemas: [${localSchemaRefs.join(", ")}] })`);
|
|
375
385
|
}
|
|
376
386
|
schemaRefs.push(...remoteSchemaRefs);
|
|
387
|
+
if (localPaths.length === 0 && remotePaths.length === 1) {
|
|
388
|
+
return [
|
|
389
|
+
...imports,
|
|
390
|
+
"",
|
|
391
|
+
`export const getSchema = () => remoteSchema0.schema;`,
|
|
392
|
+
`export const executor = remoteSchema0.executor;`
|
|
393
|
+
].join("\n");
|
|
394
|
+
}
|
|
377
395
|
let schemaRef;
|
|
378
396
|
if (schemaRefs.length === 0) {
|
|
379
|
-
imports.unshift(`import {
|
|
397
|
+
imports.unshift(`import { buildSchema, type GraphQLSchema } from "graphql";`);
|
|
380
398
|
schemaRef = `buildSchema("type Query { _empty: String }")`;
|
|
381
399
|
} else if (remoteSchemaRefs.length === 0) {
|
|
400
|
+
imports.unshift(`import type { GraphQLSchema } from "graphql";`);
|
|
382
401
|
schemaRef = schemaRefs[0];
|
|
383
402
|
} else {
|
|
384
403
|
imports.unshift(`import { stitchSchemas } from "@graphql-tools/stitch";`);
|
|
385
|
-
|
|
404
|
+
imports.unshift(`import type { GraphQLSchema } from "graphql";`);
|
|
405
|
+
schemaRef = `stitchSchemas({ subschemas: [${schemaRefs.join(", ")}], mergeTypes: false })`;
|
|
386
406
|
}
|
|
387
407
|
return [
|
|
388
408
|
...imports,
|
|
389
409
|
"",
|
|
390
|
-
`
|
|
410
|
+
`let _schema: GraphQLSchema | undefined;`,
|
|
411
|
+
`export const getSchema = () => (_schema ??= ${schemaRef});`,
|
|
412
|
+
`export const executor = undefined;`
|
|
391
413
|
].join("\n");
|
|
392
414
|
}
|
|
393
415
|
async function loadLocalSchema(path, nuxt) {
|
|
@@ -529,8 +551,10 @@ const module$1 = defineNuxtModule({
|
|
|
529
551
|
logger.warn("No GraphQL schemas loaded: using default empty schema.");
|
|
530
552
|
}
|
|
531
553
|
schema = buildSchema("type Query { _empty: String }");
|
|
554
|
+
} else if (schemas.length === 1) {
|
|
555
|
+
schema = schemas[0];
|
|
532
556
|
} else {
|
|
533
|
-
schema = stitchSchemas({ subschemas: schemas });
|
|
557
|
+
schema = stitchSchemas({ subschemas: schemas, mergeTypes: false });
|
|
534
558
|
if (!schema) {
|
|
535
559
|
throw new Error("Failed to load GraphQL schema");
|
|
536
560
|
}
|
|
@@ -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 {
|
|
1
|
+
import { executor, getSchema } 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: getSchema(),
|
|
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 {
|
|
2
|
+
import { executor, getSchema } from "#graphql/schema";
|
|
3
3
|
import { execute } from "graphql";
|
|
4
4
|
import { normalizeError } from "../../shared/utils/error.js";
|
|
5
5
|
import {
|
|
@@ -12,7 +12,18 @@ 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({
|
|
21
|
+
schema: getSchema(),
|
|
22
|
+
document,
|
|
23
|
+
variableValues,
|
|
24
|
+
operationName,
|
|
25
|
+
contextValue
|
|
26
|
+
});
|
|
16
27
|
if (result.errors?.length) {
|
|
17
28
|
return { data: null, error: normalizeError(result.errors) };
|
|
18
29
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lewebsimple/nuxt-graphql",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.10",
|
|
4
4
|
"description": "Opinionated Nuxt module for using GraphQL",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"repository": "lewebsimple/nuxt-graphql",
|
|
@@ -26,47 +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
|
-
"@nuxt/kit": "^4.4.
|
|
40
|
-
"defu": "^6.1.
|
|
41
|
-
"es-toolkit": "^1.
|
|
39
|
+
"@nuxt/kit": "^4.4.6",
|
|
40
|
+
"defu": "^6.1.7",
|
|
41
|
+
"es-toolkit": "^1.46.1",
|
|
42
42
|
"graphql-sse": "^2.6.0",
|
|
43
|
-
"graphql-yoga": "^5.
|
|
44
|
-
"jiti": "^2.
|
|
43
|
+
"graphql-yoga": "^5.21.0",
|
|
44
|
+
"jiti": "^2.7.0",
|
|
45
45
|
"ohash": "^2.0.11",
|
|
46
46
|
"picocolors": "^1.1.1",
|
|
47
47
|
"picomatch": "^4.0.4"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@graphql-codegen/plugin-helpers": "^
|
|
51
|
-
"@lewebsimple/graphql-codegen-zod": "^0.2.
|
|
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
|
+
"@lewebsimple/graphql-codegen-zod": "^0.2",
|
|
70
70
|
"graphql": "^16",
|
|
71
71
|
"zod": "^4"
|
|
72
72
|
},
|