@lewebsimple/nuxt-graphql 0.7.9 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-graphql",
3
3
  "configKey": "graphql",
4
- "version": "0.7.9",
4
+ "version": "0.7.10",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "unknown"
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.9";
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: buildSchema(${JSON.stringify(sdl)}),
361
+ get schema(): GraphQLSchema {
362
+ return (_schema ??= buildSchema(SDL));
363
+ },
354
364
  executor,
355
365
  };
356
366
  `.trim();
@@ -378,24 +388,27 @@ function getSchemaTemplate({ localPaths, remotePaths }) {
378
388
  return [
379
389
  ...imports,
380
390
  "",
381
- `export const schema = remoteSchema0.schema;`,
391
+ `export const getSchema = () => remoteSchema0.schema;`,
382
392
  `export const executor = remoteSchema0.executor;`
383
393
  ].join("\n");
384
394
  }
385
395
  let schemaRef;
386
396
  if (schemaRefs.length === 0) {
387
- imports.unshift(`import { buildSchema } from "graphql";`);
397
+ imports.unshift(`import { buildSchema, type GraphQLSchema } from "graphql";`);
388
398
  schemaRef = `buildSchema("type Query { _empty: String }")`;
389
399
  } else if (remoteSchemaRefs.length === 0) {
400
+ imports.unshift(`import type { GraphQLSchema } from "graphql";`);
390
401
  schemaRef = schemaRefs[0];
391
402
  } else {
392
403
  imports.unshift(`import { stitchSchemas } from "@graphql-tools/stitch";`);
404
+ imports.unshift(`import type { GraphQLSchema } from "graphql";`);
393
405
  schemaRef = `stitchSchemas({ subschemas: [${schemaRefs.join(", ")}], mergeTypes: false })`;
394
406
  }
395
407
  return [
396
408
  ...imports,
397
409
  "",
398
- `export const schema = ${schemaRef};`,
410
+ `let _schema: GraphQLSchema | undefined;`,
411
+ `export const getSchema = () => (_schema ??= ${schemaRef});`,
399
412
  `export const executor = undefined;`
400
413
  ].join("\n");
401
414
  }
@@ -1,4 +1,4 @@
1
- import { executor, schema } from "#graphql/schema";
1
+ import { executor, getSchema } from "#graphql/schema";
2
2
  import { createYoga } from "graphql-yoga";
3
3
  let yoga = null;
4
4
  function passthroughPlugin() {
@@ -21,7 +21,7 @@ export function getYogaInstance() {
21
21
  graphqlEndpoint: "/api/graphql",
22
22
  graphiql: import.meta.dev,
23
23
  fetchAPI: globalThis,
24
- schema,
24
+ schema: getSchema(),
25
25
  plugins: executor ? [passthroughPlugin()] : []
26
26
  });
27
27
  if (!yoga) {
@@ -1,5 +1,5 @@
1
1
  import { createContext } from "#graphql/context";
2
- import { executor, schema } from "#graphql/schema";
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 {
@@ -17,7 +17,13 @@ export async function executeSchemaOperation(event, { operationName, variables }
17
17
  variables: variableValues,
18
18
  operationName,
19
19
  context: contextValue
20
- }) : await execute({ schema, document, variableValues, operationName, contextValue });
20
+ }) : await execute({
21
+ schema: getSchema(),
22
+ document,
23
+ variableValues,
24
+ operationName,
25
+ contextValue
26
+ });
21
27
  if (result.errors?.length) {
22
28
  return { data: null, error: normalizeError(result.errors) };
23
29
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lewebsimple/nuxt-graphql",
3
- "version": "0.7.9",
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",