@lewebsimple/nuxt-graphql 0.5.8 → 0.5.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/README.md CHANGED
@@ -93,7 +93,7 @@ export default defineNuxtConfig({
93
93
 
94
94
  ### Define schema(s) (local and/or remote)
95
95
 
96
- **Local schemas** must live under `server/` and export a `GraphQLSchema` as `schema`. You can use the auto-imported `defineGraphQLSchema` helper for type-safety.
96
+ **Local schemas** must live under `server/` and export a `GraphQLSchema` as `schema`.
97
97
 
98
98
  For the example configuration above, create [server/graphql/schema.ts](server/graphql/schema.ts):
99
99
 
@@ -101,7 +101,7 @@ For the example configuration above, create [server/graphql/schema.ts](server/gr
101
101
  import { createSchema } from "graphql-yoga";
102
102
  import type { GraphQLContext } from "#graphql/context";
103
103
 
104
- const schema = createSchema<GraphQLContext>({
104
+ export const schema = createSchema<GraphQLContext>({
105
105
  typeDefs: /* GraphQL */ `
106
106
  type Query {
107
107
  hello: String!
@@ -132,8 +132,6 @@ const schema = createSchema<GraphQLContext>({
132
132
  },
133
133
  },
134
134
  });
135
-
136
- export default defineGraphQLSchema({ schema });
137
135
  ```
138
136
 
139
137
  **Remote schemas** are introspected at build time from the required endpoint URL and executed via an HTTP executor at runtime. Subscriptions are stripped from remote schemas.
@@ -165,9 +163,8 @@ Write operations in `.gql` files; operation names become registry keys like `use
165
163
 
166
164
  By default, the module scans `**/*.gql` and generates:
167
165
 
168
- - Typed documents and types in virtual modules under the `#graphql/operations` alias (internal)
166
+ - Typed documents and operations / fragments types in virtual modules under the `#graphql/operations` alias (internal)
169
167
  - Operation registry in virtual modules under the `#graphql/registry` alias (internal)
170
- - Fragment types in virtual modules under the `#graphql/fragments` alias
171
168
 
172
169
  Example document files:
173
170
 
@@ -200,7 +197,7 @@ That's it! You can now use Nuxt GraphQL in your Nuxt app ✨
200
197
  Fragments are fully supported and are the recommended way to share selection sets across operations.
201
198
 
202
199
  - Fragment names must be unique across all `.gql` files (duplicates throw during generation).
203
- - Fragment types are re-exported from `#graphql/fragments`.
200
+ - Fragment types are re-exported from `#graphql/operations`.
204
201
  - Fragments are not executable by themselves and are not part of the registry.
205
202
 
206
203
  Example with a fragment:
@@ -224,7 +221,7 @@ query SwapiFilms {
224
221
  From TypeScript, you can also use fragment types explicitly when needed:
225
222
 
226
223
  ```ts
227
- import type { TheFilmFragment } from "#graphql/fragments";
224
+ import type { TheFilmFragment } from "#graphql/operations";
228
225
  ```
229
226
 
230
227
 
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-graphql",
3
3
  "configKey": "graphql",
4
- "version": "0.5.8",
4
+ "version": "0.5.10",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -18,7 +18,7 @@ const cyan = "\x1B[36m";
18
18
  const reset = "\x1B[0m";
19
19
 
20
20
  function renderContextTemplate({ contextModules }) {
21
- const contextImports = contextModules.map((contextModule, index) => `import { createContext as createContext${index} } from '${contextModule}';`);
21
+ const contextImports = contextModules.map((contextModule, index) => `import createContext${index} from '${contextModule}';`);
22
22
  const contexts = contextModules.map((_, index) => `createContext${index}(event)`);
23
23
  return `
24
24
  ${contextImports.join("\n")}
@@ -29,7 +29,7 @@ export async function createContext(event) {
29
29
  }`.trim();
30
30
  }
31
31
  function renderContextTypesTemplate({ contextModules }) {
32
- const contextImports = contextModules.map((module, index) => `import { createContext as createContext${index} } from ${JSON.stringify(module)};`);
32
+ const contextImports = contextModules.map((module, index) => `import createContext${index} from ${JSON.stringify(module)};`);
33
33
  const contextTypes = ["{}", ...contextModules.map((_, index) => `Awaited<ReturnType<typeof createContext${index}>>`)];
34
34
  return `
35
35
  import type { H3Event } from "h3";
@@ -97,7 +97,7 @@ async function renderOperationsTemplate({ schema, documents }) {
97
97
  const module = docs.map(({ name, object }) => `export const ${name} = ${object};`).join("\n");
98
98
  const types = `${content.replace(/export const \w+ = [\s\S]*?;\n?/g, "")}
99
99
  declare module "#graphql/operations" {
100
- ${docs.map(({ name, type }) => `export type ${name} = ${type};`).join("\n ")}
100
+ ${docs.map(({ name, type }) => `export const ${name}: ${type};`).join("\n ")}
101
101
  }`.trim();
102
102
  return { module, types };
103
103
  }
@@ -305,7 +305,6 @@ export {};
305
305
  function renderSharedTypesTemplate() {
306
306
  return `
307
307
  import type { DocumentNode } from "graphql";
308
- import type { CacheConfig } from "nuxt-graphql/runtime/shared/lib/cache-config";
309
308
 
310
309
  declare global {
311
310
  type GraphQLCacheConfig = {
@@ -326,7 +325,6 @@ declare module "nuxt/schema" {
326
325
  }
327
326
 
328
327
  export { };
329
-
330
328
  `.trim();
331
329
  }
332
330
 
@@ -360,7 +358,7 @@ const module$1 = defineNuxtModule({
360
358
  return relativePath;
361
359
  }
362
360
  nuxt.options.alias ||= {};
363
- nuxt.options.alias["#graphql"] ||= resolveBuild("graphql");
361
+ nuxt.options.alias["#graphql"] = resolveBuild("graphql");
364
362
  const buildCache = /* @__PURE__ */ new Map();
365
363
  function cachedLoader(baseKey, loader) {
366
364
  return async (...args) => {
@@ -424,7 +422,9 @@ const module$1 = defineNuxtModule({
424
422
  "!**/dist/**",
425
423
  "!**/node_modules/**"
426
424
  ], { loaders: [new GraphQLFileLoader()] });
427
- } catch {
425
+ } catch (error) {
426
+ const message = error instanceof Error ? error.message : String(error);
427
+ logger.warn(`Failed to load documents: ${message}`);
428
428
  return [];
429
429
  }
430
430
  });
@@ -470,8 +470,11 @@ const module$1 = defineNuxtModule({
470
470
  nuxt.hook("builder:watch", async (_event, changedPath) => {
471
471
  if (changedPath.endsWith(".gql")) {
472
472
  logger.info(`Documents change detected: ${cyan}${getRelativePath(changedPath)}${reset}`);
473
- buildCache.delete("documents");
474
- buildCache.delete("operations");
473
+ for (const key of buildCache.keys()) {
474
+ if (key.startsWith("documents:") || key.startsWith("operations:") || key.startsWith("registry:")) {
475
+ buildCache.delete(key);
476
+ }
477
+ }
475
478
  }
476
479
  });
477
480
  }
@@ -1,7 +1,4 @@
1
1
  /**
2
- * Export the default schema definition wrapper.
2
+ * Default hello-world schema for development scaffolding.
3
3
  */
4
- declare const _default: {
5
- schema: import("graphql").GraphQLSchema | import("@graphql-tools/delegate").SubschemaConfig<any, any, any, Record<string, any>>;
6
- };
7
- export default _default;
4
+ export declare const schema: import("graphql-yoga").GraphQLSchemaWithContext<import("graphql-yoga").YogaInitialContext>;
@@ -1,6 +1,5 @@
1
1
  import { createSchema } from "graphql-yoga";
2
- import { defineGraphQLSchema } from "../utils/defineGraphQLSchema.js";
3
- const schema = createSchema({
2
+ export const schema = createSchema({
4
3
  typeDefs: (
5
4
  /* GraphQL */
6
5
  `
@@ -15,4 +14,3 @@ const schema = createSchema({
15
14
  }
16
15
  }
17
16
  });
18
- export default defineGraphQLSchema({ schema });
@@ -1,12 +1,6 @@
1
1
  import type { H3Event } from "h3";
2
- type GraphQLContextFactory<TContext extends Record<string, unknown>> = (event: H3Event) => TContext | Promise<TContext>;
2
+ export type GraphQLContextFactory<TContext extends Record<string, unknown>> = (event: H3Event) => TContext | Promise<TContext>;
3
3
  /**
4
4
  * Define a GraphQL context factory with proper typing.
5
- *
6
- * @param createContext Context factory function.
7
- * @returns The same factory, typed for inference.
8
5
  */
9
- export declare function defineGraphQLContext<TContext extends Record<string, unknown>>(createContext: GraphQLContextFactory<TContext>): {
10
- createContext: GraphQLContextFactory<TContext>;
11
- };
12
- export {};
6
+ export declare function defineGraphQLContext<TContext extends Record<string, unknown>>(createContext: GraphQLContextFactory<TContext>): GraphQLContextFactory<TContext>;
@@ -1,3 +1,3 @@
1
1
  export function defineGraphQLContext(createContext) {
2
- return { createContext };
2
+ return createContext;
3
3
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lewebsimple/nuxt-graphql",
3
- "version": "0.5.8",
3
+ "version": "0.5.10",
4
4
  "description": "Opinionated Nuxt module for using GraphQL",
5
5
  "repository": "lewebsimple/nuxt-graphql",
6
6
  "license": "AGPL-3.0-only",
@@ -1,14 +0,0 @@
1
- import type { GraphQLSchema } from "graphql";
2
- import type { SubschemaConfig } from "@graphql-tools/delegate";
3
- /**
4
- * Wrap a GraphQL schema or subschema config for module consumption.
5
- *
6
- * @param {{ schema: GraphQLSchema | SubschemaConfig }} options Schema wrapper input.
7
- * @param options.schema Local schema or subschema config.
8
- * @returns Wrapper object containing the schema.
9
- */
10
- export declare function defineGraphQLSchema({ schema }: {
11
- schema: GraphQLSchema | SubschemaConfig;
12
- }): {
13
- schema: GraphQLSchema | SubschemaConfig<any, any, any, Record<string, any>>;
14
- };
@@ -1,3 +0,0 @@
1
- export function defineGraphQLSchema({ schema }) {
2
- return { schema };
3
- }