Open gustawdaniel opened 4 years ago
To fix you need add line
app.use(bodyParser.json({type: 'application/json'}))
but nothing about this case in docs is mentioned. I propose to add to docs section about connecting bodyParser with nexus-graphql.
For now, a brief mention about customizing server body parsing could go into the server docs section. PR welcome. Can start very simple.
Running in to the same issue, it's my understanding that when using body-parser
you should be able to specify the Content-Type
you'd like to have filtered by the body parser middleware. For example, I need to parse a body of type application/octet-stream
from Google Cloud Tasks that is attempting to hit my Nexus api. However, when I add the following in my app.ts
to accept octet-stream
:
server.express.use(bodyParser.raw({type: 'application/octet-stream'}));
I receive the following error when trying to send any kind of request (even from graphql playground):
■ nexus:server:graphql BadRequestError: request.body json expected to have a query field
at /Users/jordan/GitHub/releasehub-app/server/node_modules/nexus/dist/runtime/server/handler-graphql.js:21:60
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async /Users/jordan/GitHub/releasehub-app/server/node_modules/nexus/dist/runtime/server/server.js:101:9
But if I add in:
server.express.use(bodyParser.json());
beneath this .raw()
then things work as normal. Seems like odd behavior.
I have code
And tests
It works. But when I am adding
bodyParser
to make possible uploading filesso my file looks like this:
then
my test are broken
and I can see error: