nitro-graphql 0.0.1 → 0.0.3
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 +14 -14
- package/dist/{client-codegen-DM2n5Gt2.js → client-codegen.js} +1 -2
- package/dist/client-watcher.d.ts +2 -5
- package/dist/client-watcher.js +36 -28
- package/dist/codegen.d.ts +12 -1
- package/dist/codegen.js +107 -1
- package/dist/context.d.ts +9 -1
- package/dist/context.js +0 -1
- package/dist/dev.js +95 -0
- package/dist/index.d.ts +12 -8
- package/dist/index.js +67 -329
- package/dist/prerender.js +279 -0
- package/dist/{scanner-BdcKEPQk.js → scanner.js} +4 -5
- package/dist/{types-D_NqyCcy.d.ts → types.d.ts} +2 -11
- package/dist/utils.d.ts +13 -3
- package/dist/utils.js +22 -2
- package/package.json +9 -4
- package/dist/client-codegen-DM2n5Gt2.js.map +0 -1
- package/dist/client-watcher.d.ts.map +0 -1
- package/dist/client-watcher.js.map +0 -1
- package/dist/codegen-DWJuLowd.d.ts +0 -16
- package/dist/codegen-DWJuLowd.d.ts.map +0 -1
- package/dist/codegen-Dbw6gEZt.js +0 -110
- package/dist/codegen-Dbw6gEZt.js.map +0 -1
- package/dist/context-BgqNJFCT.d.ts +0 -13
- package/dist/context-BgqNJFCT.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/scanner-BdcKEPQk.js.map +0 -1
- package/dist/types-D_NqyCcy.d.ts.map +0 -1
- package/dist/utils-87_22aIA.js +0 -41
- package/dist/utils-87_22aIA.js.map +0 -1
- package/dist/utils-BuYDOLIi.d.ts +0 -22
- package/dist/utils-BuYDOLIi.d.ts.map +0 -1
- package/dist/watcher.d.ts +0 -9
- package/dist/watcher.d.ts.map +0 -1
- package/dist/watcher.js +0 -96
- package/dist/watcher.js.map +0 -1
- /package/dist/{context-CZdhkJYD.js → types.js} +0 -0
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { scanGraphQLFiles } from "./scanner.js";
|
|
2
|
+
import { generateTypes } from "./codegen.js";
|
|
3
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
4
|
+
import { mergeTypeDefs } from "@graphql-tools/merge";
|
|
5
|
+
import { makeExecutableSchema } from "@graphql-tools/schema";
|
|
6
|
+
import { consola } from "consola";
|
|
7
|
+
import { join } from "pathe";
|
|
8
|
+
|
|
9
|
+
//#region src/prerender.ts
|
|
10
|
+
const logger = consola.withTag("graphql");
|
|
11
|
+
async function prerender(nitro, options) {
|
|
12
|
+
const scanResult = await scanGraphQLFiles(nitro);
|
|
13
|
+
if (scanResult.resolvers.length > 0) logger.success(`Found ${scanResult.resolvers.length} resolvers`);
|
|
14
|
+
if (scanResult.typeDefs.length > 0) {
|
|
15
|
+
const mergedTypeDefs = mergeTypeDefs(scanResult.typeDefs);
|
|
16
|
+
const schema = makeExecutableSchema({
|
|
17
|
+
typeDefs: mergedTypeDefs,
|
|
18
|
+
resolvers: {}
|
|
19
|
+
});
|
|
20
|
+
const generatedTypes = await generateTypes(schema);
|
|
21
|
+
const outputPath = join(nitro.options.buildDir, "types", "graphql-types.generated.ts");
|
|
22
|
+
const typesDir = join(nitro.options.buildDir, "types");
|
|
23
|
+
await mkdir(typesDir, { recursive: true });
|
|
24
|
+
await writeFile(outputPath, generatedTypes);
|
|
25
|
+
const graphqlDtsPath = join(typesDir, "graphql.d.ts");
|
|
26
|
+
const graphqlDtsContent = `// Auto-generated by nitro-graphql
|
|
27
|
+
import type { Resolvers as Test } from './graphql-types.generated'
|
|
28
|
+
|
|
29
|
+
declare module 'nitro-graphql/types' {
|
|
30
|
+
interface Resolvers extends Test {}
|
|
31
|
+
}
|
|
32
|
+
`;
|
|
33
|
+
await writeFile(graphqlDtsPath, graphqlDtsContent);
|
|
34
|
+
logger.success("Types generated");
|
|
35
|
+
} else {
|
|
36
|
+
const typesDir = join(nitro.options.buildDir, "types");
|
|
37
|
+
await mkdir(typesDir, { recursive: true });
|
|
38
|
+
const minimalTypes = `// Generated by nitro-graphql (no schema found)
|
|
39
|
+
export type Resolvers = any
|
|
40
|
+
`;
|
|
41
|
+
const outputPath = join(typesDir, "graphql-types.generated.ts");
|
|
42
|
+
await writeFile(outputPath, minimalTypes);
|
|
43
|
+
const graphqlDtsPath = join(typesDir, "graphql.d.ts");
|
|
44
|
+
const graphqlDtsContent = `// Auto-generated by nitro-graphql
|
|
45
|
+
import type { Resolvers as Test } from './graphql-types.generated'
|
|
46
|
+
|
|
47
|
+
declare module 'nitro-graphql/types' {
|
|
48
|
+
interface Resolvers extends Test {}
|
|
49
|
+
}
|
|
50
|
+
`;
|
|
51
|
+
await writeFile(graphqlDtsPath, graphqlDtsContent);
|
|
52
|
+
logger.info("Created minimal types (no schema found)");
|
|
53
|
+
}
|
|
54
|
+
nitro.options.virtual["#nitro-graphql/handler"] = () => `
|
|
55
|
+
import { createYoga } from 'graphql-yoga'
|
|
56
|
+
import { defineEventHandler, readRawBody, setHeader, setResponseStatus } from 'h3'
|
|
57
|
+
import { useStorage } from 'nitro/runtime'
|
|
58
|
+
import { makeExecutableSchema } from '@graphql-tools/schema'
|
|
59
|
+
import { mergeTypeDefs, mergeResolvers } from '@graphql-tools/merge'
|
|
60
|
+
import { join } from 'pathe'
|
|
61
|
+
// Types are generated at build time to .nitro/graphql-types.generated.ts
|
|
62
|
+
|
|
63
|
+
// GraphQL Context type is injected via context module
|
|
64
|
+
|
|
65
|
+
// Create resolver helper
|
|
66
|
+
globalThis.defineResolver = function(resolvers) {
|
|
67
|
+
return resolvers
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Dynamic schema loading function
|
|
71
|
+
async function loadTypeDefs() {
|
|
72
|
+
const schemaPath = join('${nitro.options.srcDir}', 'graphql', '**', '*.graphql')
|
|
73
|
+
const { loadFilesSync } = await import('@graphql-tools/load-files')
|
|
74
|
+
return loadFilesSync(schemaPath, {
|
|
75
|
+
recursive: true,
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Load resolvers using dynamic imports (Nitro handles the bundling)
|
|
80
|
+
const resolverImports = [
|
|
81
|
+
${scanResult.resolvers.map((resolver) => ` () => import('${resolver.path}')`).join(",\n")}
|
|
82
|
+
]
|
|
83
|
+
|
|
84
|
+
// Async function to load resolvers
|
|
85
|
+
async function loadResolvers() {
|
|
86
|
+
let resolvers = {}
|
|
87
|
+
try {
|
|
88
|
+
if (resolverImports.length > 0) {
|
|
89
|
+
const resolverModules = []
|
|
90
|
+
|
|
91
|
+
for (let i = 0; i < resolverImports.length; i++) {
|
|
92
|
+
try {
|
|
93
|
+
const resolverModule = await resolverImports[i]()
|
|
94
|
+
const resolver = resolverModule.default || resolverModule
|
|
95
|
+
|
|
96
|
+
if (resolver) {
|
|
97
|
+
resolverModules.push(resolver)
|
|
98
|
+
}
|
|
99
|
+
} catch (error) {
|
|
100
|
+
console.warn('[graphql] Failed to load resolver:', i, error.message)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (resolverModules.length > 0) {
|
|
105
|
+
resolvers = mergeResolvers(resolverModules)
|
|
106
|
+
} else {
|
|
107
|
+
console.warn('[graphql] No resolvers could be loaded')
|
|
108
|
+
resolvers = { Query: {}, Mutation: {} }
|
|
109
|
+
}
|
|
110
|
+
} else {
|
|
111
|
+
console.warn('[graphql] No resolvers found')
|
|
112
|
+
resolvers = { Query: {}, Mutation: {} }
|
|
113
|
+
}
|
|
114
|
+
} catch (error) {
|
|
115
|
+
console.warn('[graphql] Error loading resolvers:', error.message)
|
|
116
|
+
resolvers = { Query: {}, Mutation: {} }
|
|
117
|
+
}
|
|
118
|
+
return resolvers
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Apollo Sandbox HTML with 1 week cache
|
|
122
|
+
const apolloSandboxHtml = \`<!DOCTYPE html>
|
|
123
|
+
<html lang="en">
|
|
124
|
+
<body style="margin: 0; overflow-x: hidden; overflow-y: hidden">
|
|
125
|
+
<div id="sandbox" style="height:100vh; width:100vw;"></div>
|
|
126
|
+
<script src="https://embeddable-sandbox.cdn.apollographql.com/02e2da0fccbe0240ef03d2396d6c98559bab5b06/embeddable-sandbox.umd.production.min.js"><\/script>
|
|
127
|
+
<script>
|
|
128
|
+
new window.EmbeddedSandbox({
|
|
129
|
+
target: "#sandbox",
|
|
130
|
+
initialEndpoint: window.location.href,
|
|
131
|
+
hideCookieToggle: false,
|
|
132
|
+
initialState: {
|
|
133
|
+
includeCookies: true
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
<\/script>
|
|
137
|
+
</body>
|
|
138
|
+
</html>\`
|
|
139
|
+
|
|
140
|
+
// Set cache headers for Apollo Sandbox HTML (1 week = 604800 seconds)
|
|
141
|
+
function setApolloSandboxCacheHeaders(event) {
|
|
142
|
+
setHeader(event, 'Cache-Control', 'public, max-age=604800, s-maxage=604800')
|
|
143
|
+
setHeader(event, 'Expires', new Date(Date.now() + 604800000).toUTCString())
|
|
144
|
+
setHeader(event, 'ETag', \`"apollo-sandbox-\${Date.now()}"\`)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Lazy initialization
|
|
148
|
+
let yoga = null
|
|
149
|
+
let initPromise = null
|
|
150
|
+
|
|
151
|
+
async function getYoga() {
|
|
152
|
+
// In development mode, always reload schema for hot updates
|
|
153
|
+
const isDev = ${nitro.options.dev}
|
|
154
|
+
if (yoga && !isDev) return yoga
|
|
155
|
+
|
|
156
|
+
if (!initPromise || isDev) {
|
|
157
|
+
// Reset yoga instance in development mode
|
|
158
|
+
if (isDev) {
|
|
159
|
+
yoga = null
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
initPromise = (async () => {
|
|
163
|
+
// Load custom yoga config first (separate from resolvers)
|
|
164
|
+
let customYogaConfig = {}
|
|
165
|
+
${scanResult.yogaConfigPath ? `
|
|
166
|
+
try {
|
|
167
|
+
const yogaConfigModule = await import('${scanResult.yogaConfigPath}')
|
|
168
|
+
customYogaConfig = yogaConfigModule.default || yogaConfigModule
|
|
169
|
+
} catch (error) {
|
|
170
|
+
console.warn('[graphql] Failed to load yoga config:', error.message)
|
|
171
|
+
}` : ""}
|
|
172
|
+
|
|
173
|
+
const resolvers = await loadResolvers()
|
|
174
|
+
const typeDefs = await loadTypeDefs()
|
|
175
|
+
|
|
176
|
+
// Merge schema and resolvers (without yoga config interfering)
|
|
177
|
+
const schema = makeExecutableSchema({
|
|
178
|
+
typeDefs: mergeTypeDefs(typeDefs),
|
|
179
|
+
resolvers,
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
// Default yoga configuration
|
|
183
|
+
const defaultYogaConfig = {
|
|
184
|
+
schema,
|
|
185
|
+
context: async ({ request }) => {
|
|
186
|
+
const event = request.$$event
|
|
187
|
+
return {
|
|
188
|
+
event,
|
|
189
|
+
request,
|
|
190
|
+
storage: useStorage(),
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
graphqlEndpoint: '${options.endpoint || "/api/graphql"}',
|
|
194
|
+
graphiql: ${options.playground !== false},
|
|
195
|
+
renderGraphiQL: () => apolloSandboxHtml,
|
|
196
|
+
landingPage: false,
|
|
197
|
+
cors: ${JSON.stringify(options.cors || false)},
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Clean up custom config (remove properties that could be mistaken for GraphQL resolvers)
|
|
201
|
+
const cleanCustomConfig = { ...customYogaConfig }
|
|
202
|
+
|
|
203
|
+
// Remove empty arrays and functions that GraphQL Tools might confuse with resolvers
|
|
204
|
+
if (Array.isArray(cleanCustomConfig.plugins) && cleanCustomConfig.plugins.length === 0) {
|
|
205
|
+
delete cleanCustomConfig.plugins
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Remove these yoga-specific configs from resolver merging
|
|
209
|
+
const yogaOnlyConfigs = ['context', 'plugins', 'maskedErrors', 'graphiql', 'cors']
|
|
210
|
+
const cleanResolverConfig = { ...cleanCustomConfig }
|
|
211
|
+
yogaOnlyConfigs.forEach(key => {
|
|
212
|
+
delete cleanResolverConfig[key]
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
// Merge custom config with defaults
|
|
216
|
+
const yogaConfig = {
|
|
217
|
+
...defaultYogaConfig,
|
|
218
|
+
...cleanCustomConfig,
|
|
219
|
+
// Always override schema and endpoint from default config
|
|
220
|
+
schema,
|
|
221
|
+
graphqlEndpoint: '${options.endpoint || "/api/graphql"}',
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
yoga = createYoga(yogaConfig)
|
|
225
|
+
|
|
226
|
+
return yoga
|
|
227
|
+
})()
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return initPromise
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export default defineEventHandler(async (event) => {
|
|
234
|
+
const { req } = event.node
|
|
235
|
+
const host = req.headers.host || 'localhost'
|
|
236
|
+
const protocol = 'http'
|
|
237
|
+
const url = new URL(req.url || '/', protocol + '://' + host)
|
|
238
|
+
|
|
239
|
+
// Attach event to request for context
|
|
240
|
+
req.$$event = event
|
|
241
|
+
|
|
242
|
+
const yogaInstance = await getYoga()
|
|
243
|
+
const response = await yogaInstance.fetch(url.toString(), {
|
|
244
|
+
method: req.method || 'GET',
|
|
245
|
+
headers: req.headers,
|
|
246
|
+
body: req.method !== 'GET' && req.method !== 'HEAD' ? await readRawBody(event) : undefined,
|
|
247
|
+
}, {
|
|
248
|
+
event,
|
|
249
|
+
})
|
|
250
|
+
|
|
251
|
+
// Set response headers
|
|
252
|
+
response.headers.forEach((value, key) => {
|
|
253
|
+
setHeader(event, key, value)
|
|
254
|
+
})
|
|
255
|
+
|
|
256
|
+
// Set status code
|
|
257
|
+
setResponseStatus(event, response.status)
|
|
258
|
+
|
|
259
|
+
// Return response body
|
|
260
|
+
if (response.body) {
|
|
261
|
+
const contentType = response.headers.get('content-type')
|
|
262
|
+
if (contentType?.includes('text/html')) {
|
|
263
|
+
// Set cache headers for Apollo Sandbox HTML
|
|
264
|
+
setApolloSandboxCacheHeaders(event)
|
|
265
|
+
return await response.text()
|
|
266
|
+
}
|
|
267
|
+
if (contentType?.includes('application/json')) {
|
|
268
|
+
return await response.text()
|
|
269
|
+
}
|
|
270
|
+
return response.body
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
return null
|
|
274
|
+
})
|
|
275
|
+
`;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
//#endregion
|
|
279
|
+
export { prerender };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { consola } from "consola";
|
|
2
2
|
import { basename, join, relative } from "pathe";
|
|
3
3
|
import { existsSync, readFileSync } from "node:fs";
|
|
4
|
-
import {
|
|
4
|
+
import { glob } from "tinyglobby";
|
|
5
5
|
|
|
6
6
|
//#region src/scanner.ts
|
|
7
7
|
async function scanGraphQLFiles(nitro) {
|
|
@@ -34,7 +34,7 @@ async function scanResolverFiles(nitro) {
|
|
|
34
34
|
const resolverFiles = await Promise.all(nitro.options.scanDirs.map(async (scanDir) => {
|
|
35
35
|
const graphqlDir = join(scanDir, "graphql");
|
|
36
36
|
if (!existsSync(graphqlDir)) return [];
|
|
37
|
-
return
|
|
37
|
+
return glob([
|
|
38
38
|
join(graphqlDir, NITRO_GLOB_PATTERN),
|
|
39
39
|
`!${join(graphqlDir, "**/*.d.ts")}`,
|
|
40
40
|
`!${join(graphqlDir, "**/*.test.*")}`,
|
|
@@ -69,7 +69,7 @@ async function scanGraphQLFilesWithResolvers(nitro) {
|
|
|
69
69
|
const graphqlFiles = await Promise.all(nitro.options.scanDirs.map(async (scanDir) => {
|
|
70
70
|
const graphqlDir = join(scanDir, "graphql");
|
|
71
71
|
if (!existsSync(graphqlDir)) return [];
|
|
72
|
-
return
|
|
72
|
+
return glob([join(graphqlDir, "**/*.graphql"), join(graphqlDir, "**/*.gql")], {
|
|
73
73
|
cwd: scanDir,
|
|
74
74
|
dot: true,
|
|
75
75
|
ignore: nitro.options.ignore || [],
|
|
@@ -115,5 +115,4 @@ async function scanForYogaConfig(nitro) {
|
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
//#endregion
|
|
118
|
-
export { scanGraphQLFiles };
|
|
119
|
-
//# sourceMappingURL=scanner-BdcKEPQk.js.map
|
|
118
|
+
export { scanGraphQLFiles };
|
|
@@ -28,20 +28,11 @@ interface NitroGraphQLOptions {
|
|
|
28
28
|
enabled?: boolean;
|
|
29
29
|
outputPath?: string;
|
|
30
30
|
watchPatterns?: string[];
|
|
31
|
+
nuxtPatterns?: string[];
|
|
31
32
|
config?: CodegenClientConfig;
|
|
32
33
|
};
|
|
33
34
|
yogaConfig?: Partial<YogaServerOptions<any, any>>;
|
|
34
35
|
}
|
|
35
|
-
declare module 'nitropack' {
|
|
36
|
-
interface NitroOptions {
|
|
37
|
-
graphqlYoga?: NitroGraphQLOptions;
|
|
38
|
-
}
|
|
39
|
-
interface NitroRuntimeConfig {
|
|
40
|
-
graphqlYoga?: NitroGraphQLOptions;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
36
|
interface Resolvers {}
|
|
44
|
-
//# sourceMappingURL=types.d.ts.map
|
|
45
37
|
//#endregion
|
|
46
|
-
export { CodegenClientConfig, GraphQLSchemaConfig, NitroGraphQLOptions, Resolvers };
|
|
47
|
-
//# sourceMappingURL=types-D_NqyCcy.d.ts.map
|
|
38
|
+
export { CodegenClientConfig, GraphQLSchemaConfig, NitroGraphQLOptions, Resolvers };
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
-
import "
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { YogaServerOptions } from "graphql-yoga";
|
|
2
|
+
import { GraphQLSchemaConfig, Resolvers } from "nitro-graphql/types";
|
|
3
|
+
|
|
4
|
+
//#region src/utils.d.ts
|
|
5
|
+
declare function defineGraphQLSchema(config: GraphQLSchemaConfig): GraphQLSchemaConfig;
|
|
6
|
+
declare function defineResolver(resolvers: Resolvers): Resolvers;
|
|
7
|
+
/**
|
|
8
|
+
* Helper function to define GraphQL Yoga configuration with type safety
|
|
9
|
+
*/
|
|
10
|
+
declare function defineYogaConfig<TServerContext = any, TUserContext = any>(config: Partial<YogaServerOptions<TServerContext, TUserContext>>): Partial<YogaServerOptions<TServerContext, TUserContext>>;
|
|
11
|
+
declare function relativeWithDot(from: string, to: string): string;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { defineGraphQLSchema, defineResolver, defineYogaConfig, relativeWithDot };
|
package/dist/utils.js
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { relative } from "pathe";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
//#region src/utils.ts
|
|
4
|
+
function defineGraphQLSchema(config) {
|
|
5
|
+
return config;
|
|
6
|
+
}
|
|
7
|
+
function defineResolver(resolvers) {
|
|
8
|
+
return resolvers;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Helper function to define GraphQL Yoga configuration with type safety
|
|
12
|
+
*/
|
|
13
|
+
function defineYogaConfig(config) {
|
|
14
|
+
return config;
|
|
15
|
+
}
|
|
16
|
+
const RELATIVE_RE = /^\.{1,2}\//;
|
|
17
|
+
function relativeWithDot(from, to) {
|
|
18
|
+
const rel = relative(from, to);
|
|
19
|
+
return RELATIVE_RE.test(rel) ? rel : `./${rel}`;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { defineGraphQLSchema, defineResolver, defineYogaConfig, relativeWithDot };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nitro-graphql",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.3",
|
|
5
5
|
"description": "GraphQL integration for Nitro",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"sideEffects": false,
|
|
@@ -29,6 +29,10 @@
|
|
|
29
29
|
"./utils": {
|
|
30
30
|
"types": "./dist/utils.d.ts",
|
|
31
31
|
"import": "./dist/utils.js"
|
|
32
|
+
},
|
|
33
|
+
"./types": {
|
|
34
|
+
"types": "./dist/types.d.ts",
|
|
35
|
+
"import": "./dist/types.js"
|
|
32
36
|
}
|
|
33
37
|
},
|
|
34
38
|
"main": "./dist/index.js",
|
|
@@ -55,15 +59,16 @@
|
|
|
55
59
|
"chokidar": "^4.0.3",
|
|
56
60
|
"consola": "^3.4.2",
|
|
57
61
|
"defu": "^6.1.4",
|
|
58
|
-
"globby": "^14.1.0",
|
|
59
62
|
"graphql": "^16.11.0",
|
|
60
63
|
"graphql-scalars": "^1.24.2",
|
|
61
64
|
"graphql-yoga": "^5.14.0",
|
|
62
|
-
"pathe": "^2.0.3"
|
|
65
|
+
"pathe": "^2.0.3",
|
|
66
|
+
"perfect-debounce": "^1.0.0",
|
|
67
|
+
"tinyglobby": "^0.2.14"
|
|
63
68
|
},
|
|
64
69
|
"devDependencies": {
|
|
65
70
|
"@antfu/eslint-config": "^4.16.2",
|
|
66
|
-
"@types/node": "^20.19.
|
|
71
|
+
"@types/node": "^20.19.7",
|
|
67
72
|
"bumpp": "^10.2.0",
|
|
68
73
|
"changelogen": "^0.6.2",
|
|
69
74
|
"eslint": "^9.30.1",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client-codegen-DM2n5Gt2.js","names":["_schema: any","_documents: any","_config: any","_info: any","patterns: string | string[]","e: any","schema: GraphQLSchema","config: CodegenClientConfig","outputPath?: string","defaultConfig: CodegenClientConfig","typescriptPlugin","typescriptOperations","typescriptGenericSdk"],"sources":["../src/client-codegen.ts"],"sourcesContent":["import type { GraphQLSchema } from 'graphql'\nimport type { CodegenClientConfig } from './types'\nimport { codegen } from '@graphql-codegen/core'\nimport { plugin as typescriptPlugin } from '@graphql-codegen/typescript'\nimport { plugin as typescriptGenericSdk } from '@graphql-codegen/typescript-generic-sdk'\nimport { plugin as typescriptOperations } from '@graphql-codegen/typescript-operations'\nimport { GraphQLFileLoader } from '@graphql-tools/graphql-file-loader'\nimport { loadDocuments } from '@graphql-tools/load'\nimport { printSchemaWithDirectives } from '@graphql-tools/utils'\nimport { consola } from 'consola'\nimport { defu } from 'defu'\nimport { parse } from 'graphql'\n\nfunction pluginContent(_schema: any, _documents: any, _config: any, _info: any) {\n return {\n prepend: [\n '// THIS FILE IS GENERATED, DO NOT EDIT!',\n '/* eslint-disable eslint-comments/no-unlimited-disable */',\n '/* tslint:disable */',\n '/* eslint-disable */',\n '/* prettier-ignore */',\n ],\n content: '',\n }\n}\n\nasync function loadGraphQLDocuments(patterns: string | string[]) {\n try {\n const result = await loadDocuments(patterns, {\n loaders: [new GraphQLFileLoader()],\n })\n return result\n }\n catch (e: any) {\n if (\n (e.message || '').includes(\n 'Unable to find any GraphQL type definitions for the following pointers:',\n )\n ) {\n // No GraphQL files found - this is normal\n return []\n }\n else {\n // Re-throw other errors\n throw e\n }\n }\n}\n\nexport async function generateClientTypes(\n schema: GraphQLSchema,\n patterns: string | string[],\n config: CodegenClientConfig = {},\n outputPath?: string,\n) {\n const docs = await loadGraphQLDocuments(patterns)\n\n if (docs.length === 0) {\n consola.info('[graphql] No client GraphQL files found. Skipping client type generation.')\n return ''\n }\n\n consola.info(`[graphql] Found ${docs.length} client GraphQL documents`)\n\n const defaultConfig: CodegenClientConfig = {\n documentMode: 'string',\n emitLegacyCommonJSImports: false,\n useTypeImports: true,\n enumsAsTypes: true,\n strictScalars: true,\n maybeValue: 'T | null | undefined',\n inputMaybeValue: 'T | undefined',\n scalars: {\n DateTime: 'string',\n JSON: 'any',\n UUID: 'string',\n NonEmptyString: 'string',\n Currency: 'string',\n },\n }\n\n const mergedConfig = defu(config, defaultConfig)\n\n try {\n const output = await codegen({\n filename: outputPath || 'client-types.generated.ts',\n schema: parse(printSchemaWithDirectives(schema)),\n documents: [...docs],\n config: mergedConfig,\n plugins: [\n { pluginContent: {} },\n { typescript: {} },\n { typescriptOperations: {} },\n { typescriptGenericSdk: { rawRequest: false } },\n ],\n pluginMap: {\n pluginContent: { plugin: pluginContent },\n typescript: { plugin: typescriptPlugin },\n typescriptOperations: { plugin: typescriptOperations },\n typescriptGenericSdk: { plugin: typescriptGenericSdk },\n },\n })\n\n return output\n }\n catch (error) {\n consola.warn('[graphql] Client type generation failed:', error)\n return ''\n }\n}\n"],"mappings":";;;;;;;;;;;;AAaA,SAAS,cAAcA,SAAcC,YAAiBC,SAAcC,OAAY;AAC9E,QAAO;EACL,SAAS;GACP;GACA;GACA;GACA;GACA;EACD;EACD,SAAS;CACV;AACF;AAED,eAAe,qBAAqBC,UAA6B;AAC/D,KAAI;EACF,MAAM,SAAS,MAAM,cAAc,UAAU,EAC3C,SAAS,CAAC,IAAI,mBAAoB,EACnC,EAAC;AACF,SAAO;CACR,SACMC,GAAQ;AACb,MACE,CAAC,EAAE,WAAW,IAAI,SAChB,0EACD,CAGD,QAAO,CAAE;MAIT,OAAM;CAET;AACF;AAED,eAAsB,oBACpBC,QACAF,UACAG,SAA8B,CAAE,GAChCC,YACA;CACA,MAAM,OAAO,MAAM,qBAAqB,SAAS;AAEjD,KAAI,KAAK,WAAW,GAAG;AACrB,UAAQ,KAAK,4EAA4E;AACzF,SAAO;CACR;AAED,SAAQ,KAAK,CAAC,gBAAgB,EAAE,KAAK,OAAO,yBAAyB,CAAC,CAAC;CAEvE,MAAMC,gBAAqC;EACzC,cAAc;EACd,2BAA2B;EAC3B,gBAAgB;EAChB,cAAc;EACd,eAAe;EACf,YAAY;EACZ,iBAAiB;EACjB,SAAS;GACP,UAAU;GACV,MAAM;GACN,MAAM;GACN,gBAAgB;GAChB,UAAU;EACX;CACF;CAED,MAAM,eAAe,KAAK,QAAQ,cAAc;AAEhD,KAAI;EACF,MAAM,SAAS,MAAM,QAAQ;GAC3B,UAAU,cAAc;GACxB,QAAQ,MAAM,0BAA0B,OAAO,CAAC;GAChD,WAAW,CAAC,GAAG,IAAK;GACpB,QAAQ;GACR,SAAS;IACP,EAAE,eAAe,CAAE,EAAE;IACrB,EAAE,YAAY,CAAE,EAAE;IAClB,EAAE,sBAAsB,CAAE,EAAE;IAC5B,EAAE,sBAAsB,EAAE,YAAY,MAAO,EAAE;GAChD;GACD,WAAW;IACT,eAAe,EAAE,QAAQ,cAAe;IACxC,YAAY,EAAUC,OAAkB;IACxC,sBAAsB,EAAE,QAAQC,SAAsB;IACtD,sBAAsB,EAAE,QAAQC,SAAsB;GACvD;EACF,EAAC;AAEF,SAAO;CACR,SACM,OAAO;AACZ,UAAQ,KAAK,4CAA4C,MAAM;AAC/D,SAAO;CACR;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client-watcher.d.ts","names":[],"sources":["../src/client-watcher.ts"],"sourcesContent":[],"mappings":";;;;iBAmEsB,kBAAA,QAA0B,gBAAgB,sBAAmB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client-watcher.js","names":["nitro: Nitro","options: NitroGraphQLYogaOptions","options: NitroGraphQLOptions"],"sources":["../src/client-watcher.ts"],"sourcesContent":["import type { Nitro } from 'nitropack/types'\nimport type { NitroGraphQLOptions } from './types'\nimport { mkdir, writeFile } from 'node:fs/promises'\nimport { mergeTypeDefs } from '@graphql-tools/merge'\nimport { makeExecutableSchema } from '@graphql-tools/schema'\nimport { consola } from 'consola'\nimport { join } from 'pathe'\n// import { generateClientTypes } from './client-codegen' // Conditionally imported to prevent bundling\nimport { scanGraphQLFiles } from './scanner'\nimport { debounce } from './utils'\n\nconst logger = consola.withTag('graphql')\n\nasync function regenerateClientTypes(nitro: Nitro, options: NitroGraphQLYogaOptions) {\n try {\n if (!options.client?.enabled)\n return\n\n // Regenerating client types silently\n\n // Get the server schema\n const scanResult = await scanGraphQLFiles(nitro)\n if (scanResult.typeDefs.length === 0) {\n logger.warn('⚠️ No server schema found for client type generation')\n return\n }\n\n const mergedTypeDefs = mergeTypeDefs(scanResult.typeDefs)\n const schema = makeExecutableSchema({\n typeDefs: mergedTypeDefs,\n resolvers: {},\n })\n\n // Client GraphQL file patterns\n const clientPatterns = options.client.watchPatterns || [\n join(nitro.options.srcDir, '**/*.graphql'),\n join(nitro.options.srcDir, '**/*.gql'),\n // Exclude server GraphQL files\n `!${join(nitro.options.srcDir, 'graphql/**/*')}`,\n ]\n\n // Generate client types using dynamic import\n const { generateClientTypes } = await import('./client-codegen')\n const generatedTypes = await generateClientTypes(\n schema,\n clientPatterns,\n options.client.config,\n options.client.outputPath,\n )\n\n if (generatedTypes) {\n const outputPath = options.client.outputPath\n || join(nitro.options.buildDir, 'types', 'graphql-client.generated.ts')\n\n const typesDir = join(nitro.options.buildDir, 'types')\n await mkdir(typesDir, { recursive: true })\n await writeFile(outputPath, generatedTypes)\n\n logger.success('✨ Client types updated')\n }\n }\n catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error)\n logger.error('❌ Client type generation failed:', errorMessage)\n }\n}\n\nexport async function setupClientWatcher(nitro: Nitro, options: NitroGraphQLOptions) {\n if (!options.client?.enabled) {\n logger.info('🚫 Client type generation disabled')\n return\n }\n\n // Setting up client file watcher\n\n // Client GraphQL patterns\n const clientPatterns = options.client.watchPatterns || [\n join(nitro.options.srcDir, '**/*.graphql'),\n join(nitro.options.srcDir, '**/*.gql'),\n ]\n\n const generateClientTypesDebounced = debounce(async () => {\n await regenerateClientTypes(nitro, options)\n }, 300)\n\n const { watch } = await import('chokidar')\n const { globby } = await import('globby')\n\n // Find existing client GraphQL files\n const existingClientFiles = await globby(clientPatterns, {\n absolute: true,\n ignore: [join(nitro.options.srcDir, 'graphql/**/*')], // Exclude server files\n })\n\n // Client file watching setup complete\n\n const watchPatterns = existingClientFiles.length > 0 ? existingClientFiles : clientPatterns\n\n const watcher = watch(watchPatterns, {\n persistent: true,\n ignoreInitial: true,\n ignored: /(^|[/\\\\])\\../,\n followSymlinks: false,\n depth: 10,\n usePolling: true,\n interval: 1000,\n binaryInterval: 1000,\n })\n\n watcher.on('change', (_path) => {\n generateClientTypesDebounced()\n })\n\n watcher.on('add', (_path) => {\n generateClientTypesDebounced()\n })\n\n watcher.on('unlink', (_path) => {\n generateClientTypesDebounced()\n })\n\n watcher.on('error', (error) => {\n const errorMessage = error instanceof Error ? error.message : String(error)\n logger.error('❌ Client watcher error:', errorMessage)\n })\n\n nitro.hooks.hook('close', () => {\n logger.info('🔒 Closing client watcher')\n watcher.close()\n })\n\n // Generate initial types\n await generateClientTypesDebounced()\n\n logger.success('✅ Client watcher ready')\n}\n"],"mappings":";;;;;;;;;AAWA,MAAM,SAAS,QAAQ,QAAQ,UAAU;AAEzC,eAAe,sBAAsBA,OAAcC,SAAkC;AACnF,KAAI;AACF,OAAK,QAAQ,QAAQ,QACnB;EAKF,MAAM,aAAa,MAAM,iBAAiB,MAAM;AAChD,MAAI,WAAW,SAAS,WAAW,GAAG;AACpC,UAAO,KAAK,wDAAwD;AACpE;EACD;EAED,MAAM,iBAAiB,cAAc,WAAW,SAAS;EACzD,MAAM,SAAS,qBAAqB;GAClC,UAAU;GACV,WAAW,CAAE;EACd,EAAC;EAGF,MAAM,iBAAiB,QAAQ,OAAO,iBAAiB;GACrD,KAAK,MAAM,QAAQ,QAAQ,eAAe;GAC1C,KAAK,MAAM,QAAQ,QAAQ,WAAW;GAEtC,CAAC,CAAC,EAAE,KAAK,MAAM,QAAQ,QAAQ,eAAe,EAAE;EACjD;EAGD,MAAM,EAAE,qBAAqB,GAAG,MAAM,OAAO;EAC7C,MAAM,iBAAiB,MAAM,oBAC3B,QACA,gBACA,QAAQ,OAAO,QACf,QAAQ,OAAO,WAChB;AAED,MAAI,gBAAgB;GAClB,MAAM,aAAa,QAAQ,OAAO,cAC7B,KAAK,MAAM,QAAQ,UAAU,SAAS,8BAA8B;GAEzE,MAAM,WAAW,KAAK,MAAM,QAAQ,UAAU,QAAQ;AACtD,SAAM,MAAM,UAAU,EAAE,WAAW,KAAM,EAAC;AAC1C,SAAM,UAAU,YAAY,eAAe;AAE3C,UAAO,QAAQ,yBAAyB;EACzC;CACF,SACM,OAAO;EACZ,MAAM,eAAe,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;AAC3E,SAAO,MAAM,oCAAoC,aAAa;CAC/D;AACF;AAED,eAAsB,mBAAmBD,OAAcE,SAA8B;AACnF,MAAK,QAAQ,QAAQ,SAAS;AAC5B,SAAO,KAAK,qCAAqC;AACjD;CACD;CAKD,MAAM,iBAAiB,QAAQ,OAAO,iBAAiB,CACrD,KAAK,MAAM,QAAQ,QAAQ,eAAe,EAC1C,KAAK,MAAM,QAAQ,QAAQ,WAAW,AACvC;CAED,MAAM,+BAA+B,SAAS,YAAY;AACxD,QAAM,sBAAsB,OAAO,QAAQ;CAC5C,GAAE,IAAI;CAEP,MAAM,EAAE,OAAO,GAAG,MAAM,OAAO;CAC/B,MAAM,EAAE,QAAQ,GAAG,MAAM,OAAO;CAGhC,MAAM,sBAAsB,MAAM,OAAO,gBAAgB;EACvD,UAAU;EACV,QAAQ,CAAC,KAAK,MAAM,QAAQ,QAAQ,eAAe,AAAC;CACrD,EAAC;CAIF,MAAM,gBAAgB,oBAAoB,SAAS,IAAI,sBAAsB;CAE7E,MAAM,UAAU,MAAM,eAAe;EACnC,YAAY;EACZ,eAAe;EACf,SAAS;EACT,gBAAgB;EAChB,OAAO;EACP,YAAY;EACZ,UAAU;EACV,gBAAgB;CACjB,EAAC;AAEF,SAAQ,GAAG,UAAU,CAAC,UAAU;AAC9B,gCAA8B;CAC/B,EAAC;AAEF,SAAQ,GAAG,OAAO,CAAC,UAAU;AAC3B,gCAA8B;CAC/B,EAAC;AAEF,SAAQ,GAAG,UAAU,CAAC,UAAU;AAC9B,gCAA8B;CAC/B,EAAC;AAEF,SAAQ,GAAG,SAAS,CAAC,UAAU;EAC7B,MAAM,eAAe,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;AAC3E,SAAO,MAAM,2BAA2B,aAAa;CACtD,EAAC;AAEF,OAAM,MAAM,KAAK,SAAS,MAAM;AAC9B,SAAO,KAAK,4BAA4B;AACxC,UAAQ,OAAO;CAChB,EAAC;AAGF,OAAM,8BAA8B;AAEpC,QAAO,QAAQ,yBAAyB;AACzC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { GraphQLSchema } from "graphql";
|
|
2
|
-
|
|
3
|
-
//#region src/codegen.d.ts
|
|
4
|
-
interface CodegenServerConfig {
|
|
5
|
-
contextType?: string;
|
|
6
|
-
scalars?: Record<string, any>;
|
|
7
|
-
defaultMapper?: string;
|
|
8
|
-
mapperTypeSuffix?: string;
|
|
9
|
-
[key: string]: any;
|
|
10
|
-
}
|
|
11
|
-
declare function generateTypes(schema: GraphQLSchema, config?: CodegenServerConfig, outputPath?: string): Promise<string>;
|
|
12
|
-
//# sourceMappingURL=codegen.d.ts.map
|
|
13
|
-
|
|
14
|
-
//#endregion
|
|
15
|
-
export { CodegenServerConfig, generateTypes };
|
|
16
|
-
//# sourceMappingURL=codegen-DWJuLowd.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"codegen-DWJuLowd.d.ts","names":[],"sources":["../src/codegen.ts"],"sourcesContent":[],"mappings":";;;UAeiB,mBAAA;;EAAA,OAAA,CAAA,EAEL,MAFK,CAAA,MAAmB,EAAA,GAAA,CAAA;EAqBd,aAAA,CAAA,EAAa,MAAA;EAAA,gBAAA,CAAA,EAAA,MAAA;EAAA,CAAA,GACzB,EAAA,MAAA,CAAA,EAAA,GAAA;;AAEW,iBAHC,aAAA,CAGD,MAAA,EAFX,aAEW,EAAA,MAAA,CAAA,EADX,mBACW,EAAA,UAAA,CAAA,EAAA,MAAA,CAAA,EAAA,OAAA,CAAA,MAAA,CAAA;AAAA"}
|
package/dist/codegen-Dbw6gEZt.js
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { codegen } from "@graphql-codegen/core";
|
|
2
|
-
import * as typescriptPlugin from "@graphql-codegen/typescript";
|
|
3
|
-
import * as typescriptResolversPlugin from "@graphql-codegen/typescript-resolvers";
|
|
4
|
-
import { printSchemaWithDirectives } from "@graphql-tools/utils";
|
|
5
|
-
import { defu } from "defu";
|
|
6
|
-
import { parse } from "graphql";
|
|
7
|
-
import { CurrencyResolver, DateTimeResolver, JSONResolver, NonEmptyStringResolver, UUIDResolver } from "graphql-scalars";
|
|
8
|
-
|
|
9
|
-
//#region src/codegen.ts
|
|
10
|
-
function pluginContent(_schema, _documents, _config, _info) {
|
|
11
|
-
return {
|
|
12
|
-
prepend: [
|
|
13
|
-
"// THIS FILE IS GENERATED, DO NOT EDIT!",
|
|
14
|
-
"/* eslint-disable eslint-comments/no-unlimited-disable */",
|
|
15
|
-
"/* tslint:disable */",
|
|
16
|
-
"/* eslint-disable */",
|
|
17
|
-
"/* prettier-ignore */"
|
|
18
|
-
],
|
|
19
|
-
content: ""
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
async function generateTypes(schema, config = {}, outputPath) {
|
|
23
|
-
const defaultConfig = {
|
|
24
|
-
scalars: {
|
|
25
|
-
Boolean: {
|
|
26
|
-
input: "boolean",
|
|
27
|
-
output: "boolean"
|
|
28
|
-
},
|
|
29
|
-
DateTime: DateTimeResolver.extensions.codegenScalarType,
|
|
30
|
-
DateTimeISO: DateTimeResolver.extensions.codegenScalarType,
|
|
31
|
-
UUID: UUIDResolver.extensions.codegenScalarType,
|
|
32
|
-
JSON: JSONResolver.extensions.codegenScalarType,
|
|
33
|
-
JSONObject: JSONResolver.extensions.codegenScalarType,
|
|
34
|
-
NonEmptyString: NonEmptyStringResolver.extensions.codegenScalarType,
|
|
35
|
-
Currency: CurrencyResolver.extensions.codegenScalarType,
|
|
36
|
-
File: {
|
|
37
|
-
input: "File",
|
|
38
|
-
output: "File"
|
|
39
|
-
},
|
|
40
|
-
Cursor: {
|
|
41
|
-
input: "number",
|
|
42
|
-
output: "number"
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
defaultScalarType: "unknown",
|
|
46
|
-
defaultMapper: `ResolverReturnType<{T}>`,
|
|
47
|
-
contextType: "./context#GraphQLContext",
|
|
48
|
-
maybeValue: "T | null | undefined",
|
|
49
|
-
inputMaybeValue: "T | undefined",
|
|
50
|
-
enumsAsTypes: true,
|
|
51
|
-
useTypeImports: true,
|
|
52
|
-
strictScalars: true,
|
|
53
|
-
emitLegacyCommonJSImports: false
|
|
54
|
-
};
|
|
55
|
-
const mergedConfig = defu(config, defaultConfig);
|
|
56
|
-
const output = await codegen({
|
|
57
|
-
filename: outputPath || "types.generated.ts",
|
|
58
|
-
schema: parse(printSchemaWithDirectives(schema)),
|
|
59
|
-
documents: [],
|
|
60
|
-
config: mergedConfig,
|
|
61
|
-
plugins: [
|
|
62
|
-
{ imports: {} },
|
|
63
|
-
{ pluginContent: {} },
|
|
64
|
-
{ typescript: {} },
|
|
65
|
-
{ typescriptResolvers: {} }
|
|
66
|
-
],
|
|
67
|
-
pluginMap: {
|
|
68
|
-
pluginContent: { plugin: pluginContent },
|
|
69
|
-
imports: { plugin: () => ({
|
|
70
|
-
prepend: [`type Primitive =
|
|
71
|
-
| null
|
|
72
|
-
| undefined
|
|
73
|
-
| string
|
|
74
|
-
| number
|
|
75
|
-
| boolean
|
|
76
|
-
| symbol
|
|
77
|
-
| bigint;
|
|
78
|
-
|
|
79
|
-
type BuiltIns = Primitive | void | Date | RegExp;
|
|
80
|
-
|
|
81
|
-
type ResolverReturnType<T> = T extends BuiltIns
|
|
82
|
-
? T
|
|
83
|
-
: T extends (...args: any[]) => unknown
|
|
84
|
-
? T | undefined
|
|
85
|
-
: T extends object
|
|
86
|
-
? T extends Array<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
|
|
87
|
-
? ItemType[] extends T // Test for arrays (non-tuples) specifically
|
|
88
|
-
? Array<ResolverReturnType<ItemType>>
|
|
89
|
-
: ResolverReturnTypeObject<T> // Tuples behave properly
|
|
90
|
-
: ResolverReturnTypeObject<T>
|
|
91
|
-
: unknown;
|
|
92
|
-
|
|
93
|
-
type ResolverReturnTypeObject<T extends object> = {
|
|
94
|
-
[K in keyof T]: ResolverReturnType<T[K]>
|
|
95
|
-
};`, ""],
|
|
96
|
-
content: ""
|
|
97
|
-
}) },
|
|
98
|
-
typescript: typescriptPlugin,
|
|
99
|
-
typescriptResolvers: typescriptResolversPlugin
|
|
100
|
-
}
|
|
101
|
-
}).catch((e) => {
|
|
102
|
-
console.warn("[nitro-graphql] Code generation error:", e);
|
|
103
|
-
return "";
|
|
104
|
-
});
|
|
105
|
-
return output;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
//#endregion
|
|
109
|
-
export { generateTypes };
|
|
110
|
-
//# sourceMappingURL=codegen-Dbw6gEZt.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"codegen-Dbw6gEZt.js","names":["_schema: any","_documents: any","_config: any","_info: any","schema: GraphQLSchema","config: CodegenServerConfig","outputPath?: string","defaultConfig: CodegenServerConfig","e: any"],"sources":["../src/codegen.ts"],"sourcesContent":["import type { GraphQLSchema } from 'graphql'\nimport { codegen } from '@graphql-codegen/core'\nimport * as typescriptPlugin from '@graphql-codegen/typescript'\nimport * as typescriptResolversPlugin from '@graphql-codegen/typescript-resolvers'\nimport { printSchemaWithDirectives } from '@graphql-tools/utils'\nimport { defu } from 'defu'\nimport { parse } from 'graphql'\nimport {\n CurrencyResolver,\n DateTimeResolver,\n JSONResolver,\n NonEmptyStringResolver,\n UUIDResolver,\n} from 'graphql-scalars'\n\nexport interface CodegenServerConfig {\n contextType?: string\n scalars?: Record<string, any>\n defaultMapper?: string\n mapperTypeSuffix?: string\n [key: string]: any\n}\n\nfunction pluginContent(_schema: any, _documents: any, _config: any, _info: any) {\n return {\n prepend: [\n '// THIS FILE IS GENERATED, DO NOT EDIT!',\n '/* eslint-disable eslint-comments/no-unlimited-disable */',\n '/* tslint:disable */',\n '/* eslint-disable */',\n '/* prettier-ignore */',\n ],\n content: '',\n }\n}\n\nexport async function generateTypes(\n schema: GraphQLSchema,\n config: CodegenServerConfig = {},\n outputPath?: string,\n) {\n const defaultConfig: CodegenServerConfig = {\n scalars: {\n Boolean: {\n input: 'boolean',\n output: 'boolean',\n },\n DateTime: DateTimeResolver.extensions.codegenScalarType as any,\n DateTimeISO: DateTimeResolver.extensions.codegenScalarType as any,\n UUID: UUIDResolver.extensions.codegenScalarType as any,\n JSON: JSONResolver.extensions.codegenScalarType as any,\n JSONObject: JSONResolver.extensions.codegenScalarType as any,\n NonEmptyString: NonEmptyStringResolver.extensions.codegenScalarType as any,\n Currency: CurrencyResolver.extensions.codegenScalarType as any,\n File: {\n input: 'File',\n output: 'File',\n },\n Cursor: {\n input: 'number',\n output: 'number',\n },\n },\n defaultScalarType: 'unknown',\n defaultMapper: `ResolverReturnType<{T}>`,\n contextType: './context#GraphQLContext',\n maybeValue: 'T | null | undefined',\n inputMaybeValue: 'T | undefined',\n enumsAsTypes: true,\n useTypeImports: true,\n strictScalars: true,\n emitLegacyCommonJSImports: false,\n }\n\n const mergedConfig = defu(config, defaultConfig)\n\n const output = await codegen({\n filename: outputPath || 'types.generated.ts',\n schema: parse(printSchemaWithDirectives(schema)),\n documents: [],\n config: mergedConfig,\n plugins: [\n { imports: {} },\n { pluginContent: {} },\n { typescript: {} },\n { typescriptResolvers: {} },\n ],\n pluginMap: {\n pluginContent: {\n plugin: pluginContent,\n },\n imports: {\n plugin: () => ({\n prepend: [\n `type Primitive =\n | null\n | undefined\n | string\n | number\n | boolean\n | symbol\n | bigint;\n\ntype BuiltIns = Primitive | void | Date | RegExp;\n\ntype ResolverReturnType<T> = T extends BuiltIns\n ? T\n : T extends (...args: any[]) => unknown\n ? T | undefined\n : T extends object\n ? T extends Array<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156\n ? ItemType[] extends T // Test for arrays (non-tuples) specifically\n ? Array<ResolverReturnType<ItemType>>\n : ResolverReturnTypeObject<T> // Tuples behave properly\n : ResolverReturnTypeObject<T>\n : unknown;\n\ntype ResolverReturnTypeObject<T extends object> = {\n [K in keyof T]: ResolverReturnType<T[K]>\n};`,\n '',\n ],\n content: '',\n }),\n },\n typescript: typescriptPlugin,\n typescriptResolvers: typescriptResolversPlugin,\n },\n }).catch((e: any) => {\n console.warn('[nitro-graphql] Code generation error:', e)\n return ''\n })\n\n return output\n}\n"],"mappings":";;;;;;;;;AAuBA,SAAS,cAAcA,SAAcC,YAAiBC,SAAcC,OAAY;AAC9E,QAAO;EACL,SAAS;GACP;GACA;GACA;GACA;GACA;EACD;EACD,SAAS;CACV;AACF;AAED,eAAsB,cACpBC,QACAC,SAA8B,CAAE,GAChCC,YACA;CACA,MAAMC,gBAAqC;EACzC,SAAS;GACP,SAAS;IACP,OAAO;IACP,QAAQ;GACT;GACD,UAAU,iBAAiB,WAAW;GACtC,aAAa,iBAAiB,WAAW;GACzC,MAAM,aAAa,WAAW;GAC9B,MAAM,aAAa,WAAW;GAC9B,YAAY,aAAa,WAAW;GACpC,gBAAgB,uBAAuB,WAAW;GAClD,UAAU,iBAAiB,WAAW;GACtC,MAAM;IACJ,OAAO;IACP,QAAQ;GACT;GACD,QAAQ;IACN,OAAO;IACP,QAAQ;GACT;EACF;EACD,mBAAmB;EACnB,eAAe,CAAC,uBAAuB,CAAC;EACxC,aAAa;EACb,YAAY;EACZ,iBAAiB;EACjB,cAAc;EACd,gBAAgB;EAChB,eAAe;EACf,2BAA2B;CAC5B;CAED,MAAM,eAAe,KAAK,QAAQ,cAAc;CAEhD,MAAM,SAAS,MAAM,QAAQ;EAC3B,UAAU,cAAc;EACxB,QAAQ,MAAM,0BAA0B,OAAO,CAAC;EAChD,WAAW,CAAE;EACb,QAAQ;EACR,SAAS;GACP,EAAE,SAAS,CAAE,EAAE;GACf,EAAE,eAAe,CAAE,EAAE;GACrB,EAAE,YAAY,CAAE,EAAE;GAClB,EAAE,qBAAqB,CAAE,EAAE;EAC5B;EACD,WAAW;GACT,eAAe,EACb,QAAQ,cACT;GACD,SAAS,EACP,QAAQ,OAAO;IACb,SAAS,CACP,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;EAyBX,CAAC,EACS,EACD;IACD,SAAS;GACV,GACF;GACD,YAAY;GACZ,qBAAqB;EACtB;CACF,EAAC,CAAC,MAAM,CAACC,MAAW;AACnB,UAAQ,KAAK,0CAA0C,EAAE;AACzD,SAAO;CACR,EAAC;AAEF,QAAO;AACR"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { YogaInitialContext } from "graphql-yoga";
|
|
2
|
-
import { H3Event } from "h3";
|
|
3
|
-
|
|
4
|
-
//#region src/context.d.ts
|
|
5
|
-
interface GraphQLContext extends YogaInitialContext {
|
|
6
|
-
event: H3Event;
|
|
7
|
-
storage: any;
|
|
8
|
-
}
|
|
9
|
-
//# sourceMappingURL=context.d.ts.map
|
|
10
|
-
|
|
11
|
-
//#endregion
|
|
12
|
-
export { GraphQLContext };
|
|
13
|
-
//# sourceMappingURL=context-BgqNJFCT.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context-BgqNJFCT.d.ts","names":[],"sources":["../src/context.ts"],"sourcesContent":[],"mappings":";;;;UAGiB,cAAA,SAAuB;SAC/B;EADQ,OAAA,EAAA,GAAA"}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":""}
|