nitro-graphql 2.0.0-beta.15 → 2.0.0-beta.17
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,6 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as h31 from "h3";
|
|
2
2
|
|
|
3
3
|
//#region src/routes/apollo-server.d.ts
|
|
4
|
-
declare const _default:
|
|
4
|
+
declare const _default: h31.EventHandlerWithFetch<h31.EventHandlerRequest, Promise<any>>;
|
|
5
5
|
//#endregion
|
|
6
6
|
export { _default as default };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as h30 from "h3";
|
|
2
2
|
|
|
3
3
|
//#region src/routes/graphql-yoga.d.ts
|
|
4
|
-
declare const _default:
|
|
4
|
+
declare const _default: h30.EventHandlerWithFetch<h30.EventHandlerRequest, Promise<Response>>;
|
|
5
5
|
//#endregion
|
|
6
6
|
export { _default as default };
|
package/dist/routes/health.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as h35 from "h3";
|
|
2
2
|
|
|
3
3
|
//#region src/routes/health.d.ts
|
|
4
|
-
declare const _default:
|
|
4
|
+
declare const _default: h35.EventHandlerWithFetch<h35.EventHandlerRequest, Promise<{
|
|
5
5
|
status: string;
|
|
6
6
|
message: string;
|
|
7
7
|
timestamp: string;
|
package/dist/setup.js
CHANGED
|
@@ -93,7 +93,7 @@ async function setupNitroGraphQL(nitro) {
|
|
|
93
93
|
const watcher = watch(watchDirs, {
|
|
94
94
|
persistent: true,
|
|
95
95
|
ignoreInitial: true,
|
|
96
|
-
ignored: [...nitro.options.ignore, ...generateLayerIgnorePatterns(
|
|
96
|
+
ignored: [...nitro.options.ignore, ...generateLayerIgnorePatterns()]
|
|
97
97
|
}).on("all", async (_, path) => {
|
|
98
98
|
if (path.endsWith(".graphql") || path.endsWith(".gql")) if (path.includes(nitro.graphql.serverDir) || path.includes("server/graphql") || path.includes("server\\graphql")) {
|
|
99
99
|
await serverTypeGeneration(nitro);
|
|
@@ -218,16 +218,39 @@ async function setupNitroGraphQL(nitro) {
|
|
|
218
218
|
if (!rollupConfig$1.output.inlineDynamicImports) {
|
|
219
219
|
rollupConfig$1.output.manualChunks = (id, meta) => {
|
|
220
220
|
if (id.endsWith(".graphql") || id.endsWith(".gql")) return "schemas";
|
|
221
|
-
if (id.endsWith(".resolver.ts"))
|
|
221
|
+
if (id.endsWith(".resolver.ts")) {
|
|
222
|
+
let graphqlIndex = id.indexOf("server/graphql/");
|
|
223
|
+
let baseLength = 15;
|
|
224
|
+
if (graphqlIndex === -1) {
|
|
225
|
+
graphqlIndex = id.indexOf("routes/graphql/");
|
|
226
|
+
baseLength = 15;
|
|
227
|
+
}
|
|
228
|
+
if (graphqlIndex !== -1) return id.slice(graphqlIndex + baseLength).replace(/\.resolver\.ts$/, "");
|
|
229
|
+
return "resolvers";
|
|
230
|
+
}
|
|
222
231
|
if (typeof manualChunks === "function") return manualChunks(id, meta);
|
|
223
232
|
};
|
|
224
|
-
rollupConfig$1.output.advancedChunks = {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
233
|
+
rollupConfig$1.output.advancedChunks = {
|
|
234
|
+
groups: [{
|
|
235
|
+
name: "schemas",
|
|
236
|
+
test: /\.(?:graphql|gql)$/
|
|
237
|
+
}, {
|
|
238
|
+
name: (moduleId) => {
|
|
239
|
+
if (!moduleId.endsWith(".resolver.ts")) return;
|
|
240
|
+
let graphqlIndex = moduleId.indexOf("server/graphql/");
|
|
241
|
+
let baseLength = 15;
|
|
242
|
+
if (graphqlIndex === -1) {
|
|
243
|
+
graphqlIndex = moduleId.indexOf("routes/graphql/");
|
|
244
|
+
baseLength = 15;
|
|
245
|
+
}
|
|
246
|
+
if (graphqlIndex !== -1) return moduleId.slice(graphqlIndex + baseLength).replace(/\.resolver\.ts$/, "");
|
|
247
|
+
return "resolvers";
|
|
248
|
+
},
|
|
249
|
+
test: /\.resolver\.(?:ts|js)$/
|
|
250
|
+
}],
|
|
251
|
+
minSize: 0,
|
|
252
|
+
minShareCount: 1
|
|
253
|
+
};
|
|
231
254
|
}
|
|
232
255
|
rollupConfig$1.output.chunkFileNames = (chunkInfo) => {
|
|
233
256
|
if (chunkInfo.moduleIds && chunkInfo.moduleIds.some((id) => id.endsWith(".graphql") || id.endsWith(".resolver.ts") || id.endsWith(".gql"))) return `chunks/graphql/[name].mjs`;
|
|
@@ -293,7 +316,7 @@ export default <IGraphQLConfig> {
|
|
|
293
316
|
}`, "graphql.config.ts");
|
|
294
317
|
const serverSchemaPath = resolveFilePath(scaffoldConfig.serverSchema, scaffoldConfig.enabled, true, "{serverGraphql}/schema.ts", placeholders);
|
|
295
318
|
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);
|
|
319
|
+
const serverContextPath = resolveFilePath(scaffoldConfig.serverContext, scaffoldConfig.enabled, true, "{serverGraphql}/context.d.ts", placeholders);
|
|
297
320
|
if (serverSchemaPath || serverConfigPath || serverContextPath) {
|
|
298
321
|
if (!existsSync(nitro.graphql.serverDir)) mkdirSync(nitro.graphql.serverDir, { recursive: true });
|
|
299
322
|
}
|
|
@@ -321,7 +344,7 @@ export default defineGraphQLConfig({
|
|
|
321
344
|
if (serverContextPath) writeFileIfNotExists(serverContextPath, `// Example context definition - please change it to your needs
|
|
322
345
|
// import type { Database } from '../utils/useDb'
|
|
323
346
|
|
|
324
|
-
declare module 'h3' {
|
|
347
|
+
declare module 'nitro/h3' {
|
|
325
348
|
interface H3EventContext {
|
|
326
349
|
// Add your custom context properties here
|
|
327
350
|
// useDatabase: () => Database
|
|
@@ -333,10 +356,13 @@ declare module 'h3' {
|
|
|
333
356
|
// }
|
|
334
357
|
// }
|
|
335
358
|
}
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
export {}
|
|
362
|
+
`, "server context.d.ts");
|
|
363
|
+
if (existsSync(join(nitro.graphql.serverDir, "context.ts"))) {
|
|
364
|
+
consola.warn("nitro-graphql: Found context.ts file. Please rename it to context.d.ts for type-only definitions.");
|
|
365
|
+
consola.info("The context file should now be context.d.ts instead of context.ts");
|
|
340
366
|
}
|
|
341
367
|
} else consola.info("[nitro-graphql] Scaffold file generation is disabled (library mode)");
|
|
342
368
|
}
|
|
@@ -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
|
};
|