nitro-graphql 1.5.1 → 1.5.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
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
# Nitro GraphQL
|
|
2
|
-
|
|
3
1
|
<div align="center">
|
|
4
2
|
|
|
3
|
+
<img src="./.docs/public/logo.svg" alt="Nitro GraphQL Logo" width="120" height="120">
|
|
4
|
+
|
|
5
|
+
# Nitro GraphQL
|
|
6
|
+
|
|
5
7
|
[![npm version][npm-version-src]][npm-version-href]
|
|
6
8
|
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
7
9
|
[![bundle][bundle-src]][bundle-href]
|
|
8
10
|
[![License][license-src]][license-href]
|
|
11
|
+
[![Documentation][docs-src]][docs-href]
|
|
9
12
|
|
|
10
13
|
**The easiest way to add GraphQL to any Nitro application**
|
|
11
14
|
|
|
12
15
|
🚀 **Auto-discovery** • 📝 **Type Generation** • 🎮 **Apollo Sandbox** • 🔧 **Zero Config**
|
|
13
16
|
|
|
14
|
-
[
|
|
17
|
+
[📚 Documentation](https://nitro-graphql.pages.dev) • [Quick Start](#-quick-start) • [Examples](#-examples) • [Community](#-community)
|
|
15
18
|
|
|
16
19
|
</div>
|
|
17
20
|
|
|
@@ -1215,4 +1218,6 @@ pnpm lint
|
|
|
1215
1218
|
[bundle-src]: https://deno.bundlejs.com/badge?q=nitro-graphql@0.0.4
|
|
1216
1219
|
[bundle-href]: https://deno.bundlejs.com/badge?q=nitro-graphql@0.0.4
|
|
1217
1220
|
[license-src]: https://img.shields.io/github/license/productdevbook/nitro-graphql.svg?style=flat&colorA=080f12&colorB=1fa669
|
|
1218
|
-
[license-href]: https://github.com/productdevbook/nitro-graphql/blob/main/LICENSE
|
|
1221
|
+
[license-href]: https://github.com/productdevbook/nitro-graphql/blob/main/LICENSE
|
|
1222
|
+
[docs-src]: https://img.shields.io/badge/docs-read-blue?style=flat&colorA=080f12&colorB=1fa669
|
|
1223
|
+
[docs-href]: https://nitro-graphql.pages.dev
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { generateDirectiveSchemas } from "./utils/directive-parser.js";
|
|
2
2
|
import { generateLayerIgnorePatterns, getLayerAppDirectories, getLayerServerDirectories, relativeWithDot, scanDirectives, scanDocs, scanResolvers, scanSchemas, validateExternalServices } from "./utils/index.js";
|
|
3
3
|
import { writeFileIfNotExists } from "./utils/file-generator.js";
|
|
4
|
-
import { getDefaultPaths, getScaffoldConfig, resolveFilePath, shouldGenerateScaffold } from "./utils/path-resolver.js";
|
|
4
|
+
import { getDefaultPaths, getScaffoldConfig, getTypesConfig, resolveFilePath, shouldGenerateScaffold } from "./utils/path-resolver.js";
|
|
5
5
|
import { clientTypeGeneration, serverTypeGeneration } from "./utils/type-generation.js";
|
|
6
6
|
import { rollupConfig } from "./rollup.js";
|
|
7
7
|
import { existsSync, mkdirSync } from "node:fs";
|
|
@@ -99,7 +99,6 @@ var src_default = defineNitroModule({
|
|
|
99
99
|
watcher.close();
|
|
100
100
|
});
|
|
101
101
|
const tsconfigDir = dirname(resolve(nitro.options.buildDir, nitro.options.typescript.tsconfigPath));
|
|
102
|
-
const typesDir = resolve(nitro.options.buildDir, "types");
|
|
103
102
|
nitro.scanSchemas = await scanSchemas(nitro);
|
|
104
103
|
nitro.scanDocuments = await scanDocs(nitro);
|
|
105
104
|
nitro.scanResolvers = await scanResolvers(nitro);
|
|
@@ -226,13 +225,33 @@ var src_default = defineNitroModule({
|
|
|
226
225
|
types.tsConfig ||= {};
|
|
227
226
|
types.tsConfig.compilerOptions ??= {};
|
|
228
227
|
types.tsConfig.compilerOptions.paths ??= {};
|
|
229
|
-
|
|
230
|
-
|
|
228
|
+
const placeholders = getDefaultPaths(nitro);
|
|
229
|
+
const typesConfig = getTypesConfig(nitro);
|
|
230
|
+
const serverTypesPath = resolveFilePath(typesConfig.server, typesConfig.enabled, true, "{typesDir}/nitro-graphql-server.d.ts", placeholders);
|
|
231
|
+
if (serverTypesPath) types.tsConfig.compilerOptions.paths["#graphql/server"] = [relativeWithDot(tsconfigDir, serverTypesPath)];
|
|
232
|
+
const clientTypesPath = resolveFilePath(typesConfig.client, typesConfig.enabled, true, "{typesDir}/nitro-graphql-client.d.ts", placeholders);
|
|
233
|
+
if (clientTypesPath) types.tsConfig.compilerOptions.paths["#graphql/client"] = [relativeWithDot(tsconfigDir, clientTypesPath)];
|
|
231
234
|
types.tsConfig.compilerOptions.paths["#graphql/schema"] = [relativeWithDot(tsconfigDir, join(nitro.graphql.serverDir, "schema.ts"))];
|
|
232
|
-
if (nitro.options.graphql?.externalServices?.length) for (const service of nitro.options.graphql.externalServices)
|
|
235
|
+
if (nitro.options.graphql?.externalServices?.length) for (const service of nitro.options.graphql.externalServices) {
|
|
236
|
+
const servicePlaceholders = {
|
|
237
|
+
...placeholders,
|
|
238
|
+
serviceName: service.name
|
|
239
|
+
};
|
|
240
|
+
const externalTypesPath = resolveFilePath(service.paths?.types ?? typesConfig.external, typesConfig.enabled, true, "{typesDir}/nitro-graphql-client-{serviceName}.d.ts", servicePlaceholders);
|
|
241
|
+
if (externalTypesPath) types.tsConfig.compilerOptions.paths[`#graphql/client/${service.name}`] = [relativeWithDot(tsconfigDir, externalTypesPath)];
|
|
242
|
+
}
|
|
233
243
|
types.tsConfig.include = types.tsConfig.include || [];
|
|
234
|
-
types.tsConfig.include.push(relativeWithDot(tsconfigDir,
|
|
235
|
-
if (
|
|
244
|
+
if (serverTypesPath) types.tsConfig.include.push(relativeWithDot(tsconfigDir, serverTypesPath));
|
|
245
|
+
if (clientTypesPath) types.tsConfig.include.push(relativeWithDot(tsconfigDir, clientTypesPath));
|
|
246
|
+
types.tsConfig.include.push(relativeWithDot(tsconfigDir, join(placeholders.typesDir, "graphql.d.ts")));
|
|
247
|
+
if (nitro.options.graphql?.externalServices?.length) for (const service of nitro.options.graphql.externalServices) {
|
|
248
|
+
const servicePlaceholders = {
|
|
249
|
+
...placeholders,
|
|
250
|
+
serviceName: service.name
|
|
251
|
+
};
|
|
252
|
+
const externalTypesPath = resolveFilePath(service.paths?.types ?? typesConfig.external, typesConfig.enabled, true, "{typesDir}/nitro-graphql-client-{serviceName}.d.ts", servicePlaceholders);
|
|
253
|
+
if (externalTypesPath) types.tsConfig.include.push(relativeWithDot(tsconfigDir, externalTypesPath));
|
|
254
|
+
}
|
|
236
255
|
});
|
|
237
256
|
if (nitro.options.framework?.name === "nuxt" && nitro.options.graphql?.externalServices?.length) nitro.hooks.hook("build:before", () => {
|
|
238
257
|
const nuxtOptions = nitro._nuxt?.options;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as h31 from "h3";
|
|
2
2
|
|
|
3
3
|
//#region src/routes/apollo-server.d.ts
|
|
4
|
-
declare const _default:
|
|
4
|
+
declare const _default: h31.EventHandler<h31.EventHandlerRequest, Promise<any>>;
|
|
5
5
|
//#endregion
|
|
6
6
|
export { _default as default };
|
package/dist/routes/debug.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as h35 from "h3";
|
|
2
2
|
|
|
3
3
|
//#region src/routes/debug.d.ts
|
|
4
4
|
|
|
@@ -10,7 +10,7 @@ import * as h31 from "h3";
|
|
|
10
10
|
* - /_nitro/graphql/debug - HTML dashboard
|
|
11
11
|
* - /_nitro/graphql/debug?format=json - JSON API
|
|
12
12
|
*/
|
|
13
|
-
declare const _default:
|
|
13
|
+
declare const _default: h35.EventHandler<h35.EventHandlerRequest, Promise<string | {
|
|
14
14
|
timestamp: string;
|
|
15
15
|
environment: {
|
|
16
16
|
dev: any;
|
|
@@ -23,14 +23,14 @@ declare function loadExternalSchema(service: ExternalGraphQLService, buildDir?:
|
|
|
23
23
|
*/
|
|
24
24
|
declare function downloadAndSaveSchema(service: ExternalGraphQLService, buildDir: string): Promise<string | undefined>;
|
|
25
25
|
declare function loadGraphQLDocuments(patterns: string | string[]): Promise<Source[]>;
|
|
26
|
-
declare function generateClientTypes(schema: GraphQLSchema, docs: Source[], config?: CodegenClientConfig, sdkConfig?: GenericSdkConfig, outputPath?: string, serviceName?: string): Promise<false | {
|
|
26
|
+
declare function generateClientTypes(schema: GraphQLSchema, docs: Source[], config?: CodegenClientConfig, sdkConfig?: GenericSdkConfig, outputPath?: string, serviceName?: string, virtualTypesPath?: string): Promise<false | {
|
|
27
27
|
types: string;
|
|
28
28
|
sdk: string;
|
|
29
29
|
}>;
|
|
30
30
|
/**
|
|
31
31
|
* Generate client types for external GraphQL service
|
|
32
32
|
*/
|
|
33
|
-
declare function generateExternalClientTypes(service: ExternalGraphQLService, schema: GraphQLSchema, docs: Source[]): Promise<{
|
|
33
|
+
declare function generateExternalClientTypes(service: ExternalGraphQLService, schema: GraphQLSchema, docs: Source[], virtualTypesPath?: string): Promise<{
|
|
34
34
|
types: string;
|
|
35
35
|
sdk: string;
|
|
36
36
|
} | false>;
|
|
@@ -165,7 +165,7 @@ async function loadGraphQLDocuments(patterns) {
|
|
|
165
165
|
else throw e;
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
|
-
async function generateClientTypes(schema, docs, config = {}, sdkConfig = {}, outputPath, serviceName) {
|
|
168
|
+
async function generateClientTypes(schema, docs, config = {}, sdkConfig = {}, outputPath, serviceName, virtualTypesPath) {
|
|
169
169
|
if (docs.length === 0 && !serviceName) {
|
|
170
170
|
consola$1.info("No client GraphQL files found. Skipping client type generation.");
|
|
171
171
|
return false;
|
|
@@ -252,7 +252,7 @@ export function getSdk(requester: Requester): Sdk {
|
|
|
252
252
|
typescriptOperations: { plugin: plugin$2 }
|
|
253
253
|
}
|
|
254
254
|
});
|
|
255
|
-
const typesPath = serviceName ? `#graphql/client/${serviceName}` : "#graphql/client";
|
|
255
|
+
const typesPath = virtualTypesPath || (serviceName ? `#graphql/client/${serviceName}` : "#graphql/client");
|
|
256
256
|
const sdkOutput = await preset.buildGeneratesSection({
|
|
257
257
|
baseOutputDir: outputPath || "client-types.generated.ts",
|
|
258
258
|
schema: parse(printSchemaWithDirectives(schema)),
|
|
@@ -282,8 +282,8 @@ export function getSdk(requester: Requester): Sdk {
|
|
|
282
282
|
/**
|
|
283
283
|
* Generate client types for external GraphQL service
|
|
284
284
|
*/
|
|
285
|
-
async function generateExternalClientTypes(service, schema, docs) {
|
|
286
|
-
return generateClientTypes(schema, docs, service.codegen?.client || {}, service.codegen?.clientSDK || {}, void 0, service.name);
|
|
285
|
+
async function generateExternalClientTypes(service, schema, docs, virtualTypesPath) {
|
|
286
|
+
return generateClientTypes(schema, docs, service.codegen?.client || {}, service.codegen?.clientSDK || {}, void 0, service.name, virtualTypesPath);
|
|
287
287
|
}
|
|
288
288
|
|
|
289
289
|
//#endregion
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { resolve } from "pathe";
|
|
1
|
+
import { isAbsolute, resolve } from "pathe";
|
|
2
2
|
|
|
3
3
|
//#region src/utils/path-resolver.ts
|
|
4
4
|
/**
|
|
@@ -49,7 +49,7 @@ function resolveFilePath(config, categoryEnabled, topLevelEnabled, defaultPath,
|
|
|
49
49
|
if (!shouldGenerateFile(config, categoryEnabled, topLevelEnabled)) return null;
|
|
50
50
|
if (typeof config === "string") {
|
|
51
51
|
const customPath = replacePlaceholders(config, placeholders);
|
|
52
|
-
return resolve(placeholders.rootDir, customPath);
|
|
52
|
+
return isAbsolute(customPath) ? customPath : resolve(placeholders.rootDir, customPath);
|
|
53
53
|
}
|
|
54
54
|
const resolvedDefault = replacePlaceholders(defaultPath, placeholders);
|
|
55
55
|
return resolve(placeholders.rootDir, resolvedDefault);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nitro-graphql",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.5.
|
|
4
|
+
"version": "1.5.3",
|
|
5
5
|
"description": "GraphQL integration for Nitro",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"sideEffects": false,
|
|
@@ -117,7 +117,8 @@
|
|
|
117
117
|
"h3": "1.15.3",
|
|
118
118
|
"nitropack": "^2.12.7",
|
|
119
119
|
"tsdown": "^0.15.9",
|
|
120
|
-
"typescript": "^5.9.3"
|
|
120
|
+
"typescript": "^5.9.3",
|
|
121
|
+
"vitepress-plugin-llms": "^1.8.1"
|
|
121
122
|
},
|
|
122
123
|
"resolutions": {
|
|
123
124
|
"nitro-graphql": "link:."
|
|
@@ -130,6 +131,9 @@
|
|
|
130
131
|
"playground:nitro": "cd playgrounds/nitro && pnpm install && pnpm dev",
|
|
131
132
|
"playground:nuxt": "cd playgrounds/nuxt && pnpm install && pnpm dev",
|
|
132
133
|
"playground:federation": "cd playgrounds/federation && pnpm install && pnpm dev",
|
|
134
|
+
"docs:dev": "cd .docs && pnpm install && pnpm dev",
|
|
135
|
+
"docs:build": "cd .docs && pnpm install && pnpm build",
|
|
136
|
+
"docs:preview": "cd .docs && pnpm preview",
|
|
133
137
|
"lint": "eslint .",
|
|
134
138
|
"lint:fix": "eslint . --fix"
|
|
135
139
|
}
|