nitro-graphql 2.0.0-beta.15 → 2.0.0-beta.16

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.
@@ -1,4 +1,4 @@
1
- import * as h33 from "h3";
1
+ import * as h35 from "h3";
2
2
 
3
3
  //#region src/routes/debug.d.ts
4
4
 
@@ -10,7 +10,7 @@ import * as h33 from "h3";
10
10
  * - /_nitro/graphql/debug - HTML dashboard
11
11
  * - /_nitro/graphql/debug?format=json - JSON API
12
12
  */
13
- declare const _default: h33.EventHandlerWithFetch<h33.EventHandlerRequest, Promise<string | {
13
+ declare const _default: h35.EventHandlerWithFetch<h35.EventHandlerRequest, Promise<string | {
14
14
  timestamp: string;
15
15
  environment: {
16
16
  dev: any;
@@ -1,6 +1,6 @@
1
- import * as h35 from "h3";
1
+ import * as h33 from "h3";
2
2
 
3
3
  //#region src/routes/graphql-yoga.d.ts
4
- declare const _default: h35.EventHandlerWithFetch<h35.EventHandlerRequest, Promise<Response>>;
4
+ declare const _default: h33.EventHandlerWithFetch<h33.EventHandlerRequest, Promise<Response>>;
5
5
  //#endregion
6
6
  export { _default as default };
package/dist/setup.js CHANGED
@@ -293,7 +293,7 @@ export default <IGraphQLConfig> {
293
293
  }`, "graphql.config.ts");
294
294
  const serverSchemaPath = resolveFilePath(scaffoldConfig.serverSchema, scaffoldConfig.enabled, true, "{serverGraphql}/schema.ts", placeholders);
295
295
  const serverConfigPath = resolveFilePath(scaffoldConfig.serverConfig, scaffoldConfig.enabled, true, "{serverGraphql}/config.ts", placeholders);
296
- const serverContextPath = resolveFilePath(scaffoldConfig.serverContext, scaffoldConfig.enabled, true, "{serverGraphql}/context.ts", placeholders);
296
+ const serverContextPath = resolveFilePath(scaffoldConfig.serverContext, scaffoldConfig.enabled, true, "{serverGraphql}/context.d.ts", placeholders);
297
297
  if (serverSchemaPath || serverConfigPath || serverContextPath) {
298
298
  if (!existsSync(nitro.graphql.serverDir)) mkdirSync(nitro.graphql.serverDir, { recursive: true });
299
299
  }
@@ -321,7 +321,7 @@ export default defineGraphQLConfig({
321
321
  if (serverContextPath) writeFileIfNotExists(serverContextPath, `// Example context definition - please change it to your needs
322
322
  // import type { Database } from '../utils/useDb'
323
323
 
324
- declare module 'h3' {
324
+ declare module 'nitro/h3' {
325
325
  interface H3EventContext {
326
326
  // Add your custom context properties here
327
327
  // useDatabase: () => Database
@@ -333,10 +333,13 @@ declare module 'h3' {
333
333
  // }
334
334
  // }
335
335
  }
336
- }`, "server context.ts");
337
- if (existsSync(join(nitro.graphql.serverDir, "context.d.ts"))) {
338
- consola.warn("nitro-graphql: Found context.d.ts file. Please rename it to context.ts for the new structure.");
339
- consola.info("The context file should now be context.ts instead of context.d.ts");
336
+ }
337
+
338
+ export {}
339
+ `, "server context.d.ts");
340
+ if (existsSync(join(nitro.graphql.serverDir, "context.ts"))) {
341
+ consola.warn("nitro-graphql: Found context.ts file. Please rename it to context.d.ts for type-only definitions.");
342
+ consola.info("The context file should now be context.d.ts instead of context.ts");
340
343
  }
341
344
  } else consola.info("[nitro-graphql] Scaffold file generation is disabled (library mode)");
342
345
  }
@@ -37,7 +37,7 @@ async function generateTypes(selectFremework, schema, config = {}, outputPath) {
37
37
  },
38
38
  defaultScalarType: "unknown",
39
39
  defaultMapper: `ResolverReturnType<{T}>`,
40
- contextType: "h3#H3Event",
40
+ contextType: "nitro/h3#H3Event",
41
41
  maybeValue: "T | null | undefined",
42
42
  inputMaybeValue: "T | undefined",
43
43
  declarationKind: "interface",
@@ -45,7 +45,7 @@ function generateNuxtOfetchClient(nitro, clientDir, serviceName = "default") {
45
45
  const serviceDir = dirname(ofetchPath);
46
46
  if (!existsSync(serviceDir)) mkdirSync(serviceDir, { recursive: true });
47
47
  if (existsSync(ofetchPath)) return;
48
- writeFileIfNotExists(ofetchPath, `// This file is auto-generated once by nitro-graphql for quick start
48
+ writeFileIfNotExists(ofetchPath, nitro.options.framework?.name === "nuxt" ? `// This file is auto-generated once by nitro-graphql for quick start
49
49
  // You can modify this file according to your needs
50
50
  import type { Requester } from './sdk'
51
51
  import { getSdk } from './sdk'
@@ -67,6 +67,26 @@ export function createGraphQLClient(endpoint: string): Requester {
67
67
  }
68
68
  }
69
69
 
70
+ export const $sdk = getSdk(createGraphQLClient('/api/graphql'))` : `// This file is auto-generated once by nitro-graphql for quick start
71
+ // You can modify this file according to your needs
72
+ import type { Requester } from './sdk'
73
+ import { ofetch } from 'ofetch'
74
+ import { getSdk } from './sdk'
75
+
76
+ export function createGraphQLClient(endpoint: string): Requester {
77
+ return async <R>(doc: string, vars?: any): Promise<R> => {
78
+ const result = await ofetch(endpoint, {
79
+ method: 'POST',
80
+ body: { query: doc, variables: vars },
81
+ headers: {
82
+ 'Content-Type': 'application/json',
83
+ },
84
+ })
85
+
86
+ return result as R
87
+ }
88
+ }
89
+
70
90
  export const $sdk = getSdk(createGraphQLClient('/api/graphql'))`, `${serviceName} ofetch.ts`);
71
91
  }
72
92
  function generateExternalOfetchClient(nitro, service, endpoint) {
@@ -83,7 +103,7 @@ function generateExternalOfetchClient(nitro, service, endpoint) {
83
103
  if (!existsSync(serviceDir)) mkdirSync(serviceDir, { recursive: true });
84
104
  if (!existsSync(ofetchPath)) {
85
105
  const capitalizedServiceName = serviceName.charAt(0).toUpperCase() + serviceName.slice(1);
86
- writeFileIfNotExists(ofetchPath, `// This file is auto-generated once by nitro-graphql for quick start
106
+ writeFileIfNotExists(ofetchPath, nitro.options.framework?.name === "nuxt" ? `// This file is auto-generated once by nitro-graphql for quick start
87
107
  // You can modify this file according to your needs
88
108
  import type { Sdk, Requester } from './sdk'
89
109
  import { getSdk } from './sdk'
@@ -105,6 +125,26 @@ export function create${capitalizedServiceName}GraphQLClient(endpoint: string =
105
125
  }
106
126
  }
107
127
 
128
+ export const $${serviceName}Sdk: Sdk = getSdk(create${capitalizedServiceName}GraphQLClient())` : `// This file is auto-generated once by nitro-graphql for quick start
129
+ // You can modify this file according to your needs
130
+ import type { Sdk, Requester } from './sdk'
131
+ import { ofetch } from 'ofetch'
132
+ import { getSdk } from './sdk'
133
+
134
+ export function create${capitalizedServiceName}GraphQLClient(endpoint: string = '${endpoint}'): Requester {
135
+ return async <R>(doc: string, vars?: any): Promise<R> => {
136
+ const result = await ofetch(endpoint, {
137
+ method: 'POST',
138
+ body: { query: doc, variables: vars },
139
+ headers: {
140
+ 'Content-Type': 'application/json',
141
+ },
142
+ })
143
+
144
+ return result as R
145
+ }
146
+ }
147
+
108
148
  export const $${serviceName}Sdk: Sdk = getSdk(create${capitalizedServiceName}GraphQLClient())`, `${serviceName} external ofetch.ts`);
109
149
  }
110
150
  }
package/dist/vite.js CHANGED
@@ -38,6 +38,8 @@ function graphql(options) {
38
38
  },
39
39
  nitro: { async setup(nitro) {
40
40
  if (options) nitro.options.graphql = defu(nitro.options.graphql || {}, options);
41
+ nitro.options.graphql = nitro.options.graphql || {};
42
+ nitro.options.graphql._vitePlugin = true;
41
43
  await setupNitroGraphQL(nitro);
42
44
  } }
43
45
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nitro-graphql",
3
3
  "type": "module",
4
- "version": "2.0.0-beta.15",
4
+ "version": "2.0.0-beta.16",
5
5
  "description": "GraphQL integration for Nitro",
6
6
  "license": "MIT",
7
7
  "sideEffects": false,