GraphQL File Upload is not intercepted in NodeJS
See original GitHub issueEnvironment
Name | Version |
---|---|
msw | 0.26.2 |
node | 15.9.0 |
OS | Ubuntu |
Request handlers
/**
* @jest-environment node
*/
import { createReadStream } from 'fs'
import FormData from 'form-data'
import { graphql } from 'msw'
import { setupServer } from 'msw/node'
import fetch from 'node-fetch'
const server = setupServer()
server.listen({ onUnhandledRequest: 'warn' })
it('file upload', async () => {
const query = `
mutation UploadFile($file: Upload!) {
uploadFile(file: $file)
}
`
server.use(
graphql.mutation('UploadFile', (req, res, ctx) =>
res(ctx.data({ uploadFile: true })),
),
)
const form = new FormData()
form.append('operations', JSON.stringify({ query, variables: { file: null } }))
form.append('map', JSON.stringify({ '0': ['variables.file'] }))
form.append('0', createReadStream(__filename))
const response = await fetch('http://localhost:1234/api/graphql', {
method: 'POST',
body: form,
})
})
Current behavior
[MSW] Warning: captured a request without a matching request handler:
• POST http://localhost:1234/api/graphql
Expected behavior
Expected GraphQL File Upload request to be intercepted. What am I doing wrong?
P.S. Thanks for this awesome library!
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Developers - GraphQL File Upload is not intercepted in NodeJS -
Environment. Name Version msw 0.26.2 node 15.9.0 OS Ubuntu. Request handlers. /** * @jest-environment node */ import { createReadStream } from 'fs' import...
Read more >File uploads in Node.js < v8.5.0 - Apollo GraphQL Docs
File uploads are supported in Apollo Server 2.x through the third-party graphql-upload package. While Apollo Server 2.x aims to support Node.js LTS versions ......
Read more >NestJS upload using GraphQL - node.js - Stack Overflow
Using Base64 to upload files is not scalable, if you have multiple files to upload or with huge file sizes. It's possible now...
Read more >Upload File(s) to GraphQL Server using Postman, Axios and ...
In this video I've shown how to Upload Single/Multiple File to GraphQL Server using: -1. Postman2. Axios and3. Cypress (using XMLHttpRequest ...
Read more >Handle file uploads using a GraphQL middleware - Medium
Add a new scalar type (to be called Upload) at the input of our mutation,; Develop middleware to intercept the HTTP POST multipart/form-data ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve been experimenting with different FormData polyfills. Here are my observations:
@jest-environment node
@jest-environment jsdom
@kettanaito I’ve expected graphql upload to work since https://github.com/mswjs/msw/pull/543 is merged. In a real scenario I can’t send a JSON since I’m using external library for sending graphql requests which uses node-fetch and form-data.
Thanks for suggestions, I’ll try more digging and maybe send a PR