@graphcommerce/graphql-mesh 10.1.0-canary.31 → 10.1.0-canary.34
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/CHANGELOG.md +14 -0
- package/api/createEnvelop.ts +9 -0
- package/customFetch.ts +13 -2
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 10.1.0-canary.34
|
|
4
|
+
|
|
5
|
+
## 10.1.0-canary.33
|
|
6
|
+
|
|
7
|
+
### Patch Changes
|
|
8
|
+
|
|
9
|
+
- [#2648](https://github.com/graphcommerce-org/graphcommerce/pull/2648) [`24541b8`](https://github.com/graphcommerce-org/graphcommerce/commit/24541b8d3d7f5de80ebc7b9a03d439b4347eb9e6) - Fix multipart file uploads through the mesh returning "Unable to parse the request." in `next dev` (turbopack). `customFetch` used `globalThis.fetch` (undici) inside Next, while `@graphql-tools/executor-http` builds upload bodies with `FormData` from `@whatwg-node/fetch`. In `next dev`, `@whatwg-node/fetch` is evaluated while `next.config.ts` loads — before any `__NEXT` global exists — so its Next.js detection fails and it exports its ponyfills. Undici doesn't recognize the ponyfill `FormData` and stringified the request body to the literal `[object Object]`. `customFetch` now always uses the fetch exported by `@whatwg-node/fetch`, which is `globalThis.fetch` whenever the native path is active and the matching ponyfill fetch otherwise, so fetch and `FormData` always come from the same implementation family. ([@paales](https://github.com/paales))
|
|
10
|
+
|
|
11
|
+
## 10.1.0-canary.32
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#2644](https://github.com/graphcommerce-org/graphcommerce/pull/2644) [`c4ca56a`](https://github.com/graphcommerce-org/graphcommerce/commit/c4ca56a08915d918f78339ecddcc418dfc26857d) - Fix GraphQL multipart uploads (`Upload` scalar) through the Mesh. Next.js' pages-router bodyParser decodes multipart request bodies as UTF-8 text before Yoga can parse them, silently corrupting binary upload bytes (invalid UTF-8 sequences become replacement characters and the part's mime type is lost). The `/api/graphql` route now sets `bodyParser: false` so Yoga receives the raw stream, and `createServer` throws a descriptive error when it receives a multipart request whose body was already consumed by the bodyParser. ([@paales](https://github.com/paales))
|
|
16
|
+
|
|
3
17
|
## 10.1.0-canary.31
|
|
4
18
|
|
|
5
19
|
## 10.1.0-canary.30
|
package/api/createEnvelop.ts
CHANGED
|
@@ -8,6 +8,15 @@ export const createServer = async (endpoint: string) => {
|
|
|
8
8
|
|
|
9
9
|
const handler = createBuiltMeshHTTPHandler()
|
|
10
10
|
return async (req: NextApiRequest, res: NextApiResponse) => {
|
|
11
|
+
if (req.headers['content-type']?.startsWith('multipart/form-data') && req.body !== undefined) {
|
|
12
|
+
// Next's pages-router bodyParser has already consumed the request stream and decoded it as
|
|
13
|
+
// UTF-8 text, which corrupts binary `Upload` bytes (the multipart boundary survives, so the
|
|
14
|
+
// request would otherwise be forwarded with silently mangled file contents).
|
|
15
|
+
throw Error(
|
|
16
|
+
"Multipart GraphQL requests require Next.js' bodyParser to be disabled. Add `bodyParser: false` to the route config in pages/api/graphql.ts: export const config = { api: { externalResolver: true, bodyParser: false } }",
|
|
17
|
+
)
|
|
18
|
+
}
|
|
19
|
+
|
|
11
20
|
res.setHeader('Access-Control-Allow-Origin', req.headers.origin || '*')
|
|
12
21
|
const requestedHeaders = req.headers['access-control-request-headers']
|
|
13
22
|
if (requestedHeaders) {
|
package/customFetch.ts
CHANGED
|
@@ -2,8 +2,19 @@ import fetchRetry from 'fetch-retry'
|
|
|
2
2
|
import type { RequestInitWithRetry } from 'fetch-retry'
|
|
3
3
|
|
|
4
4
|
const fetcher = fetchRetry(
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Always use the fetch that `@whatwg-node/fetch` exports, never `globalThis.fetch` directly. When
|
|
7
|
+
* `@whatwg-node/fetch` detects a Next.js runtime it re-exports the native fetch primitives (so
|
|
8
|
+
* inside Next this IS `globalThis.fetch`/undici, keeping SSL handshakes alive), but when that
|
|
9
|
+
* detection fails — `next dev` (turbopack) evaluates it while loading `next.config.ts` (via
|
|
10
|
+
* `@graphql-codegen/cli`), before any `__NEXT` global exists — it exports its ponyfills instead.
|
|
11
|
+
* In that case `@graphql-tools/executor-http` builds multipart upload bodies with the ponyfill
|
|
12
|
+
* `FormData`, which undici doesn't recognize and stringifies to the literal `[object Object]`
|
|
13
|
+
* (Magento: "Unable to parse the request."). The fetch implementation must therefore always come
|
|
14
|
+
* from the same family as the `FormData`/`File` classes executor-http uses.
|
|
15
|
+
*/
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-var-requires
|
|
17
|
+
require('@whatwg-node/fetch').fetch,
|
|
7
18
|
)
|
|
8
19
|
|
|
9
20
|
/**
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphcommerce/graphql-mesh",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
-
"version": "10.1.0-canary.
|
|
5
|
+
"version": "10.1.0-canary.34",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@whatwg-node/fetch": "^0.10.13",
|
|
8
8
|
"fetch-retry": "^5.0.6",
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"@apollo/client": "*",
|
|
23
|
-
"@graphcommerce/eslint-config-pwa": "^10.1.0-canary.
|
|
24
|
-
"@graphcommerce/prettier-config-pwa": "^10.1.0-canary.
|
|
25
|
-
"@graphcommerce/typescript-config-pwa": "^10.1.0-canary.
|
|
23
|
+
"@graphcommerce/eslint-config-pwa": "^10.1.0-canary.34",
|
|
24
|
+
"@graphcommerce/prettier-config-pwa": "^10.1.0-canary.34",
|
|
25
|
+
"@graphcommerce/typescript-config-pwa": "^10.1.0-canary.34",
|
|
26
26
|
"@graphql-mesh/runtime": "*",
|
|
27
27
|
"@graphql-mesh/types": "*"
|
|
28
28
|
},
|