@as-integrations/h3 1.1.5 → 1.1.6

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/dist/index.cjs CHANGED
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ const server = require('@apollo/server');
3
4
  const h3 = require('h3');
4
5
 
5
6
  function startServerAndCreateH3Handler(server, options) {
@@ -41,7 +42,7 @@ async function toGraphqlRequest(event) {
41
42
  };
42
43
  }
43
44
  function normalizeHeaders(headers) {
44
- const headerMap = /* @__PURE__ */ new Map();
45
+ const headerMap = new server.HeaderMap();
45
46
  for (const [key, value] of Object.entries(headers)) {
46
47
  if (Array.isArray(value)) {
47
48
  headerMap.set(key, value.join(","));
@@ -60,12 +61,7 @@ function normalizeQueryString(url) {
60
61
  async function normalizeBody(event) {
61
62
  const PayloadMethods = ["PATCH", "POST", "PUT", "DELETE"];
62
63
  if (h3.isMethod(event, PayloadMethods)) {
63
- const body = await h3.readRawBody(event);
64
- if (h3.getRequestHeader(event, "content-type")?.includes("application/json")) {
65
- return body ? JSON.parse(body) : {};
66
- } else {
67
- return body;
68
- }
64
+ return await h3.readBody(event);
69
65
  }
70
66
  }
71
67
 
@@ -0,0 +1,14 @@
1
+ import { BaseContext, ContextFunction, ApolloServer } from '@apollo/server';
2
+ import { H3Event, EventHandler } from 'h3';
3
+
4
+ type WithRequired<T, K extends keyof T> = T & Required<Pick<T, K>>;
5
+ interface H3ContextFunctionArgument {
6
+ event: H3Event;
7
+ }
8
+ interface H3HandlerOptions<TContext extends BaseContext> {
9
+ context?: ContextFunction<[H3ContextFunctionArgument], TContext>;
10
+ }
11
+ declare function startServerAndCreateH3Handler(server: ApolloServer<BaseContext>, options?: H3HandlerOptions<BaseContext>): EventHandler;
12
+ declare function startServerAndCreateH3Handler<TContext extends BaseContext>(server: ApolloServer<TContext>, options: WithRequired<H3HandlerOptions<TContext>, 'context'>): EventHandler;
13
+
14
+ export { type H3ContextFunctionArgument, type H3HandlerOptions, startServerAndCreateH3Handler };
@@ -0,0 +1,14 @@
1
+ import { BaseContext, ContextFunction, ApolloServer } from '@apollo/server';
2
+ import { H3Event, EventHandler } from 'h3';
3
+
4
+ type WithRequired<T, K extends keyof T> = T & Required<Pick<T, K>>;
5
+ interface H3ContextFunctionArgument {
6
+ event: H3Event;
7
+ }
8
+ interface H3HandlerOptions<TContext extends BaseContext> {
9
+ context?: ContextFunction<[H3ContextFunctionArgument], TContext>;
10
+ }
11
+ declare function startServerAndCreateH3Handler(server: ApolloServer<BaseContext>, options?: H3HandlerOptions<BaseContext>): EventHandler;
12
+ declare function startServerAndCreateH3Handler<TContext extends BaseContext>(server: ApolloServer<TContext>, options: WithRequired<H3HandlerOptions<TContext>, 'context'>): EventHandler;
13
+
14
+ export { type H3ContextFunctionArgument, type H3HandlerOptions, startServerAndCreateH3Handler };
package/dist/index.d.ts CHANGED
@@ -11,4 +11,4 @@ interface H3HandlerOptions<TContext extends BaseContext> {
11
11
  declare function startServerAndCreateH3Handler(server: ApolloServer<BaseContext>, options?: H3HandlerOptions<BaseContext>): EventHandler;
12
12
  declare function startServerAndCreateH3Handler<TContext extends BaseContext>(server: ApolloServer<TContext>, options: WithRequired<H3HandlerOptions<TContext>, 'context'>): EventHandler;
13
13
 
14
- export { H3ContextFunctionArgument, H3HandlerOptions, startServerAndCreateH3Handler };
14
+ export { type H3ContextFunctionArgument, type H3HandlerOptions, startServerAndCreateH3Handler };
package/dist/index.mjs CHANGED
@@ -1,4 +1,5 @@
1
- import { eventHandler, isMethod, setHeaders, getHeaders, readRawBody, getRequestHeader } from 'h3';
1
+ import { HeaderMap } from '@apollo/server';
2
+ import { eventHandler, isMethod, setHeaders, getHeaders, readBody } from 'h3';
2
3
 
3
4
  function startServerAndCreateH3Handler(server, options) {
4
5
  server.startInBackgroundHandlingStartupErrorsByLoggingAndFailingAllRequests();
@@ -39,7 +40,7 @@ async function toGraphqlRequest(event) {
39
40
  };
40
41
  }
41
42
  function normalizeHeaders(headers) {
42
- const headerMap = /* @__PURE__ */ new Map();
43
+ const headerMap = new HeaderMap();
43
44
  for (const [key, value] of Object.entries(headers)) {
44
45
  if (Array.isArray(value)) {
45
46
  headerMap.set(key, value.join(","));
@@ -58,12 +59,7 @@ function normalizeQueryString(url) {
58
59
  async function normalizeBody(event) {
59
60
  const PayloadMethods = ["PATCH", "POST", "PUT", "DELETE"];
60
61
  if (isMethod(event, PayloadMethods)) {
61
- const body = await readRawBody(event);
62
- if (getRequestHeader(event, "content-type")?.includes("application/json")) {
63
- return body ? JSON.parse(body) : {};
64
- } else {
65
- return body;
66
- }
62
+ return await readBody(event);
67
63
  }
68
64
  }
69
65
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@as-integrations/h3",
3
- "version": "1.1.5",
3
+ "version": "1.1.6",
4
4
  "description": "An Apollo Server integration for use with h3 or Nuxt",
5
5
  "repository": "github:apollo-server-integrations/apollo-server-integration-h3",
6
6
  "license": "MIT",
@@ -8,7 +8,6 @@
8
8
  "type": "module",
9
9
  "exports": {
10
10
  ".": {
11
- "types": "./dist/index.d.ts",
12
11
  "import": "./dist/index.mjs",
13
12
  "require": "./dist/index.cjs"
14
13
  }
@@ -21,31 +20,31 @@
21
20
  ],
22
21
  "peerDependencies": {
23
22
  "@apollo/server": "^4.1.1",
24
- "h3": "^0.8.6 || ^1.0.0"
23
+ "h3": "^1.8.0"
25
24
  },
26
25
  "devDependencies": {
27
- "@apollo/server": "^4.3.1",
28
- "@apollo/server-integration-testsuite": "^4.3.1",
29
- "@apollo/utils.withrequired": "^2.0.0",
30
- "@jest/globals": "^29.3.1",
26
+ "@apollo/server": "^4.9.1",
27
+ "@apollo/server-integration-testsuite": "^4.9.1",
28
+ "@apollo/utils.withrequired": "^3.0.0",
29
+ "@jest/globals": "^29.6.3",
31
30
  "@nuxtjs/eslint-config-typescript": "^12.0.0",
32
- "@typescript-eslint/eslint-plugin": "^5.48.2",
33
- "@typescript-eslint/parser": "^5.48.2",
34
- "@vitest/coverage-c8": "^0.27.2",
35
- "eslint": "^8.32.0",
36
- "eslint-config-prettier": "^8.6.0",
37
- "eslint-plugin-unused-imports": "^2.0.0",
38
- "graphql": "^16.6.0",
39
- "h3": "^1.0.2",
40
- "jest": "^29.3.1",
41
- "prettier": "^2.8.3",
31
+ "@typescript-eslint/eslint-plugin": "^6.4.1",
32
+ "@typescript-eslint/parser": "^6.4.1",
33
+ "@vitest/coverage-c8": "^0.33.0",
34
+ "eslint": "^8.47.0",
35
+ "eslint-config-prettier": "^9.0.0",
36
+ "eslint-plugin-unused-imports": "^3.0.0",
37
+ "graphql": "^16.8.0",
38
+ "h3": "^1.8.0",
39
+ "jest": "^29.6.3",
40
+ "prettier": "^3.0.2",
42
41
  "standard-version": "^9.5.0",
43
- "ts-jest": "^29.0.5",
44
- "typescript": "^4.9.4",
45
- "unbuild": "^1.1.1",
46
- "vitest": "^0.27.2"
42
+ "ts-jest": "^29.1.1",
43
+ "typescript": "^5.1.6",
44
+ "unbuild": "^2.0.0",
45
+ "vitest": "^0.34.2"
47
46
  },
48
- "packageManager": "pnpm@7.25.1",
47
+ "packageManager": "pnpm@8.6.12",
49
48
  "scripts": {
50
49
  "build": "unbuild",
51
50
  "test": "vitest dev",