nitro-graphql 2.0.0-beta.3 → 2.0.0-beta.31
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 +477 -20
- package/dist/define.d.mts +296 -0
- package/dist/define.mjs +323 -0
- package/dist/ecosystem/nuxt.mjs +109 -0
- package/dist/index.d.mts +43 -0
- package/dist/index.mjs +63 -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} +7 -7
- 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} +11 -7
- package/dist/routes/health.d.mts +10 -0
- package/dist/routes/{health.js → health.mjs} +3 -2
- package/dist/setup.d.mts +11 -0
- package/dist/setup.mjs +376 -0
- package/dist/{utils/define.d.ts → types/define.d.mts} +4 -27
- package/dist/types/define.mjs +1 -0
- package/dist/types/index.d.mts +246 -0
- package/dist/types/index.mjs +1 -0
- package/dist/types/standard-schema.mjs +1 -0
- package/dist/utils/{apollo.d.ts → apollo.d.mts} +2 -2
- package/dist/utils/apollo.mjs +59 -0
- package/dist/utils/{client-codegen.d.ts → client-codegen.d.mts} +6 -3
- package/dist/utils/{client-codegen.js → client-codegen.mjs} +6 -6
- package/dist/utils/errors.d.mts +73 -0
- package/dist/utils/errors.mjs +89 -0
- 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} +4 -3
- package/dist/utils/{index.js → index.mjs} +80 -40
- 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} +3 -3
- package/dist/utils/type-generation.d.mts +12 -0
- package/dist/utils/type-generation.mjs +420 -0
- 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/package.json +79 -70
- 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/utils/apollo.js +0 -61
- package/dist/utils/define.js +0 -57
- package/dist/utils/type-generation.d.ts +0 -7
- package/dist/utils/type-generation.js +0 -287
- /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/{directive-parser.d.ts → directive-parser.d.mts} +0 -0
- /package/dist/utils/{directive-parser.js → directive-parser.mjs} +0 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/virtual/server-directives.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Virtual module stub for #nitro-graphql/server-directives
|
|
4
|
+
* This file is only used during build/bundling to prevent import resolution errors.
|
|
5
|
+
* At runtime, Nitro will override this with the actual virtual module.
|
|
6
|
+
*/
|
|
7
|
+
declare const directives: Array<{
|
|
8
|
+
directive: any;
|
|
9
|
+
}>;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { directives };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region src/virtual/server-directives.ts
|
|
2
|
+
/**
|
|
3
|
+
* Virtual module stub for #nitro-graphql/server-directives
|
|
4
|
+
* This file is only used during build/bundling to prevent import resolution errors.
|
|
5
|
+
* At runtime, Nitro will override this with the actual virtual module.
|
|
6
|
+
*/
|
|
7
|
+
const directives = [];
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
export { directives };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/virtual/server-resolvers.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Virtual module stub for #nitro-graphql/server-resolvers
|
|
4
|
+
* This file is only used during build/bundling to prevent import resolution errors.
|
|
5
|
+
* At runtime, Nitro will override this with the actual virtual module.
|
|
6
|
+
*/
|
|
7
|
+
declare const resolvers: Array<{
|
|
8
|
+
resolver: any;
|
|
9
|
+
}>;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { resolvers };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region src/virtual/server-resolvers.ts
|
|
2
|
+
/**
|
|
3
|
+
* Virtual module stub for #nitro-graphql/server-resolvers
|
|
4
|
+
* This file is only used during build/bundling to prevent import resolution errors.
|
|
5
|
+
* At runtime, Nitro will override this with the actual virtual module.
|
|
6
|
+
*/
|
|
7
|
+
const resolvers = [];
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
export { resolvers };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/virtual/server-schemas.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Virtual module stub for #nitro-graphql/server-schemas
|
|
4
|
+
* This file is only used during build/bundling to prevent import resolution errors.
|
|
5
|
+
* At runtime, Nitro will override this with the actual virtual module.
|
|
6
|
+
*/
|
|
7
|
+
declare const schemas: Array<{
|
|
8
|
+
def: string;
|
|
9
|
+
}>;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { schemas };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region src/virtual/server-schemas.ts
|
|
2
|
+
/**
|
|
3
|
+
* Virtual module stub for #nitro-graphql/server-schemas
|
|
4
|
+
* This file is only used during build/bundling to prevent import resolution errors.
|
|
5
|
+
* At runtime, Nitro will override this with the actual virtual module.
|
|
6
|
+
*/
|
|
7
|
+
const schemas = [];
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
export { schemas };
|
package/package.json
CHANGED
|
@@ -1,123 +1,128 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nitro-graphql",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.31",
|
|
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
|
-
|
|
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"
|
|
12
|
+
},
|
|
13
|
+
"#nitro-graphql/graphql-config": {
|
|
14
|
+
"types": "./dist/virtual/graphql-config.d.mts",
|
|
15
|
+
"import": "./dist/virtual/graphql-config.mjs"
|
|
18
16
|
},
|
|
19
|
-
"
|
|
20
|
-
"types": "./dist/
|
|
21
|
-
"import": "./dist/
|
|
17
|
+
"#nitro-graphql/server-schemas": {
|
|
18
|
+
"types": "./dist/virtual/server-schemas.d.mts",
|
|
19
|
+
"import": "./dist/virtual/server-schemas.mjs"
|
|
22
20
|
},
|
|
23
|
-
"
|
|
24
|
-
"types": "./dist/
|
|
25
|
-
"import": "./dist/
|
|
21
|
+
"#nitro-graphql/server-resolvers": {
|
|
22
|
+
"types": "./dist/virtual/server-resolvers.d.mts",
|
|
23
|
+
"import": "./dist/virtual/server-resolvers.mjs"
|
|
26
24
|
},
|
|
27
|
-
"
|
|
28
|
-
"types": "./dist/
|
|
29
|
-
"import": "./dist/
|
|
25
|
+
"#nitro-graphql/server-directives": {
|
|
26
|
+
"types": "./dist/virtual/server-directives.d.mts",
|
|
27
|
+
"import": "./dist/virtual/server-directives.mjs"
|
|
30
28
|
},
|
|
31
|
-
"
|
|
32
|
-
"types": "./dist/
|
|
33
|
-
"import": "./dist/
|
|
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
|
-
"./
|
|
40
|
-
"types": "./dist/
|
|
41
|
-
"import": "./dist/
|
|
47
|
+
"./define": {
|
|
48
|
+
"types": "./dist/define.d.mts",
|
|
49
|
+
"import": "./dist/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"
|
|
62
|
+
},
|
|
63
|
+
"./types": {
|
|
64
|
+
"types": "./dist/types/index.d.mts",
|
|
65
|
+
"import": "./dist/types/index.mjs"
|
|
54
66
|
}
|
|
55
67
|
},
|
|
56
|
-
"module": "./dist/index.
|
|
57
|
-
"types": "./dist/index.d.
|
|
68
|
+
"module": "./dist/index.mjs",
|
|
69
|
+
"types": "./dist/index.d.mts",
|
|
58
70
|
"files": [
|
|
59
71
|
"dist"
|
|
60
72
|
],
|
|
61
73
|
"peerDependencies": {
|
|
62
74
|
"@apollo/server": "^5.0.0",
|
|
63
|
-
"@apollo/utils.withrequired": "^3.0.0",
|
|
64
|
-
"@as-integrations/h3": "^2.0.0",
|
|
65
75
|
"graphql": "^16.11.0",
|
|
66
|
-
"h3": "^2.0.1-rc.2",
|
|
67
76
|
"nitro": "^3.0.1-alpha.0"
|
|
68
77
|
},
|
|
69
78
|
"peerDependenciesMeta": {
|
|
70
79
|
"@apollo/server": {
|
|
71
80
|
"optional": true
|
|
72
|
-
},
|
|
73
|
-
"@apollo/utils.withrequired": {
|
|
74
|
-
"optional": true
|
|
75
|
-
},
|
|
76
|
-
"@as-integrations/h3": {
|
|
77
|
-
"optional": true
|
|
78
81
|
}
|
|
79
82
|
},
|
|
80
83
|
"dependencies": {
|
|
81
|
-
"@apollo/subgraph": "^2.
|
|
84
|
+
"@apollo/subgraph": "^2.12.1",
|
|
82
85
|
"@graphql-codegen/core": "^5.0.0",
|
|
83
86
|
"@graphql-codegen/import-types-preset": "^3.0.1",
|
|
84
|
-
"@graphql-codegen/typescript": "^5.0.
|
|
87
|
+
"@graphql-codegen/typescript": "^5.0.4",
|
|
85
88
|
"@graphql-codegen/typescript-generic-sdk": "^4.0.2",
|
|
86
|
-
"@graphql-codegen/typescript-operations": "^5.0.
|
|
87
|
-
"@graphql-codegen/typescript-resolvers": "^5.1.
|
|
88
|
-
"@graphql-tools/graphql-file-loader": "^8.1.
|
|
89
|
-
"@graphql-tools/load": "^8.1.
|
|
89
|
+
"@graphql-codegen/typescript-operations": "^5.0.4",
|
|
90
|
+
"@graphql-codegen/typescript-resolvers": "^5.1.2",
|
|
91
|
+
"@graphql-tools/graphql-file-loader": "^8.1.6",
|
|
92
|
+
"@graphql-tools/load": "^8.1.6",
|
|
90
93
|
"@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.
|
|
94
|
+
"@graphql-tools/merge": "^9.1.5",
|
|
95
|
+
"@graphql-tools/schema": "^10.0.29",
|
|
96
|
+
"@graphql-tools/url-loader": "^9.0.4",
|
|
97
|
+
"@graphql-tools/utils": "^10.10.3",
|
|
95
98
|
"chokidar": "^4.0.3",
|
|
96
99
|
"consola": "^3.4.2",
|
|
97
100
|
"defu": "^6.1.4",
|
|
98
101
|
"graphql-config": "^5.1.5",
|
|
99
102
|
"graphql-scalars": "^1.25.0",
|
|
100
|
-
"knitwork": "^1.
|
|
103
|
+
"knitwork": "^1.3.0",
|
|
101
104
|
"ohash": "^2.0.11",
|
|
102
|
-
"oxc-parser": "^0.
|
|
105
|
+
"oxc-parser": "^0.98.0",
|
|
103
106
|
"pathe": "^2.0.3",
|
|
104
107
|
"tinyglobby": "^0.2.15"
|
|
105
108
|
},
|
|
106
109
|
"devDependencies": {
|
|
107
|
-
"@antfu/eslint-config": "^6.
|
|
108
|
-
"@nuxt/kit": "^4.1
|
|
109
|
-
"@nuxt/schema": "^4.1
|
|
110
|
-
"@types/node": "^24.
|
|
110
|
+
"@antfu/eslint-config": "^6.2.0",
|
|
111
|
+
"@nuxt/kit": "^4.2.1",
|
|
112
|
+
"@nuxt/schema": "^4.2.1",
|
|
113
|
+
"@types/node": "^24.10.1",
|
|
114
|
+
"@vitejs/devtools": "^0.0.0-alpha.16",
|
|
111
115
|
"bumpp": "^10.3.1",
|
|
112
116
|
"changelogen": "^0.6.2",
|
|
113
|
-
"crossws": "0.
|
|
114
|
-
"eslint": "^9.
|
|
115
|
-
"graphql": "16.
|
|
116
|
-
"graphql-yoga": "
|
|
117
|
-
"
|
|
118
|
-
"
|
|
119
|
-
"
|
|
120
|
-
"
|
|
117
|
+
"crossws": "^0.4.1",
|
|
118
|
+
"eslint": "^9.39.1",
|
|
119
|
+
"graphql": "16.12.0",
|
|
120
|
+
"graphql-yoga": "5.16.2",
|
|
121
|
+
"nitro": "npm:nitro-nightly@latest",
|
|
122
|
+
"tsdown": "^0.16.6",
|
|
123
|
+
"typescript": "^5.9.3",
|
|
124
|
+
"vite": "npm:rolldown-vite@latest",
|
|
125
|
+
"vitepress-plugin-llms": "^1.9.3"
|
|
121
126
|
},
|
|
122
127
|
"resolutions": {
|
|
123
128
|
"nitro-graphql": "link:."
|
|
@@ -130,7 +135,11 @@
|
|
|
130
135
|
"playground:nitro": "cd playgrounds/nitro && pnpm install && pnpm dev",
|
|
131
136
|
"playground:nuxt": "cd playgrounds/nuxt && pnpm install && pnpm dev",
|
|
132
137
|
"playground:federation": "cd playgrounds/federation && pnpm install && pnpm dev",
|
|
138
|
+
"docs:dev": "cd .docs && pnpm install && pnpm update:metadata && pnpm dev",
|
|
139
|
+
"docs:build": "cd .docs && pnpm install && pnpm update:metadata && pnpm build",
|
|
140
|
+
"docs:preview": "cd .docs && pnpm preview",
|
|
133
141
|
"lint": "eslint .",
|
|
134
|
-
"lint:fix": "eslint . --fix"
|
|
142
|
+
"lint:fix": "eslint . --fix",
|
|
143
|
+
"test:types": "tsc --noEmit"
|
|
135
144
|
}
|
|
136
145
|
}
|
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 nitro_types0 from "nitro/types";
|
|
4
|
-
|
|
5
|
-
//#region src/index.d.ts
|
|
6
|
-
declare const _default: nitro_types0.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 };
|