nitro-graphql 0.0.1
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/LICENSE +21 -0
- package/README.md +476 -0
- package/dist/client-codegen-DM2n5Gt2.js +86 -0
- package/dist/client-codegen-DM2n5Gt2.js.map +1 -0
- package/dist/client-watcher.d.ts +10 -0
- package/dist/client-watcher.d.ts.map +1 -0
- package/dist/client-watcher.js +92 -0
- package/dist/client-watcher.js.map +1 -0
- package/dist/codegen-DWJuLowd.d.ts +16 -0
- package/dist/codegen-DWJuLowd.d.ts.map +1 -0
- package/dist/codegen-Dbw6gEZt.js +110 -0
- package/dist/codegen-Dbw6gEZt.js.map +1 -0
- package/dist/codegen.d.ts +2 -0
- package/dist/codegen.js +3 -0
- package/dist/context-BgqNJFCT.d.ts +13 -0
- package/dist/context-BgqNJFCT.d.ts.map +1 -0
- package/dist/context-CZdhkJYD.js +0 -0
- package/dist/context.d.ts +2 -0
- package/dist/context.js +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +424 -0
- package/dist/index.js.map +1 -0
- package/dist/scanner-BdcKEPQk.js +119 -0
- package/dist/scanner-BdcKEPQk.js.map +1 -0
- package/dist/types-D_NqyCcy.d.ts +47 -0
- package/dist/types-D_NqyCcy.d.ts.map +1 -0
- package/dist/utils-87_22aIA.js +41 -0
- package/dist/utils-87_22aIA.js.map +1 -0
- package/dist/utils-BuYDOLIi.d.ts +22 -0
- package/dist/utils-BuYDOLIi.d.ts.map +1 -0
- package/dist/utils.d.ts +3 -0
- package/dist/utils.js +3 -0
- package/dist/watcher.d.ts +9 -0
- package/dist/watcher.d.ts.map +1 -0
- package/dist/watcher.js +96 -0
- package/dist/watcher.js.map +1 -0
- package/package.json +87 -0
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,110 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
package/dist/codegen.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-BgqNJFCT.d.ts","names":[],"sources":["../src/context.ts"],"sourcesContent":[],"mappings":";;;;UAGiB,cAAA,SAAuB;SAC/B;EADQ,OAAA,EAAA,GAAA"}
|
|
File without changes
|
package/dist/context.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./context-CZdhkJYD.js";
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CodegenClientConfig, GraphQLSchemaConfig, NitroGraphQLOptions, Resolvers } from "./types-D_NqyCcy.js";
|
|
2
|
+
import { CodegenServerConfig, generateTypes } from "./codegen-DWJuLowd.js";
|
|
3
|
+
import { GraphQLContext } from "./context-BgqNJFCT.js";
|
|
4
|
+
import { createResolver, defineGraphQLResolver, defineYogaConfig } from "./utils-BuYDOLIi.js";
|
|
5
|
+
import * as nitropack0 from "nitropack";
|
|
6
|
+
|
|
7
|
+
//#region src/index.d.ts
|
|
8
|
+
declare const _default: nitropack0.NitroModule;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { CodegenClientConfig, CodegenServerConfig, GraphQLContext, GraphQLSchemaConfig, NitroGraphQLOptions, Resolvers, createResolver, _default as default, defineGraphQLResolver, defineYogaConfig, generateTypes };
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":""}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
import { scanGraphQLFiles } from "./scanner-BdcKEPQk.js";
|
|
2
|
+
import { createResolver, defineGraphQLResolver, defineYogaConfig } from "./utils-87_22aIA.js";
|
|
3
|
+
import { generateTypes } from "./codegen-Dbw6gEZt.js";
|
|
4
|
+
import "./context-CZdhkJYD.js";
|
|
5
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
6
|
+
import { mergeTypeDefs } from "@graphql-tools/merge";
|
|
7
|
+
import { makeExecutableSchema } from "@graphql-tools/schema";
|
|
8
|
+
import { consola } from "consola";
|
|
9
|
+
import { join } from "pathe";
|
|
10
|
+
import { defineNitroModule } from "nitropack/kit";
|
|
11
|
+
|
|
12
|
+
//#region src/index.ts
|
|
13
|
+
const logger = consola.withTag("graphql");
|
|
14
|
+
var src_default = defineNitroModule({
|
|
15
|
+
name: "nitro:graphql-yoga",
|
|
16
|
+
async setup(nitro) {
|
|
17
|
+
const options = {
|
|
18
|
+
endpoint: "/api/graphql",
|
|
19
|
+
playground: true,
|
|
20
|
+
cors: false,
|
|
21
|
+
cacheHeaders: {
|
|
22
|
+
enabled: true,
|
|
23
|
+
maxAge: 604800
|
|
24
|
+
},
|
|
25
|
+
client: {
|
|
26
|
+
enabled: false,
|
|
27
|
+
outputPath: void 0,
|
|
28
|
+
watchPatterns: void 0,
|
|
29
|
+
config: {
|
|
30
|
+
documentMode: "string",
|
|
31
|
+
emitLegacyCommonJSImports: false,
|
|
32
|
+
useTypeImports: true,
|
|
33
|
+
enumsAsTypes: true
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
...nitro.options.graphqlYoga,
|
|
37
|
+
...nitro.options.runtimeConfig?.graphqlYoga
|
|
38
|
+
};
|
|
39
|
+
const graphqlPath = join(nitro.options.srcDir, "graphql");
|
|
40
|
+
nitro.hooks.hook("rollup:before", (nitro$1, rollupConfig) => {
|
|
41
|
+
rollupConfig.external = rollupConfig.external || [];
|
|
42
|
+
const codegenExternals = [
|
|
43
|
+
"@graphql-codegen/core",
|
|
44
|
+
"@graphql-codegen/typescript",
|
|
45
|
+
"@graphql-codegen/typescript-resolvers",
|
|
46
|
+
"@graphql-codegen/typescript-operations",
|
|
47
|
+
"@graphql-codegen/typescript-generic-sdk",
|
|
48
|
+
"@graphql-tools/graphql-file-loader",
|
|
49
|
+
"@graphql-tools/load"
|
|
50
|
+
];
|
|
51
|
+
if (Array.isArray(rollupConfig.external)) rollupConfig.external.push(...codegenExternals);
|
|
52
|
+
else if (typeof rollupConfig.external === "function") {
|
|
53
|
+
const originalExternal = rollupConfig.external;
|
|
54
|
+
rollupConfig.external = (id, parent, isResolved) => {
|
|
55
|
+
if (codegenExternals.some((external) => id.includes(external))) return true;
|
|
56
|
+
return originalExternal(id, parent, isResolved);
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
const originalChunkFileNames = rollupConfig.output.chunkFileNames;
|
|
60
|
+
rollupConfig.output.chunkFileNames = (chunk) => {
|
|
61
|
+
const allIds = chunk.moduleIds || [];
|
|
62
|
+
const hasGraphQLResolverFile = allIds.some((id) => id.includes(graphqlPath) && !id.includes("node_modules") && !id.includes("#nitro-graphql") && (id.endsWith(".ts") || id.endsWith(".js") || id.endsWith(".mjs")));
|
|
63
|
+
if (hasGraphQLResolverFile) return `chunks/graphql/[name].mjs`;
|
|
64
|
+
if (typeof originalChunkFileNames === "function") return originalChunkFileNames(chunk);
|
|
65
|
+
return originalChunkFileNames || "chunks/_/[name].mjs";
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
nitro.options.virtual ??= {};
|
|
69
|
+
nitro.options.virtual["#nitro-graphql/context"] = () => `
|
|
70
|
+
export type { GraphQLContext } from 'nitro-graphql/context'
|
|
71
|
+
`;
|
|
72
|
+
const scanResult = await scanGraphQLFiles(nitro);
|
|
73
|
+
if (scanResult.resolvers.length > 0) logger.success(`Found ${scanResult.resolvers.length} resolvers`);
|
|
74
|
+
if (scanResult.typeDefs.length > 0) {
|
|
75
|
+
const mergedTypeDefs = mergeTypeDefs(scanResult.typeDefs);
|
|
76
|
+
const schema = makeExecutableSchema({
|
|
77
|
+
typeDefs: mergedTypeDefs,
|
|
78
|
+
resolvers: {}
|
|
79
|
+
});
|
|
80
|
+
const { generateTypes: generateTypes$1 } = await new Function("return import(\"nitro-graphql/codegen\")")();
|
|
81
|
+
const generatedTypes = await generateTypes$1(schema);
|
|
82
|
+
const outputPath = join(nitro.options.buildDir, "types", "graphql-types.generated.ts");
|
|
83
|
+
const typesDir = join(nitro.options.buildDir, "types");
|
|
84
|
+
await mkdir(typesDir, { recursive: true });
|
|
85
|
+
await writeFile(outputPath, generatedTypes);
|
|
86
|
+
const graphqlDtsPath = join(typesDir, "graphql.d.ts");
|
|
87
|
+
const graphqlDtsContent = `// Auto-generated by nitro-graphql
|
|
88
|
+
import type { Resolvers as Test } from './graphql-types.generated'
|
|
89
|
+
|
|
90
|
+
declare module 'nitro-graphql' {
|
|
91
|
+
interface Resolvers extends Test {}
|
|
92
|
+
}
|
|
93
|
+
`;
|
|
94
|
+
await writeFile(graphqlDtsPath, graphqlDtsContent);
|
|
95
|
+
logger.success("Types generated");
|
|
96
|
+
} else {
|
|
97
|
+
const typesDir = join(nitro.options.buildDir, "types");
|
|
98
|
+
await mkdir(typesDir, { recursive: true });
|
|
99
|
+
const minimalTypes = `// Generated by nitro-graphql (no schema found)
|
|
100
|
+
export type Resolvers = any
|
|
101
|
+
`;
|
|
102
|
+
const outputPath = join(typesDir, "graphql-types.generated.ts");
|
|
103
|
+
await writeFile(outputPath, minimalTypes);
|
|
104
|
+
const graphqlDtsPath = join(typesDir, "graphql.d.ts");
|
|
105
|
+
const graphqlDtsContent = `// Auto-generated by nitro-graphql
|
|
106
|
+
import type { Resolvers as Test } from './graphql-types.generated'
|
|
107
|
+
|
|
108
|
+
declare module 'nitro-graphql' {
|
|
109
|
+
interface Resolvers extends Test {}
|
|
110
|
+
}
|
|
111
|
+
`;
|
|
112
|
+
await writeFile(graphqlDtsPath, graphqlDtsContent);
|
|
113
|
+
logger.info("Created minimal types (no schema found)");
|
|
114
|
+
}
|
|
115
|
+
if (nitro.options.dev) {
|
|
116
|
+
const setupGraphQLWatcher = (await new Function("return import(\"nitro-graphql/watcher\")")()).setupGraphQLWatcher;
|
|
117
|
+
const setupClientWatcher = (await new Function("return import(\"nitro-graphql/client-watcher\")")()).setupClientWatcher;
|
|
118
|
+
await setupGraphQLWatcher(nitro);
|
|
119
|
+
await setupClientWatcher(nitro, options);
|
|
120
|
+
}
|
|
121
|
+
nitro.options.handlers = nitro.options.handlers || [];
|
|
122
|
+
const endpoint = options.endpoint || "/api/graphql";
|
|
123
|
+
nitro.options.handlers.push({
|
|
124
|
+
route: endpoint,
|
|
125
|
+
handler: "#nitro-graphql/handler",
|
|
126
|
+
method: "get"
|
|
127
|
+
});
|
|
128
|
+
nitro.options.handlers.push({
|
|
129
|
+
route: endpoint,
|
|
130
|
+
handler: "#nitro-graphql/handler",
|
|
131
|
+
method: "post"
|
|
132
|
+
});
|
|
133
|
+
nitro.options.handlers.push({
|
|
134
|
+
route: endpoint,
|
|
135
|
+
handler: "#nitro-graphql/handler",
|
|
136
|
+
method: "options"
|
|
137
|
+
});
|
|
138
|
+
nitro.options.handlers.push({
|
|
139
|
+
route: `${endpoint}/health`,
|
|
140
|
+
handler: "#nitro-graphql/health",
|
|
141
|
+
method: "get"
|
|
142
|
+
});
|
|
143
|
+
nitro.options.virtual["#nitro-graphql/handler"] = () => `
|
|
144
|
+
import { createYoga } from 'graphql-yoga'
|
|
145
|
+
import { defineEventHandler, readRawBody, setHeader, setResponseStatus } from 'h3'
|
|
146
|
+
import { useStorage } from 'nitro/runtime'
|
|
147
|
+
import { makeExecutableSchema } from '@graphql-tools/schema'
|
|
148
|
+
import { mergeTypeDefs, mergeResolvers } from '@graphql-tools/merge'
|
|
149
|
+
import { join } from 'pathe'
|
|
150
|
+
// Types are generated at build time to .nitro/graphql-types.generated.ts
|
|
151
|
+
|
|
152
|
+
// GraphQL Context type is injected via context module
|
|
153
|
+
|
|
154
|
+
// Create resolver helper
|
|
155
|
+
globalThis.createResolver = function(resolvers) {
|
|
156
|
+
return resolvers
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Dynamic schema loading function
|
|
160
|
+
async function loadTypeDefs() {
|
|
161
|
+
const schemaPath = join('${nitro.options.srcDir}', 'graphql', '**', '*.graphql')
|
|
162
|
+
const { loadFilesSync } = await import('@graphql-tools/load-files')
|
|
163
|
+
return loadFilesSync(schemaPath, {
|
|
164
|
+
recursive: true,
|
|
165
|
+
})
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Load resolvers using dynamic imports (Nitro handles the bundling)
|
|
169
|
+
const resolverImports = [
|
|
170
|
+
${scanResult.resolvers.map((resolver) => ` () => import('${resolver.path}')`).join(",\n")}
|
|
171
|
+
]
|
|
172
|
+
|
|
173
|
+
// Async function to load resolvers
|
|
174
|
+
async function loadResolvers() {
|
|
175
|
+
let resolvers = {}
|
|
176
|
+
try {
|
|
177
|
+
if (resolverImports.length > 0) {
|
|
178
|
+
const resolverModules = []
|
|
179
|
+
|
|
180
|
+
for (let i = 0; i < resolverImports.length; i++) {
|
|
181
|
+
try {
|
|
182
|
+
const resolverModule = await resolverImports[i]()
|
|
183
|
+
const resolver = resolverModule.default || resolverModule
|
|
184
|
+
|
|
185
|
+
if (resolver) {
|
|
186
|
+
resolverModules.push(resolver)
|
|
187
|
+
}
|
|
188
|
+
} catch (error) {
|
|
189
|
+
console.warn('[graphql] Failed to load resolver:', i, error.message)
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (resolverModules.length > 0) {
|
|
194
|
+
resolvers = mergeResolvers(resolverModules)
|
|
195
|
+
} else {
|
|
196
|
+
console.warn('[graphql] No resolvers could be loaded')
|
|
197
|
+
resolvers = { Query: {}, Mutation: {} }
|
|
198
|
+
}
|
|
199
|
+
} else {
|
|
200
|
+
console.warn('[graphql] No resolvers found')
|
|
201
|
+
resolvers = { Query: {}, Mutation: {} }
|
|
202
|
+
}
|
|
203
|
+
} catch (error) {
|
|
204
|
+
console.warn('[graphql] Error loading resolvers:', error.message)
|
|
205
|
+
resolvers = { Query: {}, Mutation: {} }
|
|
206
|
+
}
|
|
207
|
+
return resolvers
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Apollo Sandbox HTML with 1 week cache
|
|
211
|
+
const apolloSandboxHtml = \`<!DOCTYPE html>
|
|
212
|
+
<html lang="en">
|
|
213
|
+
<body style="margin: 0; overflow-x: hidden; overflow-y: hidden">
|
|
214
|
+
<div id="sandbox" style="height:100vh; width:100vw;"></div>
|
|
215
|
+
<script src="https://embeddable-sandbox.cdn.apollographql.com/02e2da0fccbe0240ef03d2396d6c98559bab5b06/embeddable-sandbox.umd.production.min.js"><\/script>
|
|
216
|
+
<script>
|
|
217
|
+
new window.EmbeddedSandbox({
|
|
218
|
+
target: "#sandbox",
|
|
219
|
+
initialEndpoint: window.location.href,
|
|
220
|
+
hideCookieToggle: false,
|
|
221
|
+
initialState: {
|
|
222
|
+
includeCookies: true
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
<\/script>
|
|
226
|
+
</body>
|
|
227
|
+
</html>\`
|
|
228
|
+
|
|
229
|
+
// Set cache headers for Apollo Sandbox HTML (1 week = 604800 seconds)
|
|
230
|
+
function setApolloSandboxCacheHeaders(event) {
|
|
231
|
+
setHeader(event, 'Cache-Control', 'public, max-age=604800, s-maxage=604800')
|
|
232
|
+
setHeader(event, 'Expires', new Date(Date.now() + 604800000).toUTCString())
|
|
233
|
+
setHeader(event, 'ETag', \`"apollo-sandbox-\${Date.now()}"\`)
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// Lazy initialization
|
|
237
|
+
let yoga = null
|
|
238
|
+
let initPromise = null
|
|
239
|
+
|
|
240
|
+
async function getYoga() {
|
|
241
|
+
// In development mode, always reload schema for hot updates
|
|
242
|
+
const isDev = ${nitro.options.dev}
|
|
243
|
+
if (yoga && !isDev) return yoga
|
|
244
|
+
|
|
245
|
+
if (!initPromise || isDev) {
|
|
246
|
+
// Reset yoga instance in development mode
|
|
247
|
+
if (isDev) {
|
|
248
|
+
yoga = null
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
initPromise = (async () => {
|
|
252
|
+
// Load custom yoga config first (separate from resolvers)
|
|
253
|
+
let customYogaConfig = {}
|
|
254
|
+
${scanResult.yogaConfigPath ? `
|
|
255
|
+
try {
|
|
256
|
+
const yogaConfigModule = await import('${scanResult.yogaConfigPath}')
|
|
257
|
+
customYogaConfig = yogaConfigModule.default || yogaConfigModule
|
|
258
|
+
} catch (error) {
|
|
259
|
+
console.warn('[graphql] Failed to load yoga config:', error.message)
|
|
260
|
+
}` : ""}
|
|
261
|
+
|
|
262
|
+
const resolvers = await loadResolvers()
|
|
263
|
+
const typeDefs = await loadTypeDefs()
|
|
264
|
+
|
|
265
|
+
// Merge schema and resolvers (without yoga config interfering)
|
|
266
|
+
const schema = makeExecutableSchema({
|
|
267
|
+
typeDefs: mergeTypeDefs(typeDefs),
|
|
268
|
+
resolvers,
|
|
269
|
+
})
|
|
270
|
+
|
|
271
|
+
// Default yoga configuration
|
|
272
|
+
const defaultYogaConfig = {
|
|
273
|
+
schema,
|
|
274
|
+
context: async ({ request }) => {
|
|
275
|
+
const event = request.$$event
|
|
276
|
+
return {
|
|
277
|
+
event,
|
|
278
|
+
request,
|
|
279
|
+
storage: useStorage(),
|
|
280
|
+
}
|
|
281
|
+
},
|
|
282
|
+
graphqlEndpoint: '${endpoint}',
|
|
283
|
+
graphiql: ${options.playground !== false},
|
|
284
|
+
renderGraphiQL: () => apolloSandboxHtml,
|
|
285
|
+
landingPage: false,
|
|
286
|
+
cors: ${JSON.stringify(options.cors || false)},
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// Clean up custom config (remove properties that could be mistaken for GraphQL resolvers)
|
|
290
|
+
const cleanCustomConfig = { ...customYogaConfig }
|
|
291
|
+
|
|
292
|
+
// Remove empty arrays and functions that GraphQL Tools might confuse with resolvers
|
|
293
|
+
if (Array.isArray(cleanCustomConfig.plugins) && cleanCustomConfig.plugins.length === 0) {
|
|
294
|
+
delete cleanCustomConfig.plugins
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// Remove these yoga-specific configs from resolver merging
|
|
298
|
+
const yogaOnlyConfigs = ['context', 'plugins', 'maskedErrors', 'graphiql', 'cors']
|
|
299
|
+
const cleanResolverConfig = { ...cleanCustomConfig }
|
|
300
|
+
yogaOnlyConfigs.forEach(key => {
|
|
301
|
+
delete cleanResolverConfig[key]
|
|
302
|
+
})
|
|
303
|
+
|
|
304
|
+
// Merge custom config with defaults
|
|
305
|
+
const yogaConfig = {
|
|
306
|
+
...defaultYogaConfig,
|
|
307
|
+
...cleanCustomConfig,
|
|
308
|
+
// Always override schema and endpoint from default config
|
|
309
|
+
schema,
|
|
310
|
+
graphqlEndpoint: '${endpoint}',
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
yoga = createYoga(yogaConfig)
|
|
314
|
+
|
|
315
|
+
return yoga
|
|
316
|
+
})()
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
return initPromise
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
export default defineEventHandler(async (event) => {
|
|
323
|
+
const { req } = event.node
|
|
324
|
+
const host = req.headers.host || 'localhost'
|
|
325
|
+
const protocol = 'http'
|
|
326
|
+
const url = new URL(req.url || '/', protocol + '://' + host)
|
|
327
|
+
|
|
328
|
+
// Attach event to request for context
|
|
329
|
+
req.$$event = event
|
|
330
|
+
|
|
331
|
+
const yogaInstance = await getYoga()
|
|
332
|
+
const response = await yogaInstance.fetch(url.toString(), {
|
|
333
|
+
method: req.method || 'GET',
|
|
334
|
+
headers: req.headers,
|
|
335
|
+
body: req.method !== 'GET' && req.method !== 'HEAD' ? await readRawBody(event) : undefined,
|
|
336
|
+
}, {
|
|
337
|
+
event,
|
|
338
|
+
})
|
|
339
|
+
|
|
340
|
+
// Set response headers
|
|
341
|
+
response.headers.forEach((value, key) => {
|
|
342
|
+
setHeader(event, key, value)
|
|
343
|
+
})
|
|
344
|
+
|
|
345
|
+
// Set status code
|
|
346
|
+
setResponseStatus(event, response.status)
|
|
347
|
+
|
|
348
|
+
// Return response body
|
|
349
|
+
if (response.body) {
|
|
350
|
+
const contentType = response.headers.get('content-type')
|
|
351
|
+
if (contentType?.includes('text/html')) {
|
|
352
|
+
// Set cache headers for Apollo Sandbox HTML
|
|
353
|
+
setApolloSandboxCacheHeaders(event)
|
|
354
|
+
return await response.text()
|
|
355
|
+
}
|
|
356
|
+
if (contentType?.includes('application/json')) {
|
|
357
|
+
return await response.text()
|
|
358
|
+
}
|
|
359
|
+
return response.body
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
return null
|
|
363
|
+
})
|
|
364
|
+
`;
|
|
365
|
+
nitro.options.virtual["#nitro-graphql/health"] = () => `
|
|
366
|
+
import { defineEventHandler, setResponseStatus } from 'h3'
|
|
367
|
+
|
|
368
|
+
export default defineEventHandler(async (event) => {
|
|
369
|
+
try {
|
|
370
|
+
const response = await $fetch('${endpoint}', {
|
|
371
|
+
method: 'POST',
|
|
372
|
+
body: {
|
|
373
|
+
query: 'query Health { __typename }',
|
|
374
|
+
operationName: 'Health',
|
|
375
|
+
},
|
|
376
|
+
headers: {
|
|
377
|
+
'Content-Type': 'application/json',
|
|
378
|
+
'Accept': 'application/json',
|
|
379
|
+
},
|
|
380
|
+
})
|
|
381
|
+
|
|
382
|
+
if (response && typeof response === 'object' && 'data' in response) {
|
|
383
|
+
return {
|
|
384
|
+
status: 'healthy',
|
|
385
|
+
message: 'GraphQL server is running',
|
|
386
|
+
timestamp: new Date().toISOString(),
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
throw new Error('Invalid response from GraphQL server')
|
|
391
|
+
} catch (error) {
|
|
392
|
+
setResponseStatus(event, 503)
|
|
393
|
+
return {
|
|
394
|
+
status: 'unhealthy',
|
|
395
|
+
message: error.message || 'GraphQL server is not responding',
|
|
396
|
+
timestamp: new Date().toISOString(),
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
})
|
|
400
|
+
`;
|
|
401
|
+
if (nitro.options.imports) nitro.options.imports.presets.push({
|
|
402
|
+
from: "nitro-graphql",
|
|
403
|
+
imports: [
|
|
404
|
+
"createResolver",
|
|
405
|
+
"defineGraphQLResolver",
|
|
406
|
+
"defineGraphQLSchema",
|
|
407
|
+
"defineGraphQLResolvers",
|
|
408
|
+
"defineYogaConfig",
|
|
409
|
+
"gql"
|
|
410
|
+
]
|
|
411
|
+
});
|
|
412
|
+
nitro.options.typescript ??= {};
|
|
413
|
+
nitro.options.typescript.tsConfig ??= {};
|
|
414
|
+
nitro.options.typescript.tsConfig.compilerOptions ??= {};
|
|
415
|
+
nitro.options.typescript.tsConfig.compilerOptions.paths ??= {};
|
|
416
|
+
nitro.options.typescript.tsConfig.compilerOptions.paths["#build/graphql-types.generated"] = [join(nitro.options.buildDir, "types", "graphql-types.generated.ts")];
|
|
417
|
+
nitro.options.typescript.tsConfig.include = nitro.options.typescript.tsConfig.include || [];
|
|
418
|
+
nitro.options.typescript.tsConfig.include.push(join(nitro.options.buildDir, "types", "graphql-types.generated.ts"), join(nitro.options.buildDir, "types", "graphql.d.ts"));
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
//#endregion
|
|
423
|
+
export { createResolver, src_default as default, defineGraphQLResolver, defineYogaConfig, generateTypes };
|
|
424
|
+
//# sourceMappingURL=index.js.map
|