nitro-graphql 2.0.0-beta.2 → 2.0.0-beta.20
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 +855 -5
- package/dist/ecosystem/nuxt.mjs +109 -0
- package/dist/index.d.mts +12 -0
- package/dist/index.mjs +16 -0
- package/dist/rollup.d.mts +12 -0
- package/dist/rollup.mjs +282 -0
- package/dist/routes/apollo-server.d.mts +6 -0
- package/dist/routes/{apollo-server.js → apollo-server.mjs} +5 -5
- package/dist/routes/debug.d.mts +61 -0
- package/dist/routes/debug.mjs +445 -0
- package/dist/routes/graphql-yoga.d.mts +6 -0
- package/dist/routes/{graphql-yoga.js → graphql-yoga.mjs} +5 -5
- package/dist/routes/health.d.mts +10 -0
- package/dist/routes/{health.js → health.mjs} +1 -0
- package/dist/setup.d.mts +11 -0
- package/dist/setup.mjs +390 -0
- package/dist/types/index.d.mts +246 -0
- package/dist/utils/{apollo.js → apollo.mjs} +2 -2
- package/dist/utils/{client-codegen.d.ts → client-codegen.d.mts} +3 -3
- package/dist/utils/{client-codegen.js → client-codegen.mjs} +4 -4
- package/dist/utils/file-generator.d.mts +37 -0
- package/dist/utils/file-generator.mjs +72 -0
- package/dist/utils/{index.d.ts → index.d.mts} +2 -2
- package/dist/utils/{index.js → index.mjs} +63 -35
- package/dist/utils/path-resolver.d.mts +70 -0
- package/dist/utils/path-resolver.mjs +127 -0
- package/dist/utils/{server-codegen.d.ts → server-codegen.d.mts} +1 -1
- package/dist/utils/{server-codegen.js → server-codegen.mjs} +1 -1
- package/dist/utils/{type-generation.js → type-generation.mjs} +153 -42
- package/dist/virtual/debug-info.d.mts +9 -0
- package/dist/virtual/debug-info.mjs +26 -0
- package/dist/virtual/graphql-config.d.mts +9 -0
- package/dist/virtual/graphql-config.mjs +10 -0
- package/dist/virtual/module-config.d.mts +9 -0
- package/dist/virtual/module-config.mjs +10 -0
- package/dist/virtual/server-directives.d.mts +11 -0
- package/dist/virtual/server-directives.mjs +10 -0
- package/dist/virtual/server-resolvers.d.mts +11 -0
- package/dist/virtual/server-resolvers.mjs +10 -0
- package/dist/virtual/server-schemas.d.mts +11 -0
- package/dist/virtual/server-schemas.mjs +10 -0
- package/dist/vite.d.mts +27 -0
- package/dist/vite.mjs +49 -0
- package/package.json +72 -58
- package/dist/ecosystem/nuxt.js +0 -67
- package/dist/index.d.ts +0 -8
- package/dist/index.js +0 -264
- package/dist/rollup.js +0 -114
- package/dist/routes/apollo-server.d.ts +0 -6
- package/dist/routes/graphql-yoga.d.ts +0 -6
- package/dist/routes/health.d.ts +0 -6
- package/dist/types/index.d.ts +0 -128
- /package/dist/ecosystem/{nuxt.d.ts → nuxt.d.mts} +0 -0
- /package/dist/graphql/{index.d.ts → index.d.mts} +0 -0
- /package/dist/graphql/{index.js → index.mjs} +0 -0
- /package/dist/graphql/{server.d.ts → server.d.mts} +0 -0
- /package/dist/graphql/{server.js → server.mjs} +0 -0
- /package/dist/types/{standard-schema.d.ts → standard-schema.d.mts} +0 -0
- /package/dist/utils/{apollo.d.ts → apollo.d.mts} +0 -0
- /package/dist/utils/{define.d.ts → define.d.mts} +0 -0
- /package/dist/utils/{define.js → define.mjs} +0 -0
- /package/dist/utils/{directive-parser.d.ts → directive-parser.d.mts} +0 -0
- /package/dist/utils/{directive-parser.js → directive-parser.mjs} +0 -0
- /package/dist/utils/{type-generation.d.ts → type-generation.d.mts} +0 -0
package/package.json
CHANGED
|
@@ -1,60 +1,68 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nitro-graphql",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.20",
|
|
5
5
|
"description": "GraphQL integration for Nitro",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"sideEffects": false,
|
|
8
8
|
"imports": {
|
|
9
9
|
"#graphql/server": {
|
|
10
|
-
"types": "./dist/graphql/server.d.
|
|
11
|
-
"import": "./dist/graphql/server.
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
"exports": {
|
|
15
|
-
".": {
|
|
16
|
-
"types": "./dist/index.d.ts",
|
|
17
|
-
"import": "./dist/index.js"
|
|
10
|
+
"types": "./dist/graphql/server.d.mts",
|
|
11
|
+
"import": "./dist/graphql/server.mjs"
|
|
18
12
|
},
|
|
19
|
-
"
|
|
20
|
-
"types": "./dist/
|
|
21
|
-
"import": "./dist/
|
|
13
|
+
"#nitro-graphql/graphql-config": {
|
|
14
|
+
"types": "./dist/virtual/graphql-config.d.mts",
|
|
15
|
+
"import": "./dist/virtual/graphql-config.mjs"
|
|
22
16
|
},
|
|
23
|
-
"
|
|
24
|
-
"types": "./dist/
|
|
25
|
-
"import": "./dist/
|
|
17
|
+
"#nitro-graphql/server-schemas": {
|
|
18
|
+
"types": "./dist/virtual/server-schemas.d.mts",
|
|
19
|
+
"import": "./dist/virtual/server-schemas.mjs"
|
|
26
20
|
},
|
|
27
|
-
"
|
|
28
|
-
"types": "./dist/
|
|
29
|
-
"import": "./dist/
|
|
21
|
+
"#nitro-graphql/server-resolvers": {
|
|
22
|
+
"types": "./dist/virtual/server-resolvers.d.mts",
|
|
23
|
+
"import": "./dist/virtual/server-resolvers.mjs"
|
|
30
24
|
},
|
|
31
|
-
"
|
|
32
|
-
"types": "./dist/
|
|
33
|
-
"import": "./dist/
|
|
25
|
+
"#nitro-graphql/server-directives": {
|
|
26
|
+
"types": "./dist/virtual/server-directives.d.mts",
|
|
27
|
+
"import": "./dist/virtual/server-directives.mjs"
|
|
28
|
+
},
|
|
29
|
+
"#nitro-graphql/module-config": {
|
|
30
|
+
"types": "./dist/virtual/module-config.d.mts",
|
|
31
|
+
"import": "./dist/virtual/module-config.mjs"
|
|
32
|
+
},
|
|
33
|
+
"#nitro-graphql/debug-info": {
|
|
34
|
+
"types": "./dist/virtual/debug-info.d.mts",
|
|
35
|
+
"import": "./dist/virtual/debug-info.mjs"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"exports": {
|
|
39
|
+
".": {
|
|
40
|
+
"types": "./dist/index.d.mts",
|
|
41
|
+
"import": "./dist/index.mjs"
|
|
34
42
|
},
|
|
35
43
|
"./utils": {
|
|
36
|
-
"types": "./dist/utils/index.d.
|
|
37
|
-
"import": "./dist/utils/index.
|
|
44
|
+
"types": "./dist/utils/index.d.mts",
|
|
45
|
+
"import": "./dist/utils/index.mjs"
|
|
38
46
|
},
|
|
39
47
|
"./utils/define": {
|
|
40
|
-
"types": "./dist/utils/define.d.
|
|
41
|
-
"import": "./dist/utils/define.
|
|
48
|
+
"types": "./dist/utils/define.d.mts",
|
|
49
|
+
"import": "./dist/utils/define.mjs"
|
|
42
50
|
},
|
|
43
51
|
"./utils/apollo": {
|
|
44
|
-
"types": "./dist/utils/apollo.d.
|
|
45
|
-
"import": "./dist/utils/apollo.
|
|
46
|
-
},
|
|
47
|
-
"./internal": {
|
|
48
|
-
"types": "./dist/internal/index.d.ts",
|
|
49
|
-
"import": "./dist/internal/index.js"
|
|
52
|
+
"types": "./dist/utils/apollo.d.mts",
|
|
53
|
+
"import": "./dist/utils/apollo.mjs"
|
|
50
54
|
},
|
|
51
55
|
"./nuxt": {
|
|
52
|
-
"types": "./dist/ecosystem/nuxt.d.
|
|
53
|
-
"import": "./dist/ecosystem/nuxt.
|
|
56
|
+
"types": "./dist/ecosystem/nuxt.d.mts",
|
|
57
|
+
"import": "./dist/ecosystem/nuxt.mjs"
|
|
58
|
+
},
|
|
59
|
+
"./vite": {
|
|
60
|
+
"types": "./dist/vite.d.mts",
|
|
61
|
+
"import": "./dist/vite.mjs"
|
|
54
62
|
}
|
|
55
63
|
},
|
|
56
|
-
"module": "./dist/index.
|
|
57
|
-
"types": "./dist/index.d.
|
|
64
|
+
"module": "./dist/index.mjs",
|
|
65
|
+
"types": "./dist/index.d.mts",
|
|
58
66
|
"files": [
|
|
59
67
|
"dist"
|
|
60
68
|
],
|
|
@@ -78,46 +86,48 @@
|
|
|
78
86
|
}
|
|
79
87
|
},
|
|
80
88
|
"dependencies": {
|
|
81
|
-
"@apollo/subgraph": "^2.11.
|
|
89
|
+
"@apollo/subgraph": "^2.11.4",
|
|
82
90
|
"@graphql-codegen/core": "^5.0.0",
|
|
83
91
|
"@graphql-codegen/import-types-preset": "^3.0.1",
|
|
84
|
-
"@graphql-codegen/typescript": "^5.0.
|
|
92
|
+
"@graphql-codegen/typescript": "^5.0.2",
|
|
85
93
|
"@graphql-codegen/typescript-generic-sdk": "^4.0.2",
|
|
86
|
-
"@graphql-codegen/typescript-operations": "^5.0.
|
|
87
|
-
"@graphql-codegen/typescript-resolvers": "^5.0
|
|
88
|
-
"@graphql-tools/graphql-file-loader": "^8.1.
|
|
89
|
-
"@graphql-tools/load": "^8.1.
|
|
94
|
+
"@graphql-codegen/typescript-operations": "^5.0.2",
|
|
95
|
+
"@graphql-codegen/typescript-resolvers": "^5.1.0",
|
|
96
|
+
"@graphql-tools/graphql-file-loader": "^8.1.4",
|
|
97
|
+
"@graphql-tools/load": "^8.1.4",
|
|
90
98
|
"@graphql-tools/load-files": "^7.0.1",
|
|
91
|
-
"@graphql-tools/merge": "^9.1.
|
|
92
|
-
"@graphql-tools/schema": "^10.0.
|
|
93
|
-
"@graphql-tools/url-loader": "^9.0.
|
|
94
|
-
"@graphql-tools/utils": "^10.
|
|
99
|
+
"@graphql-tools/merge": "^9.1.3",
|
|
100
|
+
"@graphql-tools/schema": "^10.0.27",
|
|
101
|
+
"@graphql-tools/url-loader": "^9.0.2",
|
|
102
|
+
"@graphql-tools/utils": "^10.10.1",
|
|
95
103
|
"chokidar": "^4.0.3",
|
|
96
104
|
"consola": "^3.4.2",
|
|
97
105
|
"defu": "^6.1.4",
|
|
98
106
|
"graphql-config": "^5.1.5",
|
|
99
|
-
"graphql-scalars": "^1.
|
|
107
|
+
"graphql-scalars": "^1.25.0",
|
|
100
108
|
"knitwork": "^1.2.0",
|
|
101
109
|
"ohash": "^2.0.11",
|
|
102
|
-
"oxc-parser": "^0.
|
|
110
|
+
"oxc-parser": "^0.96.0",
|
|
103
111
|
"pathe": "^2.0.3",
|
|
104
112
|
"tinyglobby": "^0.2.15"
|
|
105
113
|
},
|
|
106
114
|
"devDependencies": {
|
|
107
|
-
"@antfu/eslint-config": "^
|
|
108
|
-
"@nuxt/kit": "^4.1
|
|
109
|
-
"@nuxt/schema": "^4.1
|
|
110
|
-
"@types/node": "^24.
|
|
111
|
-
"bumpp": "^10.
|
|
115
|
+
"@antfu/eslint-config": "^6.2.0",
|
|
116
|
+
"@nuxt/kit": "^4.2.1",
|
|
117
|
+
"@nuxt/schema": "^4.2.1",
|
|
118
|
+
"@types/node": "^24.10.0",
|
|
119
|
+
"bumpp": "^10.3.1",
|
|
112
120
|
"changelogen": "^0.6.2",
|
|
113
121
|
"crossws": "0.3.5",
|
|
114
|
-
"eslint": "^9.
|
|
122
|
+
"eslint": "^9.39.1",
|
|
115
123
|
"graphql": "16.11.0",
|
|
116
|
-
"graphql-yoga": "^5.16.
|
|
117
|
-
"h3": "^2.0.1-rc.
|
|
124
|
+
"graphql-yoga": "^5.16.2",
|
|
125
|
+
"h3": "^2.0.1-rc.5",
|
|
118
126
|
"nitro": "^3.0.1-alpha.0",
|
|
119
|
-
"tsdown": "^0.
|
|
120
|
-
"typescript": "^5.9.3"
|
|
127
|
+
"tsdown": "^0.16.1",
|
|
128
|
+
"typescript": "^5.9.3",
|
|
129
|
+
"vite": "^7.2.2",
|
|
130
|
+
"vitepress-plugin-llms": "^1.9.1"
|
|
121
131
|
},
|
|
122
132
|
"resolutions": {
|
|
123
133
|
"nitro-graphql": "link:."
|
|
@@ -130,7 +140,11 @@
|
|
|
130
140
|
"playground:nitro": "cd playgrounds/nitro && pnpm install && pnpm dev",
|
|
131
141
|
"playground:nuxt": "cd playgrounds/nuxt && pnpm install && pnpm dev",
|
|
132
142
|
"playground:federation": "cd playgrounds/federation && pnpm install && pnpm dev",
|
|
143
|
+
"docs:dev": "cd .docs && pnpm install && pnpm dev",
|
|
144
|
+
"docs:build": "cd .docs && pnpm install && pnpm build",
|
|
145
|
+
"docs:preview": "cd .docs && pnpm preview",
|
|
133
146
|
"lint": "eslint .",
|
|
134
|
-
"lint:fix": "eslint . --fix"
|
|
147
|
+
"lint:fix": "eslint . --fix",
|
|
148
|
+
"test:types": "tsc --noEmit"
|
|
135
149
|
}
|
|
136
150
|
}
|
package/dist/ecosystem/nuxt.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
-
import { join, resolve } from "pathe";
|
|
3
|
-
import { defineNuxtModule, getLayerDirectories } from "@nuxt/kit";
|
|
4
|
-
|
|
5
|
-
//#region src/ecosystem/nuxt.ts
|
|
6
|
-
var nuxt_default = defineNuxtModule({
|
|
7
|
-
meta: {
|
|
8
|
-
name: "nitro-graphql-nuxt",
|
|
9
|
-
configKey: "nitro-graphql-nuxt",
|
|
10
|
-
compatibility: { nuxt: ">=3.16.0" }
|
|
11
|
-
},
|
|
12
|
-
setup: async (_options, nuxt) => {
|
|
13
|
-
nuxt.hooks.hook("prepare:types", (options) => {
|
|
14
|
-
options.references.push({ path: "types/nitro-graphql-client.d.ts" });
|
|
15
|
-
options.tsConfig ??= {};
|
|
16
|
-
options.tsConfig.compilerOptions ??= {};
|
|
17
|
-
options.tsConfig.compilerOptions.paths ??= {};
|
|
18
|
-
options.tsConfig.compilerOptions.paths["#graphql/client"] = ["./types/nitro-graphql-client.d.ts"];
|
|
19
|
-
const externalServices$1 = nuxt.options.nitro?.graphql?.externalServices || [];
|
|
20
|
-
for (const service of externalServices$1) {
|
|
21
|
-
options.references.push({ path: `types/nitro-graphql-client-${service.name}.d.ts` });
|
|
22
|
-
options.tsConfig.compilerOptions.paths[`#graphql/client/${service.name}`] = [`./types/nitro-graphql-client-${service.name}.d.ts`];
|
|
23
|
-
}
|
|
24
|
-
options.tsConfig.include = options.tsConfig.include || [];
|
|
25
|
-
options.tsConfig.include.push("./types/nitro-graphql-client.d.ts");
|
|
26
|
-
for (const service of externalServices$1) options.tsConfig.include.push(`./types/nitro-graphql-client-${service.name}.d.ts`);
|
|
27
|
-
});
|
|
28
|
-
nuxt.options.alias = nuxt.options.alias || {};
|
|
29
|
-
nuxt.options.alias["#graphql/client"] = join(nuxt.options.buildDir, "types/nitro-graphql-client.d.ts");
|
|
30
|
-
const externalServices = nuxt.options.nitro?.graphql?.externalServices || [];
|
|
31
|
-
for (const service of externalServices) nuxt.options.alias[`#graphql/client/${service.name}`] = join(nuxt.options.buildDir, `types/nitro-graphql-client-${service.name}.d.ts`);
|
|
32
|
-
nuxt.hook("imports:dirs", (dirs) => {
|
|
33
|
-
const graphqlServerPath = nuxt.options.nitro?.graphql?.serverDir || resolve(nuxt.options.srcDir, "graphql");
|
|
34
|
-
dirs.push(graphqlServerPath);
|
|
35
|
-
});
|
|
36
|
-
nuxt.hook("nitro:config", async (nitroConfig) => {
|
|
37
|
-
const clientDir = join(nuxt.options.buildDir, "graphql");
|
|
38
|
-
const layerDirs = await getLayerDirectories(nuxt);
|
|
39
|
-
const layerDirectories = layerDirs.map((layer) => layer.root.replace(/\/$/, "")).filter((root) => root !== nuxt.options.rootDir);
|
|
40
|
-
const layerServerDirs = layerDirs.filter((layer) => layer.root !== `${nuxt.options.rootDir}/`).map((layer) => layer.server?.replace(/\/$/, "")).filter(Boolean);
|
|
41
|
-
const layerAppDirs = layerDirs.filter((layer) => layer.root !== `${nuxt.options.rootDir}/`).map((layer) => layer.app?.replace(/\/$/, "")).filter(Boolean);
|
|
42
|
-
if (!nitroConfig.graphql) nitroConfig.graphql = {};
|
|
43
|
-
nitroConfig.graphql.layerDirectories = layerDirectories;
|
|
44
|
-
nitroConfig.graphql.layerServerDirs = layerServerDirs;
|
|
45
|
-
nitroConfig.graphql.layerAppDirs = layerAppDirs;
|
|
46
|
-
if (!existsSync(resolve(nuxt.options.rootDir, "app/graphql"))) {
|
|
47
|
-
const defaultDir = join(clientDir, "default");
|
|
48
|
-
if (!existsSync(defaultDir)) mkdirSync(defaultDir, { recursive: true });
|
|
49
|
-
const sampleQueryFile = join(defaultDir, "queries.graphql");
|
|
50
|
-
if (!existsSync(sampleQueryFile)) writeFileSync(sampleQueryFile, `# Example GraphQL queries
|
|
51
|
-
# Add your GraphQL queries here
|
|
52
|
-
|
|
53
|
-
# query GetUser($id: ID!) {
|
|
54
|
-
# user(id: $id) {
|
|
55
|
-
# id
|
|
56
|
-
# name
|
|
57
|
-
# email
|
|
58
|
-
# }
|
|
59
|
-
# }
|
|
60
|
-
`, "utf-8");
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
//#endregion
|
|
67
|
-
export { nuxt_default as default };
|
package/dist/index.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { StandardSchemaV1 } from "./types/standard-schema.js";
|
|
2
|
-
import { CodegenClientConfig, CodegenServerConfig, ExternalGraphQLService, FederationConfig, GenImport, GenericSdkConfig, NitroGraphQLOptions } from "./types/index.js";
|
|
3
|
-
import * as nitropack0 from "nitropack";
|
|
4
|
-
|
|
5
|
-
//#region src/index.d.ts
|
|
6
|
-
declare const _default: nitropack0.NitroModule;
|
|
7
|
-
//#endregion
|
|
8
|
-
export { CodegenClientConfig, CodegenServerConfig, ExternalGraphQLService, FederationConfig, GenImport, GenericSdkConfig, NitroGraphQLOptions, StandardSchemaV1, _default as default };
|
package/dist/index.js
DELETED
|
@@ -1,264 +0,0 @@
|
|
|
1
|
-
import { generateDirectiveSchemas } from "./utils/directive-parser.js";
|
|
2
|
-
import { generateLayerIgnorePatterns, getLayerAppDirectories, getLayerServerDirectories, relativeWithDot, scanDirectives, scanDocs, scanResolvers, scanSchemas, validateExternalServices } from "./utils/index.js";
|
|
3
|
-
import { clientTypeGeneration, serverTypeGeneration } from "./utils/type-generation.js";
|
|
4
|
-
import { rollupConfig } from "./rollup.js";
|
|
5
|
-
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
6
|
-
import { fileURLToPath } from "node:url";
|
|
7
|
-
import { watch } from "chokidar";
|
|
8
|
-
import consola from "consola";
|
|
9
|
-
import defu from "defu";
|
|
10
|
-
import { dirname, join, relative, resolve } from "pathe";
|
|
11
|
-
|
|
12
|
-
//#region src/index.ts
|
|
13
|
-
var src_default = defineNitroModule({
|
|
14
|
-
name: "nitro-graphql",
|
|
15
|
-
async setup(nitro) {
|
|
16
|
-
if (!nitro.options.graphql?.framework) consola.warn("No GraphQL framework specified. Please set graphql.framework to \"graphql-yoga\" or \"apollo-server\".");
|
|
17
|
-
if (nitro.options.graphql?.externalServices?.length) {
|
|
18
|
-
const validationErrors = validateExternalServices(nitro.options.graphql.externalServices);
|
|
19
|
-
if (validationErrors.length > 0) {
|
|
20
|
-
consola.error("External services configuration errors:");
|
|
21
|
-
for (const error of validationErrors) consola.error(` - ${error}`);
|
|
22
|
-
throw new Error("Invalid external services configuration");
|
|
23
|
-
}
|
|
24
|
-
consola.info(`Configured ${nitro.options.graphql.externalServices.length} external GraphQL services`);
|
|
25
|
-
}
|
|
26
|
-
nitro.graphql ||= {
|
|
27
|
-
buildDir: "",
|
|
28
|
-
watchDirs: [],
|
|
29
|
-
clientDir: "",
|
|
30
|
-
serverDir: resolve(nitro.options.rootDir, "server", "graphql"),
|
|
31
|
-
dir: {
|
|
32
|
-
build: relative(nitro.options.rootDir, nitro.options.buildDir),
|
|
33
|
-
client: "graphql",
|
|
34
|
-
server: "server"
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
nitro.hooks.hook("rollup:before", (_, rollupConfig$1) => {
|
|
38
|
-
rollupConfig$1.external = rollupConfig$1.external || [];
|
|
39
|
-
const codegenExternals = ["oxc-parser", "@oxc-parser"];
|
|
40
|
-
if (Array.isArray(rollupConfig$1.external)) rollupConfig$1.external.push(...codegenExternals);
|
|
41
|
-
else if (typeof rollupConfig$1.external === "function") {
|
|
42
|
-
const originalExternal = rollupConfig$1.external;
|
|
43
|
-
rollupConfig$1.external = (id, parent, isResolved) => {
|
|
44
|
-
if (codegenExternals.some((external) => id.includes(external))) return true;
|
|
45
|
-
return originalExternal(id, parent, isResolved);
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
nitro.options.runtimeConfig.graphql = defu(nitro.options.runtimeConfig.graphql || {}, {
|
|
50
|
-
endpoint: {
|
|
51
|
-
graphql: "/api/graphql",
|
|
52
|
-
healthCheck: "/api/graphql/health"
|
|
53
|
-
},
|
|
54
|
-
playground: true
|
|
55
|
-
});
|
|
56
|
-
if (nitro.options.graphql?.federation?.enabled) consola.info(`Apollo Federation enabled for service: ${nitro.options.graphql.federation.serviceName || "unnamed"}`);
|
|
57
|
-
const graphqlBuildDir = resolve(nitro.options.buildDir, "graphql");
|
|
58
|
-
nitro.graphql.buildDir = graphqlBuildDir;
|
|
59
|
-
const watchDirs = [];
|
|
60
|
-
switch (nitro.options.framework.name) {
|
|
61
|
-
case "nuxt": {
|
|
62
|
-
if (!nitro.graphql.clientDir) {
|
|
63
|
-
nitro.graphql.clientDir = resolve(nitro.options.rootDir, "app", "graphql");
|
|
64
|
-
nitro.graphql.dir.client = "app/graphql";
|
|
65
|
-
}
|
|
66
|
-
if (!nitro.options.graphql?.serverDir) nitro.graphql.serverDir = resolve(nitro.options.rootDir, "server", "graphql");
|
|
67
|
-
watchDirs.push(nitro.graphql.clientDir);
|
|
68
|
-
const layerServerDirs = getLayerServerDirectories(nitro);
|
|
69
|
-
const layerAppDirs = getLayerAppDirectories(nitro);
|
|
70
|
-
for (const layerServerDir of layerServerDirs) watchDirs.push(join(layerServerDir, "graphql"));
|
|
71
|
-
for (const layerAppDir of layerAppDirs) watchDirs.push(join(layerAppDir, "graphql"));
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
case "nitro":
|
|
75
|
-
if (!nitro.options.graphql?.serverDir) nitro.graphql.serverDir = resolve(nitro.options.rootDir, "server", "graphql");
|
|
76
|
-
nitro.graphql.clientDir = resolve(nitro.options.rootDir, "graphql");
|
|
77
|
-
nitro.graphql.dir.client = "graphql";
|
|
78
|
-
watchDirs.push(nitro.graphql.clientDir);
|
|
79
|
-
watchDirs.push(nitro.graphql.serverDir);
|
|
80
|
-
break;
|
|
81
|
-
default:
|
|
82
|
-
}
|
|
83
|
-
if (nitro.options.graphql?.externalServices?.length) {
|
|
84
|
-
for (const service of nitro.options.graphql.externalServices) if (service.documents?.length) for (const pattern of service.documents) {
|
|
85
|
-
if (!pattern) continue;
|
|
86
|
-
const baseDir = pattern.split("**")[0]?.replace(/\/$/, "") || ".";
|
|
87
|
-
const resolvedDir = resolve(nitro.options.rootDir, baseDir);
|
|
88
|
-
if (!watchDirs.includes(resolvedDir)) watchDirs.push(resolvedDir);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
const watcher = watch(watchDirs, {
|
|
92
|
-
persistent: true,
|
|
93
|
-
ignoreInitial: true,
|
|
94
|
-
ignored: [...nitro.options.ignore, ...generateLayerIgnorePatterns(nitro)]
|
|
95
|
-
}).on("all", async (_, path) => {
|
|
96
|
-
if (path.endsWith(".graphql") || path.endsWith(".gql")) if (path.includes(nitro.graphql.serverDir) || path.includes("server/graphql") || path.includes("server\\graphql")) {
|
|
97
|
-
await serverTypeGeneration(nitro);
|
|
98
|
-
await clientTypeGeneration(nitro);
|
|
99
|
-
await nitro.hooks.callHook("dev:reload");
|
|
100
|
-
} else await clientTypeGeneration(nitro);
|
|
101
|
-
});
|
|
102
|
-
nitro.hooks.hook("close", () => {
|
|
103
|
-
watcher.close();
|
|
104
|
-
});
|
|
105
|
-
const tsconfigDir = dirname(resolve(nitro.options.buildDir, nitro.options.typescript.tsconfigPath));
|
|
106
|
-
const typesDir = resolve(nitro.options.buildDir, "types");
|
|
107
|
-
nitro.scanSchemas = await scanSchemas(nitro);
|
|
108
|
-
nitro.scanDocuments = await scanDocs(nitro);
|
|
109
|
-
nitro.scanResolvers = await scanResolvers(nitro);
|
|
110
|
-
const directives = await scanDirectives(nitro);
|
|
111
|
-
nitro.scanDirectives = directives;
|
|
112
|
-
await generateDirectiveSchemas(nitro, directives);
|
|
113
|
-
nitro.hooks.hook("dev:start", async () => {
|
|
114
|
-
nitro.scanSchemas = await scanSchemas(nitro);
|
|
115
|
-
nitro.scanResolvers = await scanResolvers(nitro);
|
|
116
|
-
const directives$1 = await scanDirectives(nitro);
|
|
117
|
-
nitro.scanDirectives = directives$1;
|
|
118
|
-
await generateDirectiveSchemas(nitro, directives$1);
|
|
119
|
-
nitro.scanDocuments = await scanDocs(nitro);
|
|
120
|
-
});
|
|
121
|
-
await rollupConfig(nitro);
|
|
122
|
-
await serverTypeGeneration(nitro);
|
|
123
|
-
await clientTypeGeneration(nitro);
|
|
124
|
-
nitro.hooks.hook("close", async () => {
|
|
125
|
-
await serverTypeGeneration(nitro);
|
|
126
|
-
await clientTypeGeneration(nitro);
|
|
127
|
-
});
|
|
128
|
-
const runtime = fileURLToPath(new URL("routes", import.meta.url));
|
|
129
|
-
const methods = [
|
|
130
|
-
"GET",
|
|
131
|
-
"POST",
|
|
132
|
-
"OPTIONS"
|
|
133
|
-
];
|
|
134
|
-
if (nitro.options.graphql?.framework === "graphql-yoga") for (const method of methods) nitro.options.handlers.push({
|
|
135
|
-
route: nitro.options.runtimeConfig.graphql?.endpoint?.graphql || "/api/graphql",
|
|
136
|
-
handler: join(runtime, "graphql-yoga"),
|
|
137
|
-
method
|
|
138
|
-
});
|
|
139
|
-
if (nitro.options.graphql?.framework === "apollo-server") for (const method of methods) nitro.options.handlers.push({
|
|
140
|
-
route: nitro.options.runtimeConfig.graphql?.endpoint?.graphql || "/api/graphql",
|
|
141
|
-
handler: join(runtime, "apollo-server"),
|
|
142
|
-
method
|
|
143
|
-
});
|
|
144
|
-
nitro.options.handlers.push({
|
|
145
|
-
route: nitro.options.runtimeConfig.graphql?.endpoint?.healthCheck || "/api/graphql/health",
|
|
146
|
-
handler: join(runtime, "health"),
|
|
147
|
-
method: "GET"
|
|
148
|
-
});
|
|
149
|
-
if (nitro.options.imports) {
|
|
150
|
-
nitro.options.imports.presets ??= [];
|
|
151
|
-
nitro.options.imports.presets.push({
|
|
152
|
-
from: fileURLToPath(new URL("utils/define", import.meta.url)),
|
|
153
|
-
imports: [
|
|
154
|
-
"defineResolver",
|
|
155
|
-
"defineMutation",
|
|
156
|
-
"defineQuery",
|
|
157
|
-
"defineSubscription",
|
|
158
|
-
"defineType",
|
|
159
|
-
"defineGraphQLConfig",
|
|
160
|
-
"defineSchema",
|
|
161
|
-
"defineDirective"
|
|
162
|
-
]
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
nitro.hooks.hook("rollup:before", (_, rollupConfig$1) => {
|
|
166
|
-
const manualChunks = rollupConfig$1.output?.manualChunks;
|
|
167
|
-
const chunkFiles = rollupConfig$1.output?.chunkFileNames;
|
|
168
|
-
if (!rollupConfig$1.output.inlineDynamicImports) rollupConfig$1.output.manualChunks = (id, meta) => {
|
|
169
|
-
if (id.endsWith(".graphql") || id.endsWith(".gql")) return "schemas";
|
|
170
|
-
if (id.endsWith(".resolver.ts")) return "resolvers";
|
|
171
|
-
if (typeof manualChunks === "function") return manualChunks(id, meta);
|
|
172
|
-
};
|
|
173
|
-
rollupConfig$1.output.chunkFileNames = (chunkInfo) => {
|
|
174
|
-
if (chunkInfo.moduleIds && chunkInfo.moduleIds.some((id) => id.endsWith(".graphql") || id.endsWith(".resolver.ts") || id.endsWith(".gql"))) return `chunks/graphql/[name].mjs`;
|
|
175
|
-
if (typeof chunkFiles === "function") return chunkFiles(chunkInfo);
|
|
176
|
-
return `chunks/_/[name].mjs`;
|
|
177
|
-
};
|
|
178
|
-
});
|
|
179
|
-
nitro.options.typescript.strict = true;
|
|
180
|
-
nitro.hooks.hook("types:extend", (types) => {
|
|
181
|
-
types.tsConfig ||= {};
|
|
182
|
-
types.tsConfig.compilerOptions ??= {};
|
|
183
|
-
types.tsConfig.compilerOptions.paths ??= {};
|
|
184
|
-
types.tsConfig.compilerOptions.paths["#graphql/server"] = [relativeWithDot(tsconfigDir, join(typesDir, "nitro-graphql-server.d.ts"))];
|
|
185
|
-
types.tsConfig.compilerOptions.paths["#graphql/client"] = [relativeWithDot(tsconfigDir, join(typesDir, "nitro-graphql-client.d.ts"))];
|
|
186
|
-
types.tsConfig.compilerOptions.paths["#graphql/schema"] = [relativeWithDot(tsconfigDir, join(nitro.graphql.serverDir, "schema.ts"))];
|
|
187
|
-
if (nitro.options.graphql?.externalServices?.length) for (const service of nitro.options.graphql.externalServices) types.tsConfig.compilerOptions.paths[`#graphql/client/${service.name}`] = [relativeWithDot(tsconfigDir, join(typesDir, `nitro-graphql-client-${service.name}.d.ts`))];
|
|
188
|
-
types.tsConfig.include = types.tsConfig.include || [];
|
|
189
|
-
types.tsConfig.include.push(relativeWithDot(tsconfigDir, join(typesDir, "nitro-graphql-server.d.ts")), relativeWithDot(tsconfigDir, join(typesDir, "nitro-graphql-client.d.ts")), relativeWithDot(tsconfigDir, join(typesDir, "graphql.d.ts")));
|
|
190
|
-
if (nitro.options.graphql?.externalServices?.length) for (const service of nitro.options.graphql.externalServices) types.tsConfig.include.push(relativeWithDot(tsconfigDir, join(typesDir, `nitro-graphql-client-${service.name}.d.ts`)));
|
|
191
|
-
});
|
|
192
|
-
if (nitro.options.framework?.name === "nuxt" && nitro.options.graphql?.externalServices?.length) nitro.hooks.hook("build:before", () => {
|
|
193
|
-
const nuxtOptions = nitro._nuxt?.options;
|
|
194
|
-
if (nuxtOptions) nuxtOptions.nitroGraphqlExternalServices = nitro.options.graphql?.externalServices || [];
|
|
195
|
-
});
|
|
196
|
-
if (!existsSync(join(nitro.options.rootDir, "graphql.config.ts"))) {
|
|
197
|
-
const schemaPath = relativeWithDot(nitro.options.rootDir, resolve(nitro.graphql.buildDir, "schema.graphql"));
|
|
198
|
-
const documentsPath = relativeWithDot(nitro.options.rootDir, resolve(nitro.graphql.clientDir, "**/*.{graphql,js,ts,jsx,tsx}"));
|
|
199
|
-
writeFileSync(join(nitro.options.rootDir, "graphql.config.ts"), `
|
|
200
|
-
import type { IGraphQLConfig } from 'graphql-config'
|
|
201
|
-
|
|
202
|
-
export default <IGraphQLConfig> {
|
|
203
|
-
projects: {
|
|
204
|
-
default: {
|
|
205
|
-
schema: [
|
|
206
|
-
'${schemaPath}',
|
|
207
|
-
],
|
|
208
|
-
documents: [
|
|
209
|
-
'${documentsPath}',
|
|
210
|
-
],
|
|
211
|
-
},
|
|
212
|
-
},
|
|
213
|
-
}`, "utf-8");
|
|
214
|
-
}
|
|
215
|
-
if (!existsSync(nitro.graphql.serverDir)) mkdirSync(nitro.graphql.serverDir, { recursive: true });
|
|
216
|
-
if (!existsSync(join(nitro.graphql.serverDir, "schema.ts"))) writeFileSync(join(nitro.graphql.serverDir, "schema.ts"), `
|
|
217
|
-
import { defineSchema } from 'nitro-graphql/utils/define'
|
|
218
|
-
|
|
219
|
-
export default defineSchema({
|
|
220
|
-
|
|
221
|
-
})
|
|
222
|
-
`, "utf-8");
|
|
223
|
-
if (!existsSync(join(nitro.graphql.serverDir, "config.ts"))) writeFileSync(join(nitro.graphql.serverDir, "config.ts"), `// Example GraphQL config file please change it to your needs
|
|
224
|
-
// import * as tables from '../drizzle/schema/index'
|
|
225
|
-
// import { useDatabase } from '../utils/useDb'
|
|
226
|
-
import { defineGraphQLConfig } from 'nitro-graphql/utils/define'
|
|
227
|
-
|
|
228
|
-
export default defineGraphQLConfig({
|
|
229
|
-
// graphql-yoga example config
|
|
230
|
-
// context: () => {
|
|
231
|
-
// return {
|
|
232
|
-
// context: {
|
|
233
|
-
// useDatabase,
|
|
234
|
-
// tables,
|
|
235
|
-
// },
|
|
236
|
-
// }
|
|
237
|
-
// },
|
|
238
|
-
})
|
|
239
|
-
`, "utf-8");
|
|
240
|
-
if (!existsSync(join(nitro.graphql.serverDir, "context.ts"))) writeFileSync(join(nitro.graphql.serverDir, "context.ts"), `// Example context definition - please change it to your needs
|
|
241
|
-
// import type { Database } from '../utils/useDb'
|
|
242
|
-
|
|
243
|
-
declare module 'h3' {
|
|
244
|
-
interface H3EventContext {
|
|
245
|
-
// Add your custom context properties here
|
|
246
|
-
// useDatabase: () => Database
|
|
247
|
-
// tables: typeof import('../drizzle/schema')
|
|
248
|
-
// auth?: {
|
|
249
|
-
// user?: {
|
|
250
|
-
// id: string
|
|
251
|
-
// role: 'admin' | 'user'
|
|
252
|
-
// }
|
|
253
|
-
// }
|
|
254
|
-
}
|
|
255
|
-
}`, "utf-8");
|
|
256
|
-
if (existsSync(join(nitro.graphql.serverDir, "context.d.ts"))) {
|
|
257
|
-
consola.warn("nitro-graphql: Found context.d.ts file. Please rename it to context.ts for the new structure.");
|
|
258
|
-
consola.info("The context file should now be context.ts instead of context.d.ts");
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
//#endregion
|
|
264
|
-
export { src_default as default };
|
package/dist/rollup.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { getImportId, scanGraphql } from "./utils/index.js";
|
|
2
|
-
import { clientTypeGeneration, serverTypeGeneration } from "./utils/type-generation.js";
|
|
3
|
-
import { resolve } from "pathe";
|
|
4
|
-
import { readFile } from "node:fs/promises";
|
|
5
|
-
import { parse } from "graphql";
|
|
6
|
-
import { genImport } from "knitwork";
|
|
7
|
-
|
|
8
|
-
//#region src/rollup.ts
|
|
9
|
-
async function rollupConfig(app) {
|
|
10
|
-
virtualSchemas(app);
|
|
11
|
-
virtualResolvers(app);
|
|
12
|
-
virtualDirectives(app);
|
|
13
|
-
getGraphQLConfig(app);
|
|
14
|
-
virtualModuleConfig(app);
|
|
15
|
-
app.hooks.hook("rollup:before", (nitro, rollupConfig$1) => {
|
|
16
|
-
rollupConfig$1.plugins = rollupConfig$1.plugins || [];
|
|
17
|
-
const { include = /\.(graphql|gql)$/i, exclude, validate = false } = app.options.graphql?.loader || {};
|
|
18
|
-
if (Array.isArray(rollupConfig$1.plugins)) {
|
|
19
|
-
rollupConfig$1.plugins.push({
|
|
20
|
-
name: "nitro-graphql",
|
|
21
|
-
async load(id) {
|
|
22
|
-
if (exclude?.test?.(id)) return null;
|
|
23
|
-
if (!include.test(id)) return null;
|
|
24
|
-
try {
|
|
25
|
-
const content = await readFile(id, "utf-8");
|
|
26
|
-
if (validate) parse(content);
|
|
27
|
-
return `export default ${JSON.stringify(content)}`;
|
|
28
|
-
} catch (error) {
|
|
29
|
-
if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") return null;
|
|
30
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
31
|
-
this.error(`Failed to read GraphQL file ${id}: ${message}`);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
rollupConfig$1.plugins.push({
|
|
36
|
-
name: "nitro-graphql-watcher",
|
|
37
|
-
async buildStart() {
|
|
38
|
-
const graphqlFiles = await scanGraphql(nitro);
|
|
39
|
-
for (const file of graphqlFiles) this.addWatchFile(file);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
app.hooks.hook("dev:reload", async () => {
|
|
45
|
-
await serverTypeGeneration(app);
|
|
46
|
-
await clientTypeGeneration(app);
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
function virtualSchemas(app) {
|
|
50
|
-
const getSchemas = () => [...app.scanSchemas, ...app.options.graphql?.typedefs ?? []];
|
|
51
|
-
app.options.virtual ??= {};
|
|
52
|
-
app.options.virtual["#nitro-internal-virtual/server-schemas"] = () => {
|
|
53
|
-
const imports = getSchemas();
|
|
54
|
-
return `
|
|
55
|
-
${imports.map((handler) => `import ${getImportId(handler)} from '${handler}';`).join("\n")}
|
|
56
|
-
|
|
57
|
-
export const schemas = [
|
|
58
|
-
${imports.map((h) => `{ def: ${getImportId(h)} }`).join(",\n")}
|
|
59
|
-
];
|
|
60
|
-
`;
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
function virtualResolvers(app) {
|
|
64
|
-
const getResolvers = () => [...app.scanResolvers];
|
|
65
|
-
app.options.virtual ??= {};
|
|
66
|
-
app.options.virtual["#nitro-internal-virtual/server-resolvers"] = () => {
|
|
67
|
-
const imports = getResolvers();
|
|
68
|
-
const importsContent = imports.map(({ specifier, imports: imports$1, options }) => genImport(specifier, imports$1, options));
|
|
69
|
-
const data = imports.map(({ imports: imports$1 }) => imports$1.map((i) => `{ resolver: ${i.as} }`).join(",\n")).filter(Boolean).join(",\n");
|
|
70
|
-
return [
|
|
71
|
-
...importsContent,
|
|
72
|
-
"export const resolvers = [",
|
|
73
|
-
data,
|
|
74
|
-
"]",
|
|
75
|
-
""
|
|
76
|
-
].join("\n");
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
function virtualDirectives(app) {
|
|
80
|
-
const getDirectives = () => app.scanDirectives || [];
|
|
81
|
-
app.options.virtual ??= {};
|
|
82
|
-
app.options.virtual["#nitro-internal-virtual/server-directives"] = () => {
|
|
83
|
-
const imports = getDirectives();
|
|
84
|
-
const importsContent = imports.map(({ specifier, imports: imports$1, options }) => genImport(specifier, imports$1, options));
|
|
85
|
-
const data = imports.map(({ imports: imports$1 }) => imports$1.map((i) => `{ directive: ${i.as} }`).join(",\n")).filter(Boolean).join(",\n");
|
|
86
|
-
return [
|
|
87
|
-
...importsContent,
|
|
88
|
-
"export const directives = [",
|
|
89
|
-
data,
|
|
90
|
-
"]",
|
|
91
|
-
""
|
|
92
|
-
].join("\n");
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
function getGraphQLConfig(app) {
|
|
96
|
-
const configPath = resolve(app.graphql.serverDir, "config.ts");
|
|
97
|
-
app.options.virtual ??= {};
|
|
98
|
-
app.options.virtual["#nitro-internal-virtual/graphql-config"] = () => {
|
|
99
|
-
return `import config from '${configPath}'
|
|
100
|
-
const importedConfig = config
|
|
101
|
-
export { importedConfig }
|
|
102
|
-
`;
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
function virtualModuleConfig(app) {
|
|
106
|
-
app.options.virtual ??= {};
|
|
107
|
-
app.options.virtual["#nitro-internal-virtual/module-config"] = () => {
|
|
108
|
-
const moduleConfig = app.options.graphql || {};
|
|
109
|
-
return `export const moduleConfig = ${JSON.stringify(moduleConfig, null, 2)};`;
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
//#endregion
|
|
114
|
-
export { rollupConfig };
|