-
-
Notifications
You must be signed in to change notification settings - Fork 436
fix: Handle multipart file uploads in GraphQL proxy #11773
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix: Handle multipart file uploads in GraphQL proxy #11773
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
The GraphQL API proxy routes were using JSON.stringify(req.body) which corrupts multipart form data for file uploads. Changes: - Disable Next.js body parsing to get raw request body - Detect multipart requests via Content-Type header - Forward multipart bodies as raw Buffer, not JSON stringified - Keep JSON request handling unchanged Fixes #11772 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
6b2ab92 to
014cc7c
Compare
pages/api/graphql/v1.js
Outdated
| const rawBody = await getRawBody(req); | ||
| const jsonBody = JSON.parse(rawBody.toString() || '{}'); | ||
| body = JSON.stringify(jsonBody); |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
Address Sentry review feedback: JSON.parse() without try/catch causes unhandled errors when clients send malformed JSON. Now returns a proper 400 Bad Request with GraphQL-formatted error response instead of crashing. Added test cases for both v1 and v2 proxies to verify behavior. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
Sentry Review AddressedAdded error handling for Manual Testing NoteThe unit tests comprehensively cover:
Full manual testing with actual file upload requires a valid staging account. The dev server starts successfully and the API proxy routes are accessible at |
Address Sentry review feedback: getRawBody() did not handle stream errors. If a client disconnects during a file upload, the stream emits an error that was previously unhandled, causing the server to crash. Now wraps the body reading in try/catch and returns a proper 500 response with GraphQL-formatted error message. Added test cases for both v1 and v2 proxies to verify behavior. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
Second Sentry Review AddressedAdded stream error handling (commit 0fbf2b3):
All Sentry feedback now addressed:
|
Summary
Fixes opencollective/opencollective#8458
Fixes opencollective/opencollective#8456
The GraphQL API proxy routes (
pages/api/graphql/v1.jsandv2.js) were usingJSON.stringify(req.body)which corrupts multipart form data for file uploads via theuseGraphQLFileUploaderhook.This also resolves the API issue opencollective/opencollective#8456 - while the direct API endpoint (
api.opencollective.com) still has infrastructure issues with multipart, the frontend Apollo client uses the proxy path (/api/graphql/v2) which now works correctly.Changes
bodyParser: false) to get raw request bodyContent-TypeheaderTest plan
Related
🤖 Generated with Claude Code