nitro-graphql 2.0.0-beta.22 → 2.0.0-beta.23
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
|
@@ -61,7 +61,7 @@ pnpm add nitro-graphql graphql-yoga graphql
|
|
|
61
61
|
|
|
62
62
|
**Apollo Server:**
|
|
63
63
|
```bash
|
|
64
|
-
pnpm add nitro-graphql @apollo/server @apollo/utils.withrequired
|
|
64
|
+
pnpm add nitro-graphql @apollo/server @apollo/utils.withrequired graphql
|
|
65
65
|
```
|
|
66
66
|
|
|
67
67
|
### 2. Configure
|
|
@@ -1029,7 +1029,7 @@ Now implement this setup.
|
|
|
1029
1029
|
Set up nitro-graphql with Apollo Server following these exact specifications:
|
|
1030
1030
|
|
|
1031
1031
|
INSTALLATION:
|
|
1032
|
-
1. Run: pnpm add nitro-graphql @apollo/server @apollo/utils.withrequired
|
|
1032
|
+
1. Run: pnpm add nitro-graphql @apollo/server @apollo/utils.withrequired graphql
|
|
1033
1033
|
|
|
1034
1034
|
CONFIGURATION (nitro.config.ts):
|
|
1035
1035
|
import { defineNitroConfig } from 'nitro/config'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as h30 from "h3";
|
|
2
2
|
|
|
3
3
|
//#region src/routes/apollo-server.d.ts
|
|
4
|
-
declare const _default:
|
|
4
|
+
declare const _default: h30.EventHandlerWithFetch<h30.EventHandlerRequest, Promise<any>>;
|
|
5
5
|
//#endregion
|
|
6
6
|
export { _default as default };
|
package/dist/routes/debug.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as h33 from "h3";
|
|
2
2
|
|
|
3
3
|
//#region src/routes/debug.d.ts
|
|
4
4
|
|
|
@@ -10,7 +10,7 @@ import * as h35 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: h33.EventHandlerWithFetch<h33.EventHandlerRequest, Promise<string | {
|
|
14
14
|
timestamp: string;
|
|
15
15
|
environment: {
|
|
16
16
|
dev: any;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as h35 from "h3";
|
|
2
2
|
|
|
3
3
|
//#region src/routes/graphql-yoga.d.ts
|
|
4
|
-
declare const _default:
|
|
4
|
+
declare const _default: h35.EventHandlerWithFetch<h35.EventHandlerRequest, Promise<Response>>;
|
|
5
5
|
//#endregion
|
|
6
6
|
export { _default as default };
|
package/dist/routes/health.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as h31 from "h3";
|
|
2
2
|
|
|
3
3
|
//#region src/routes/health.d.ts
|
|
4
|
-
declare const _default:
|
|
4
|
+
declare const _default: h31.EventHandlerWithFetch<h31.EventHandlerRequest, Promise<{
|
|
5
5
|
status: string;
|
|
6
6
|
message: string;
|
|
7
7
|
timestamp: string;
|
package/dist/utils/apollo.mjs
CHANGED
|
@@ -1,60 +1,58 @@
|
|
|
1
1
|
import { HeaderMap } from "@apollo/server";
|
|
2
|
-
import { eventHandler,
|
|
2
|
+
import { eventHandler, getRequestURL, readBody } from "h3";
|
|
3
3
|
|
|
4
4
|
//#region src/utils/apollo.ts
|
|
5
5
|
function startServerAndCreateH3Handler(server, options) {
|
|
6
6
|
const defaultContext = () => Promise.resolve({});
|
|
7
7
|
const contextFunction = options?.context ?? defaultContext;
|
|
8
|
-
return eventHandler({
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
8
|
+
return eventHandler(async (event) => {
|
|
9
|
+
const apolloServer = typeof server === "function" ? server() : server;
|
|
10
|
+
if (!options?.serverAlreadyStarted) apolloServer.startInBackgroundHandlingStartupErrorsByLoggingAndFailingAllRequests();
|
|
11
|
+
if (event.req.method === "OPTIONS") {
|
|
12
|
+
event.res.status = 204;
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
const graphqlRequest = await toGraphqlRequest(event);
|
|
17
|
+
const { body, headers, status } = await apolloServer.executeHTTPGraphQLRequest({
|
|
18
|
+
httpGraphQLRequest: graphqlRequest,
|
|
19
|
+
context: () => contextFunction({ event })
|
|
20
|
+
});
|
|
21
|
+
if (body.kind === "chunked") throw new Error("Incremental delivery not implemented");
|
|
22
|
+
for (const [key, value] of headers) event.res.headers.set(key, value);
|
|
23
|
+
event.res.status = status || 200;
|
|
24
|
+
return body.string;
|
|
25
|
+
} catch (error) {
|
|
26
|
+
if (error instanceof SyntaxError) {
|
|
27
|
+
event.res.status = 400;
|
|
28
|
+
return error.message;
|
|
29
|
+
} else throw error;
|
|
30
|
+
}
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
33
|
async function toGraphqlRequest(event) {
|
|
34
|
+
const url = getRequestURL(event);
|
|
34
35
|
return {
|
|
35
36
|
method: event.req.method || "POST",
|
|
36
|
-
headers: normalizeHeaders(
|
|
37
|
-
search:
|
|
37
|
+
headers: normalizeHeaders(Object.fromEntries(event.req.headers.entries())),
|
|
38
|
+
search: url.search.slice(1),
|
|
38
39
|
body: await normalizeBody(event)
|
|
39
40
|
};
|
|
40
41
|
}
|
|
41
42
|
function normalizeHeaders(headers) {
|
|
42
43
|
const headerMap = new HeaderMap();
|
|
43
|
-
for (const [key, value] of Object.entries(headers)) if (
|
|
44
|
-
else if (value) headerMap.set(key, value);
|
|
44
|
+
for (const [key, value] of Object.entries(headers)) if (value !== void 0) headerMap.set(key, value);
|
|
45
45
|
return headerMap;
|
|
46
46
|
}
|
|
47
|
-
function normalizeQueryString(url) {
|
|
48
|
-
if (!url) return "";
|
|
49
|
-
return url.split("?")[1] || "";
|
|
50
|
-
}
|
|
51
47
|
async function normalizeBody(event) {
|
|
52
|
-
|
|
48
|
+
const PayloadMethods = [
|
|
53
49
|
"PATCH",
|
|
54
50
|
"POST",
|
|
55
51
|
"PUT",
|
|
56
52
|
"DELETE"
|
|
57
|
-
]
|
|
53
|
+
];
|
|
54
|
+
const method = event.req.method;
|
|
55
|
+
if (method && PayloadMethods.includes(method)) return await readBody(event);
|
|
58
56
|
}
|
|
59
57
|
|
|
60
58
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nitro-graphql",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.23",
|
|
5
5
|
"description": "GraphQL integration for Nitro",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"sideEffects": false,
|
|
@@ -69,7 +69,6 @@
|
|
|
69
69
|
"peerDependencies": {
|
|
70
70
|
"@apollo/server": "^5.0.0",
|
|
71
71
|
"@apollo/utils.withrequired": "^3.0.0",
|
|
72
|
-
"@as-integrations/h3": "^2.0.0",
|
|
73
72
|
"graphql": "^16.11.0",
|
|
74
73
|
"h3": "^2.0.1-rc.2",
|
|
75
74
|
"nitro": "^3.0.1-alpha.0"
|
|
@@ -80,9 +79,6 @@
|
|
|
80
79
|
},
|
|
81
80
|
"@apollo/utils.withrequired": {
|
|
82
81
|
"optional": true
|
|
83
|
-
},
|
|
84
|
-
"@as-integrations/h3": {
|
|
85
|
-
"optional": true
|
|
86
82
|
}
|
|
87
83
|
},
|
|
88
84
|
"dependencies": {
|
|
@@ -119,10 +115,10 @@
|
|
|
119
115
|
"@vitejs/devtools": "^0.0.0-alpha.16",
|
|
120
116
|
"bumpp": "^10.3.1",
|
|
121
117
|
"changelogen": "^0.6.2",
|
|
122
|
-
"crossws": "0.
|
|
118
|
+
"crossws": "^0.4.1",
|
|
123
119
|
"eslint": "^9.39.1",
|
|
124
120
|
"graphql": "^16.12.0",
|
|
125
|
-
"graphql-yoga": "^5.16.
|
|
121
|
+
"graphql-yoga": "^5.16.2",
|
|
126
122
|
"h3": "^2.0.1-rc.5",
|
|
127
123
|
"nitro": "npm:nitro-nightly@latest",
|
|
128
124
|
"tsdown": "^0.16.1",
|