nitro-graphql 2.0.0-beta.4 → 2.0.0-beta.41

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.
Files changed (168) hide show
  1. package/README.md +438 -27
  2. package/dist/cli/commands/generate.d.mts +26 -0
  3. package/dist/cli/commands/generate.mjs +196 -0
  4. package/dist/cli/commands/index.d.mts +4 -0
  5. package/dist/cli/commands/index.mjs +5 -0
  6. package/dist/cli/commands/init.d.mts +46 -0
  7. package/dist/cli/commands/init.mjs +195 -0
  8. package/dist/cli/commands/validate.d.mts +10 -0
  9. package/dist/cli/commands/validate.mjs +69 -0
  10. package/dist/cli/completions.d.mts +7 -0
  11. package/dist/cli/completions.mjs +34 -0
  12. package/dist/cli/config.d.mts +75 -0
  13. package/dist/cli/config.mjs +20 -0
  14. package/dist/cli/index.d.mts +24 -0
  15. package/dist/cli/index.mjs +253 -0
  16. package/dist/config.d.mts +2 -0
  17. package/dist/config.mjs +3 -0
  18. package/dist/core/codegen/client.d.mts +23 -0
  19. package/dist/core/codegen/client.mjs +150 -0
  20. package/dist/core/codegen/document-loader.d.mts +10 -0
  21. package/dist/core/codegen/document-loader.mjs +18 -0
  22. package/dist/core/codegen/index.d.mts +8 -0
  23. package/dist/core/codegen/index.mjs +9 -0
  24. package/dist/core/codegen/plugin.d.mts +20 -0
  25. package/dist/core/codegen/plugin.mjs +30 -0
  26. package/dist/core/codegen/runtime.d.mts +20 -0
  27. package/dist/core/codegen/runtime.mjs +60 -0
  28. package/dist/core/codegen/schema-loader.d.mts +28 -0
  29. package/dist/core/codegen/schema-loader.mjs +128 -0
  30. package/dist/core/codegen/server.d.mts +28 -0
  31. package/dist/core/codegen/server.mjs +143 -0
  32. package/dist/core/codegen/validation.d.mts +13 -0
  33. package/dist/core/codegen/validation.mjs +96 -0
  34. package/dist/core/config.d.mts +50 -0
  35. package/dist/core/config.mjs +82 -0
  36. package/dist/core/constants.d.mts +188 -0
  37. package/dist/core/constants.mjs +210 -0
  38. package/dist/core/index.d.mts +33 -0
  39. package/dist/core/index.mjs +27 -0
  40. package/dist/core/manifest.d.mts +46 -0
  41. package/dist/core/manifest.mjs +76 -0
  42. package/dist/core/scanning/ast-scanner.d.mts +28 -0
  43. package/dist/core/scanning/ast-scanner.mjs +122 -0
  44. package/dist/core/scanning/common.d.mts +37 -0
  45. package/dist/core/scanning/common.mjs +60 -0
  46. package/dist/core/scanning/directives.d.mts +10 -0
  47. package/dist/core/scanning/directives.mjs +29 -0
  48. package/dist/core/scanning/documents.d.mts +21 -0
  49. package/dist/core/scanning/documents.mjs +43 -0
  50. package/dist/core/scanning/index.d.mts +7 -0
  51. package/dist/core/scanning/index.mjs +8 -0
  52. package/dist/core/scanning/resolvers.d.mts +15 -0
  53. package/dist/core/scanning/resolvers.mjs +59 -0
  54. package/dist/core/scanning/schemas.d.mts +14 -0
  55. package/dist/core/scanning/schemas.mjs +64 -0
  56. package/dist/core/schema/builder.d.mts +53 -0
  57. package/dist/core/schema/builder.mjs +70 -0
  58. package/dist/core/schema/federation.d.mts +34 -0
  59. package/dist/core/schema/federation.mjs +40 -0
  60. package/dist/core/schema/index.d.mts +3 -0
  61. package/dist/core/schema/index.mjs +4 -0
  62. package/dist/core/types/adapter.d.mts +58 -0
  63. package/dist/core/types/codegen.d.mts +133 -0
  64. package/dist/core/types/config.d.mts +210 -0
  65. package/dist/core/types/config.mjs +1 -0
  66. package/dist/{utils/define.d.ts → core/types/define.d.mts} +3 -30
  67. package/dist/core/types/define.mjs +1 -0
  68. package/dist/core/types/index.d.mts +5 -0
  69. package/dist/core/types/index.mjs +1 -0
  70. package/dist/core/types/scanning.d.mts +69 -0
  71. package/dist/core/types/scanning.mjs +1 -0
  72. package/dist/{utils/directive-parser.d.ts → core/utils/directive-parser.d.mts} +21 -4
  73. package/dist/{utils/directive-parser.js → core/utils/directive-parser.mjs} +25 -34
  74. package/dist/core/utils/errors.d.mts +77 -0
  75. package/dist/core/utils/errors.mjs +93 -0
  76. package/dist/core/utils/file-io.d.mts +24 -0
  77. package/dist/core/utils/file-io.mjs +47 -0
  78. package/dist/core/utils/imports.d.mts +15 -0
  79. package/dist/core/utils/imports.mjs +25 -0
  80. package/dist/core/utils/index.d.mts +7 -0
  81. package/dist/core/utils/index.mjs +8 -0
  82. package/dist/core/utils/logger.d.mts +19 -0
  83. package/dist/core/utils/logger.mjs +38 -0
  84. package/dist/core/utils/ofetch-templates.d.mts +30 -0
  85. package/dist/core/utils/ofetch-templates.mjs +135 -0
  86. package/dist/core/validation/external-services.d.mts +11 -0
  87. package/dist/core/validation/external-services.mjs +34 -0
  88. package/dist/core/validation/index.d.mts +2 -0
  89. package/dist/core/validation/index.mjs +3 -0
  90. package/dist/define.d.mts +294 -0
  91. package/dist/define.mjs +323 -0
  92. package/dist/index.d.mts +6 -0
  93. package/dist/index.mjs +6 -0
  94. package/dist/nitro/adapter.d.mts +30 -0
  95. package/dist/nitro/adapter.mjs +97 -0
  96. package/dist/{utils/apollo.d.ts → nitro/apollo.d.mts} +3 -3
  97. package/dist/nitro/apollo.mjs +59 -0
  98. package/dist/nitro/codegen.d.mts +19 -0
  99. package/dist/nitro/codegen.mjs +141 -0
  100. package/dist/nitro/config.d.mts +51 -0
  101. package/dist/nitro/config.mjs +57 -0
  102. package/dist/nitro/index.d.mts +46 -0
  103. package/dist/nitro/index.mjs +65 -0
  104. package/dist/nitro/paths.d.mts +54 -0
  105. package/dist/nitro/paths.mjs +92 -0
  106. package/dist/nitro/rollup.d.mts +6 -0
  107. package/dist/nitro/rollup.mjs +95 -0
  108. package/dist/nitro/routes/apollo-server.d.mts +6 -0
  109. package/dist/nitro/routes/apollo-server.mjs +71 -0
  110. package/dist/nitro/routes/debug-template.d.mts +15 -0
  111. package/dist/nitro/routes/debug-template.mjs +385 -0
  112. package/dist/nitro/routes/debug.d.mts +55 -0
  113. package/dist/nitro/routes/debug.mjs +102 -0
  114. package/dist/nitro/routes/graphql-yoga.d.mts +6 -0
  115. package/dist/nitro/routes/graphql-yoga.mjs +62 -0
  116. package/dist/nitro/routes/health.d.mts +10 -0
  117. package/dist/{routes/health.js → nitro/routes/health.mjs} +4 -3
  118. package/dist/nitro/setup/extend-loader.d.mts +19 -0
  119. package/dist/nitro/setup/extend-loader.mjs +129 -0
  120. package/dist/nitro/setup/file-watcher.d.mts +16 -0
  121. package/dist/nitro/setup/file-watcher.mjs +98 -0
  122. package/dist/nitro/setup/logging.d.mts +17 -0
  123. package/dist/nitro/setup/logging.mjs +66 -0
  124. package/dist/nitro/setup/rollup-integration.d.mts +16 -0
  125. package/dist/nitro/setup/rollup-integration.mjs +90 -0
  126. package/dist/nitro/setup/routes.d.mts +10 -0
  127. package/dist/nitro/setup/routes.mjs +35 -0
  128. package/dist/nitro/setup/ts-config.d.mts +11 -0
  129. package/dist/nitro/setup/ts-config.mjs +69 -0
  130. package/dist/nitro/setup.d.mts +12 -0
  131. package/dist/nitro/setup.mjs +234 -0
  132. package/dist/nitro/types.d.mts +374 -0
  133. package/dist/nitro/types.mjs +1 -0
  134. package/dist/nitro/virtual/generators.d.mts +31 -0
  135. package/dist/nitro/virtual/generators.mjs +113 -0
  136. package/dist/nitro/virtual/stubs.d.mts +20 -0
  137. package/dist/nitro/virtual/stubs.mjs +31 -0
  138. package/dist/{ecosystem/nuxt.d.ts → nuxt.d.mts} +1 -1
  139. package/dist/nuxt.mjs +109 -0
  140. package/dist/{graphql/server.d.ts → stubs/index.d.mts} +5 -1
  141. package/dist/stubs/index.mjs +1 -0
  142. package/package.json +102 -77
  143. package/dist/ecosystem/nuxt.js +0 -67
  144. package/dist/graphql/index.d.ts +0 -5
  145. package/dist/index.d.ts +0 -8
  146. package/dist/index.js +0 -264
  147. package/dist/rollup.js +0 -119
  148. package/dist/routes/apollo-server.d.ts +0 -6
  149. package/dist/routes/apollo-server.js +0 -89
  150. package/dist/routes/graphql-yoga.d.ts +0 -6
  151. package/dist/routes/graphql-yoga.js +0 -91
  152. package/dist/routes/health.d.ts +0 -6
  153. package/dist/types/index.d.ts +0 -128
  154. package/dist/types/standard-schema.d.ts +0 -59
  155. package/dist/utils/apollo.js +0 -61
  156. package/dist/utils/client-codegen.d.ts +0 -38
  157. package/dist/utils/client-codegen.js +0 -290
  158. package/dist/utils/define.js +0 -57
  159. package/dist/utils/index.d.ts +0 -39
  160. package/dist/utils/index.js +0 -250
  161. package/dist/utils/server-codegen.d.ts +0 -7
  162. package/dist/utils/server-codegen.js +0 -136
  163. package/dist/utils/type-generation.d.ts +0 -7
  164. package/dist/utils/type-generation.js +0 -287
  165. package/dist/vite.d.ts +0 -25
  166. package/dist/vite.js +0 -40
  167. /package/dist/{graphql/index.js → core/types/adapter.mjs} +0 -0
  168. /package/dist/{graphql/server.js → core/types/codegen.mjs} +0 -0
@@ -1,287 +0,0 @@
1
- import { downloadAndSaveSchema, generateClientTypes, generateExternalClientTypes, loadExternalSchema, loadGraphQLDocuments } from "./client-codegen.js";
2
- import { generateTypes } from "./server-codegen.js";
3
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
4
- import consola from "consola";
5
- import { basename, dirname, join, resolve } from "pathe";
6
- import { buildSchema, parse } from "graphql";
7
- import { buildSubgraphSchema } from "@apollo/subgraph";
8
- import { loadFilesSync } from "@graphql-tools/load-files";
9
- import { mergeTypeDefs } from "@graphql-tools/merge";
10
- import { printSchemaWithDirectives } from "@graphql-tools/utils";
11
-
12
- //#region src/utils/type-generation.ts
13
- function generateGraphQLIndexFile(clientDir, externalServices = []) {
14
- const indexPath = resolve(clientDir, "index.ts");
15
- if (!existsSync(indexPath)) {
16
- let indexContent = `// This file is auto-generated once by nitro-graphql for quick start
17
- // You can modify this file according to your needs
18
- //
19
- // Export your main GraphQL service (auto-generated)
20
- export * from './default/ofetch'
21
-
22
- // Export external GraphQL services (auto-generated for existing services)
23
- // When you add new external services, don't forget to add their exports here:
24
- // export * from './yourServiceName/ofetch'
25
- `;
26
- for (const service of externalServices) indexContent += `export * from './${service.name}/ofetch'\n`;
27
- writeFileSync(indexPath, indexContent, "utf-8");
28
- }
29
- }
30
- function generateOfetchClient(clientDir, serviceName, endpoint, isDefault = false) {
31
- const serviceDir = resolve(clientDir, serviceName);
32
- const ofetchPath = resolve(serviceDir, "ofetch.ts");
33
- if (!existsSync(serviceDir)) mkdirSync(serviceDir, { recursive: true });
34
- if (existsSync(ofetchPath)) return;
35
- const capitalizedServiceName = serviceName.charAt(0).toUpperCase() + serviceName.slice(1);
36
- const functionName = isDefault ? "createGraphQLClient" : `create${capitalizedServiceName}GraphQLClient`;
37
- const exportName = isDefault ? "$sdk" : `$${serviceName}Sdk`;
38
- writeFileSync(ofetchPath, `// This file is auto-generated once by nitro-graphql for quick start
39
- // You can modify this file according to your needs
40
- import type { ${isDefault ? "Requester" : "Sdk, Requester"} } from './sdk'
41
- import { getSdk } from './sdk'
42
-
43
- export function ${functionName}(endpoint: string${isDefault ? "" : ` = '${endpoint}'`}): Requester {
44
- return async <R>(doc: string, vars?: any): Promise<R> => {
45
- const headers = import.meta.server ? useRequestHeaders() : undefined
46
-
47
- const result = await $fetch(endpoint, {
48
- method: 'POST',
49
- body: { query: doc, variables: vars },
50
- headers: {
51
- 'Content-Type': 'application/json',
52
- ...headers,
53
- },
54
- })
55
-
56
- return result as R
57
- }
58
- }
59
-
60
- export const ${exportName}${isDefault ? "" : ": Sdk"} = getSdk(${functionName}(${isDefault ? "'/api/graphql'" : ""}))`, "utf-8");
61
- }
62
- /**
63
- * Check for duplicate type definitions using a simpler approach
64
- * Try to build each schema individually - if that succeeds but merging fails, we have duplicates
65
- * @returns true if validation passes, false if duplicates found
66
- */
67
- function validateNoDuplicateTypes(schemas, schemaStrings) {
68
- const individualSchemasByFile = /* @__PURE__ */ new Map();
69
- schemaStrings.forEach((schemaContent, index) => {
70
- const schemaPath = schemas[index];
71
- const fileName = basename(schemaPath);
72
- try {
73
- parse(schemaContent);
74
- individualSchemasByFile.set(fileName, schemaContent);
75
- } catch (error) {
76
- consola.warn(`Invalid GraphQL syntax in ${fileName}:`, error);
77
- throw error;
78
- }
79
- });
80
- try {
81
- mergeTypeDefs([schemaStrings.join("\n\n")], {
82
- throwOnConflict: false,
83
- commentDescriptions: true,
84
- sort: true
85
- });
86
- mergeTypeDefs([schemaStrings.join("\n\n")], {
87
- throwOnConflict: true,
88
- commentDescriptions: true,
89
- sort: true
90
- });
91
- } catch (conflictError) {
92
- if (conflictError?.message?.includes("already defined with a different type")) throw conflictError;
93
- }
94
- const typeNames = /* @__PURE__ */ new Set();
95
- const duplicateTypes = [];
96
- schemaStrings.forEach((schemaContent, index) => {
97
- const fileName = basename(schemas[index]);
98
- try {
99
- parse(schemaContent).definitions.forEach((def) => {
100
- if (def.kind === "ObjectTypeDefinition" || def.kind === "InterfaceTypeDefinition" || def.kind === "UnionTypeDefinition" || def.kind === "EnumTypeDefinition" || def.kind === "InputObjectTypeDefinition" || def.kind === "ScalarTypeDefinition") {
101
- const typeName = def.name.value;
102
- if ([
103
- "String",
104
- "Int",
105
- "Float",
106
- "Boolean",
107
- "ID",
108
- "DateTime",
109
- "JSON"
110
- ].includes(typeName)) return;
111
- if (typeNames.has(typeName)) {
112
- const existing = duplicateTypes.find((d) => d.type === typeName);
113
- if (existing) existing.files.push(fileName);
114
- else {
115
- const firstFile = schemas.find((_, i) => {
116
- const content = schemaStrings[i];
117
- if (!content) return false;
118
- try {
119
- return parse(content).definitions.some((d) => (d.kind === "ObjectTypeDefinition" || d.kind === "InterfaceTypeDefinition" || d.kind === "UnionTypeDefinition" || d.kind === "EnumTypeDefinition" || d.kind === "InputObjectTypeDefinition" || d.kind === "ScalarTypeDefinition") && d.name.value === typeName);
120
- } catch {
121
- return false;
122
- }
123
- });
124
- duplicateTypes.push({
125
- type: typeName,
126
- files: [basename(firstFile || ""), fileName]
127
- });
128
- }
129
- } else typeNames.add(typeName);
130
- }
131
- });
132
- } catch {}
133
- });
134
- if (duplicateTypes.length > 0) {
135
- let errorMessage = "⚠️ DUPLICATE TYPE DEFINITIONS DETECTED!\n\n";
136
- duplicateTypes.forEach(({ type, files }) => {
137
- errorMessage += `❌ Type "${type}" is defined in multiple files:\n`;
138
- files.forEach((fileName) => {
139
- const fullPath = schemas.find((path) => basename(path) === fileName) || fileName;
140
- errorMessage += ` • ${fullPath}\n`;
141
- });
142
- errorMessage += "\n";
143
- });
144
- errorMessage += "💡 Each GraphQL type should only be defined once.\n";
145
- errorMessage += " Consider using \"extend type\" syntax instead of duplicate definitions.\n";
146
- errorMessage += `\n🔍 Found ${duplicateTypes.length} duplicate type(s): ${duplicateTypes.map((d) => d.type).join(", ")}`;
147
- consola.error(errorMessage);
148
- return false;
149
- }
150
- return true;
151
- }
152
- async function serverTypeGeneration(app) {
153
- try {
154
- const schemas = app.scanSchemas || [];
155
- if (!schemas.length) {
156
- consola.info("No GraphQL definitions found for server type generation.");
157
- return;
158
- }
159
- const schemaStrings = loadFilesSync(schemas).map((schema$1) => typeof schema$1 === "string" ? schema$1 : schema$1.loc?.source?.body || "").filter(Boolean);
160
- if (!validateNoDuplicateTypes(schemas, schemaStrings)) return;
161
- const federationEnabled = app.options.graphql?.federation?.enabled === true;
162
- const mergedSchemas = mergeTypeDefs([schemaStrings.join("\n\n")], {
163
- throwOnConflict: true,
164
- commentDescriptions: true,
165
- sort: true
166
- });
167
- const schema = federationEnabled ? buildSubgraphSchema([{ typeDefs: parse(mergedSchemas) }]) : buildSchema(mergedSchemas);
168
- const data = await generateTypes(app.options.graphql?.framework || "graphql-yoga", schema, app.options.graphql ?? {});
169
- const printSchema = printSchemaWithDirectives(schema);
170
- const schemaPath = resolve(app.graphql.buildDir, "schema.graphql");
171
- mkdirSync(dirname(schemaPath), { recursive: true });
172
- writeFileSync(schemaPath, printSchema, "utf-8");
173
- const serverTypesPath = resolve(app.options.buildDir, "types", "nitro-graphql-server.d.ts");
174
- mkdirSync(dirname(serverTypesPath), { recursive: true });
175
- writeFileSync(serverTypesPath, data, "utf-8");
176
- } catch (error) {
177
- consola.error("Server schema generation error:", error);
178
- }
179
- }
180
- async function clientTypeGeneration(nitro) {
181
- try {
182
- if (nitro.scanSchemas && nitro.scanSchemas.length > 0) await generateMainClientTypes(nitro);
183
- if (nitro.options.graphql?.externalServices?.length) await generateExternalServicesTypes(nitro);
184
- } catch (error) {
185
- consola.error("Client schema generation error:", error);
186
- }
187
- }
188
- /**
189
- * Check for old structure files and warn user about manual migration
190
- */
191
- function checkOldStructure(clientDir) {
192
- const oldOfetchPath = resolve(clientDir, "ofetch.ts");
193
- const oldSdkPath = resolve(clientDir, "sdk.ts");
194
- if (existsSync(oldOfetchPath) || existsSync(oldSdkPath)) {
195
- const foundFiles = [];
196
- if (existsSync(oldOfetchPath)) foundFiles.push("app/graphql/ofetch.ts");
197
- if (existsSync(oldSdkPath)) foundFiles.push("app/graphql/sdk.ts");
198
- consola.error(`⚠️ OLD GRAPHQL STRUCTURE DETECTED!
199
-
200
- 📁 Found old files in app/graphql/ directory that need to be moved:
201
- • ${foundFiles.join("\n • ")}
202
-
203
- 🔄 Please manually move these files to the new structure:
204
- • app/graphql/ofetch.ts → app/graphql/default/ofetch.ts
205
- • app/graphql/sdk.ts → app/graphql/default/sdk.ts
206
-
207
- 📝 Also update your app/graphql/index.ts to include:
208
- export * from './default/ofetch'
209
-
210
- 💡 After moving, update your imports to use:
211
- import { $sdk } from "#graphql/client"
212
-
213
- 🚫 The old files will cause import conflicts until moved!`);
214
- }
215
- }
216
- async function generateMainClientTypes(nitro) {
217
- checkOldStructure(nitro.graphql.clientDir);
218
- const docs = nitro.scanDocuments;
219
- const loadDocs = await loadGraphQLDocuments(docs);
220
- const schemaFilePath = join(nitro.graphql.buildDir, "schema.graphql");
221
- if (!existsSync(schemaFilePath)) {
222
- consola.info("Schema file not ready yet for client type generation. Server types need to be generated first.");
223
- return;
224
- }
225
- const graphqlString = readFileSync(schemaFilePath, "utf-8");
226
- const types = await generateClientTypes(nitro.options.graphql?.federation?.enabled === true ? buildSubgraphSchema([{ typeDefs: parse(graphqlString) }]) : buildSchema(graphqlString), loadDocs, nitro.options.graphql?.codegen?.client ?? {}, nitro.options.graphql?.codegen?.clientSDK ?? {});
227
- if (types === false) return;
228
- const clientTypesPath = resolve(nitro.options.buildDir, "types", "nitro-graphql-client.d.ts");
229
- const defaultServiceDir = resolve(nitro.graphql.clientDir, "default");
230
- const sdkTypesPath = resolve(defaultServiceDir, "sdk.ts");
231
- mkdirSync(dirname(clientTypesPath), { recursive: true });
232
- writeFileSync(clientTypesPath, types.types, "utf-8");
233
- mkdirSync(defaultServiceDir, { recursive: true });
234
- let shouldWriteSdk = true;
235
- if (existsSync(sdkTypesPath)) shouldWriteSdk = readFileSync(sdkTypesPath, "utf-8") !== types.sdk;
236
- if (shouldWriteSdk) writeFileSync(sdkTypesPath, types.sdk, "utf-8");
237
- if (nitro.options.framework?.name === "nuxt") {
238
- generateOfetchClient(nitro.graphql.clientDir, "default", "/api/graphql", true);
239
- const externalServices = nitro.options.graphql?.externalServices || [];
240
- generateGraphQLIndexFile(nitro.graphql.clientDir, externalServices);
241
- }
242
- }
243
- async function generateExternalServicesTypes(nitro) {
244
- const externalServices = nitro.options.graphql?.externalServices || [];
245
- for (const service of externalServices) try {
246
- consola.info(`[graphql:${service.name}] Processing external service`);
247
- await downloadAndSaveSchema(service, nitro.options.buildDir);
248
- const schema = await loadExternalSchema(service, nitro.options.buildDir);
249
- if (!schema) {
250
- consola.warn(`[graphql:${service.name}] Failed to load schema, skipping`);
251
- continue;
252
- }
253
- const documentPatterns = service.documents || [];
254
- let loadDocs = [];
255
- if (documentPatterns.length > 0) try {
256
- loadDocs = await loadGraphQLDocuments(documentPatterns);
257
- if (!loadDocs || loadDocs.length === 0) {
258
- consola.warn(`[graphql:${service.name}] No GraphQL documents found, skipping service generation`);
259
- continue;
260
- }
261
- } catch (error) {
262
- consola.warn(`[graphql:${service.name}] No documents found, skipping service generation:`, error);
263
- continue;
264
- }
265
- const types = await generateExternalClientTypes(service, schema, loadDocs);
266
- if (types === false) {
267
- consola.warn(`[graphql:${service.name}] Type generation failed`);
268
- continue;
269
- }
270
- const serviceTypesPath = resolve(nitro.options.buildDir, "types", `nitro-graphql-client-${service.name}.d.ts`);
271
- const serviceDir = resolve(nitro.graphql.clientDir, service.name);
272
- const serviceSdkPath = resolve(serviceDir, "sdk.ts");
273
- mkdirSync(dirname(serviceTypesPath), { recursive: true });
274
- writeFileSync(serviceTypesPath, types.types, "utf-8");
275
- mkdirSync(serviceDir, { recursive: true });
276
- let shouldWriteServiceSdk = true;
277
- if (existsSync(serviceSdkPath)) shouldWriteServiceSdk = readFileSync(serviceSdkPath, "utf-8") !== types.sdk;
278
- if (shouldWriteServiceSdk) writeFileSync(serviceSdkPath, types.sdk, "utf-8");
279
- if (nitro.options.framework?.name === "nuxt") generateOfetchClient(nitro.graphql.clientDir, service.name, service.endpoint, false);
280
- consola.success(`[graphql:${service.name}] External service types generated successfully`);
281
- } catch (error) {
282
- consola.error(`[graphql:${service.name}] External service generation failed:`, error);
283
- }
284
- }
285
-
286
- //#endregion
287
- export { clientTypeGeneration, serverTypeGeneration };
package/dist/vite.d.ts DELETED
@@ -1,25 +0,0 @@
1
- import { Plugin } from "vite";
2
-
3
- //#region src/vite.d.ts
4
-
5
- /**
6
- * Vite plugin to load GraphQL files as strings
7
- * This prevents Vite from trying to parse .graphql/.gql files as JavaScript
8
- *
9
- * @example
10
- * ```ts
11
- * import { defineConfig } from 'vite'
12
- * import { nitro } from 'nitro/vite'
13
- * import { graphql } from 'nitro-graphql/vite'
14
- *
15
- * export default defineConfig({
16
- * plugins: [
17
- * graphql(), // Must be before nitro()
18
- * nitro()
19
- * ]
20
- * })
21
- * ```
22
- */
23
- declare function graphql(): Plugin;
24
- //#endregion
25
- export { graphql };
package/dist/vite.js DELETED
@@ -1,40 +0,0 @@
1
- import { readFile } from "node:fs/promises";
2
-
3
- //#region src/vite.ts
4
- /**
5
- * Vite plugin to load GraphQL files as strings
6
- * This prevents Vite from trying to parse .graphql/.gql files as JavaScript
7
- *
8
- * @example
9
- * ```ts
10
- * import { defineConfig } from 'vite'
11
- * import { nitro } from 'nitro/vite'
12
- * import { graphql } from 'nitro-graphql/vite'
13
- *
14
- * export default defineConfig({
15
- * plugins: [
16
- * graphql(), // Must be before nitro()
17
- * nitro()
18
- * ]
19
- * })
20
- * ```
21
- */
22
- function graphql() {
23
- return {
24
- name: "nitro-graphql:vite",
25
- enforce: "pre",
26
- async load(id) {
27
- if (!/\.(?:graphql|gql)$/i.test(id)) return null;
28
- try {
29
- const content = await readFile(id, "utf-8");
30
- return `export default ${JSON.stringify(content)}`;
31
- } catch (error) {
32
- if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") return null;
33
- throw error;
34
- }
35
- }
36
- };
37
- }
38
-
39
- //#endregion
40
- export { graphql };