@lewebsimple/nuxt-graphql 0.3.2 → 0.3.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.d.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
+ import { CacheConfig } from '../dist/runtime/app/lib/cache-config.js';
2
3
 
3
4
  /**
4
5
  * Find multiple files across directories
@@ -9,14 +10,6 @@ import * as _nuxt_schema from '@nuxt/schema';
9
10
  */
10
11
  type GlobPattern = string | string[];
11
12
 
12
- type CachePolicy = "no-cache" | "cache-first" | "network-first" | "swr";
13
- interface CacheConfig {
14
- cachePolicy: CachePolicy;
15
- cacheVersion: string;
16
- keyPrefix: string;
17
- ttl?: number;
18
- }
19
-
20
13
  type LocalSchemaDef = {
21
14
  type: "local";
22
15
  path: string;
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lewebsimple/nuxt-graphql",
3
3
  "configKey": "graphql",
4
- "version": "0.3.2",
4
+ "version": "0.3.4",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -4,6 +4,7 @@ import { existsSync, readFileSync, mkdirSync, writeFileSync } from 'node:fs';
4
4
  import { glob } from 'tinyglobby';
5
5
  import { generate } from '@graphql-codegen/cli';
6
6
  import { parse, Kind } from 'graphql';
7
+ import { resolveCacheConfig } from '../dist/runtime/app/lib/cache-config.js';
7
8
 
8
9
  function removeFileExtension(filePath) {
9
10
  return filePath.replace(/\.[^/.]+$/, "");
@@ -65,16 +66,6 @@ function toRelativePath(from, to) {
65
66
  return relativePath;
66
67
  }
67
68
 
68
- const defaultCacheConfig = {
69
- cachePolicy: "cache-first",
70
- cacheVersion: "1",
71
- keyPrefix: "gql",
72
- ttl: 60
73
- };
74
- function resolveCacheConfig(...overrides) {
75
- return Object.assign({}, defaultCacheConfig, ...overrides);
76
- }
77
-
78
69
  async function runGraphQLCodegen({ schema, documents, typedDocumentsPath, zodPath }) {
79
70
  const config = {
80
71
  schema,
@@ -215,6 +206,24 @@ function getRemoteExecMiddlewareProxy(middlewarePath) {
215
206
  ].join("\n");
216
207
  }
217
208
 
209
+ function getDummySchemaProxy() {
210
+ return [
211
+ `import { createSchema } from "graphql-yoga";`,
212
+ ``,
213
+ `export const schema = createSchema({`,
214
+ ` typeDefs: /* GraphQL */ \``,
215
+ ` type Query {`,
216
+ ` hello: String!`,
217
+ ` } `,
218
+ ` \`,`,
219
+ ` resolvers: {`,
220
+ ` Query: {`,
221
+ ` hello: () => "Hello world!",`,
222
+ ` },`,
223
+ ` },`,
224
+ `});`
225
+ ].join("\n");
226
+ }
218
227
  async function getLocalSchemaProxy({ layerRootDirs, schemaDef }) {
219
228
  const schemaPath = await findSingleFile(layerRootDirs, schemaDef.path, true);
220
229
  const content = [
@@ -329,26 +338,29 @@ const module$1 = defineNuxtModule({
329
338
  serverProxies["context"] = getGraphQLContextProxy(contextPath);
330
339
  serverProxies["remote-executor"] = getGenericServerProxy(resolve("./runtime/server/lib/remote-executor.ts"));
331
340
  if (Object.keys(options.schemas || {}).length === 0) {
332
- throw new Error("At least one GraphQL schema must be defined in the module options.");
333
- }
334
- for (const [schemaName, schemaDef] of Object.entries(options.schemas)) {
335
- switch (schemaDef.type) {
336
- case "local": {
337
- serverProxies[`schemas/${schemaName}`] = await getLocalSchemaProxy({ layerRootDirs, schemaDef });
338
- break;
339
- }
340
- case "remote": {
341
- const { middlewareContent, sdlContent, schemaContent } = await getRemoteSchemaProxy({ rootDir, schemaName, schemaDef });
342
- serverProxies[`schemas/${schemaName}-middleware`] = middlewareContent;
343
- serverProxies[`schemas/${schemaName}-sdl`] = sdlContent;
344
- serverProxies[`schemas/${schemaName}`] = schemaContent;
345
- break;
341
+ logger.warn("No GraphQL schemas defined in nuxt.config.ts, using dummy schema.");
342
+ serverProxies["schemas/dummy"] = getDummySchemaProxy();
343
+ serverProxies["schema"] = await getStitchedSchemaProxy({ schemaNames: ["dummy"] });
344
+ } else {
345
+ for (const [schemaName, schemaDef] of Object.entries(options.schemas)) {
346
+ switch (schemaDef.type) {
347
+ case "local": {
348
+ serverProxies[`schemas/${schemaName}`] = await getLocalSchemaProxy({ layerRootDirs, schemaDef });
349
+ break;
350
+ }
351
+ case "remote": {
352
+ const { middlewareContent, sdlContent, schemaContent } = await getRemoteSchemaProxy({ rootDir, schemaName, schemaDef });
353
+ serverProxies[`schemas/${schemaName}-middleware`] = middlewareContent;
354
+ serverProxies[`schemas/${schemaName}-sdl`] = sdlContent;
355
+ serverProxies[`schemas/${schemaName}`] = schemaContent;
356
+ break;
357
+ }
358
+ default:
359
+ throw new Error(`Unsupported GraphQL schema type: ${schemaDef.type}`);
346
360
  }
347
- default:
348
- throw new Error(`Unsupported GraphQL schema type: ${schemaDef.type}`);
349
361
  }
362
+ serverProxies["schema"] = await getStitchedSchemaProxy({ schemaNames: Object.keys(options.schemas) });
350
363
  }
351
- serverProxies["schema"] = await getStitchedSchemaProxy({ schemaNames: Object.keys(options.schemas) });
352
364
  if (options.middleware) {
353
365
  const yogaMiddlewarePath = await findSingleFile(layerRootDirs, options.middleware, true);
354
366
  logger.info(`GraphQL Yoga middleware registered: ${cyan}${toRelativePath(nuxt.options.rootDir, yogaMiddlewarePath)}${reset}`);
@@ -1,7 +1,7 @@
1
1
  import type { AsyncDataOptions } from "#app";
2
2
  import { useAsyncData, type MaybeRefOrGetter } from "#imports";
3
3
  import { type QueryName, type QueryResult, type QueryVariables } from "#graphql/registry";
4
- import { type CacheConfig } from "../../../helpers/cache-config.js";
4
+ import { type CacheConfig } from "../lib/cache-config.js";
5
5
  export interface UseGraphQLQueryOptions<T> extends AsyncDataOptions<T> {
6
6
  headers?: HeadersInit;
7
7
  cache?: CacheConfig;
@@ -1,6 +1,6 @@
1
1
  import { computed, toValue, useAsyncData, useNuxtApp, useNuxtData, useRuntimeConfig } from "#imports";
2
2
  import { queries } from "#graphql/registry";
3
- import { resolveCacheConfig } from "../../../helpers/cache-config";
3
+ import { resolveCacheConfig } from "../lib/cache-config.js";
4
4
  import { getCacheKeyParts, getInFlightRequests } from "../lib/graphql-cache.js";
5
5
  import { getPersistedEntry, setPersistedEntry } from "../lib/persisted.js";
6
6
  export function useGraphQLQuery(operationName, ...args) {
@@ -0,0 +1,8 @@
1
+ export type CachePolicy = "no-cache" | "cache-first" | "network-first" | "swr";
2
+ export interface CacheConfig {
3
+ cachePolicy: CachePolicy;
4
+ cacheVersion: string;
5
+ keyPrefix: string;
6
+ ttl?: number;
7
+ }
8
+ export declare function resolveCacheConfig(...overrides: Array<Partial<CacheConfig> | undefined>): CacheConfig;
@@ -0,0 +1,9 @@
1
+ const defaultCacheConfig = {
2
+ cachePolicy: "cache-first",
3
+ cacheVersion: "1",
4
+ keyPrefix: "gql",
5
+ ttl: 60
6
+ };
7
+ export function resolveCacheConfig(...overrides) {
8
+ return Object.assign({}, defaultCacheConfig, ...overrides);
9
+ }
@@ -1,4 +1,4 @@
1
- import type { CacheConfig } from "../../../helpers/cache-config.js";
1
+ import type { CacheConfig } from "./cache-config.js";
2
2
  export type CacheKeyParts = {
3
3
  key: string;
4
4
  opPrefix: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lewebsimple/nuxt-graphql",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "description": "Opinionated Nuxt module for using GraphQL",
5
5
  "repository": "lewebsimple/nuxt-graphql",
6
6
  "license": "MIT",