score:3

Accepted answer

applymiddleware already adds body-parser for the graphql endpoint -- there's no need to apply it again and doing so may be causing your issue.

additionally, i would expect applymiddleware to be called before router.use('*', renderer) -- otherwise, i would think the wildcard route would be used for /graphql as well?

score:1

this error also caused by incorrect json in the body or some other problems in the body, such as unnecessary wrong invisible chars. so check generated json for errors and what is actually presents in the request body.

score:1

this error can also be raised because the body is too large.

i got it with apollo-server-micro inside a custom api route of nextjs.

it can be fixed by calling the json function coming from micro before apollo gets the request :

import { json } from 'micro'
import { apolloserver } from 'apollo-server-micro'

const server = new apolloserver({/*config*/})

const raisebodylimit: (handler: nextapihandler) => nextapihandler = (
  handler
) => async (req, res) => {
  if (req.headers['content-type'] !== 'application/json') {
    return handler(req, res)
  }
  
  await json(req, { limit: '1gb' }) // this is the trick to raise body limit
 
  return handler(req, res)
}

export default raisebodylimit(
    server.createhandler({
      path: '/api/graphql',
    })
)


i saw this in this apollo-server's github issue.

here are some information to build an apollo server endpoint with next.js

score:2

i forgot the header content-type: application/json

score:6

in my particular case the client just missed "content-type" header with 'application/json' value. after adding that the error message has dissapeared.


Related Query

More Query from same tag