CodeGenieApp / CodeGenieApp/serverless-express
Body data is not being parsed when programmatically invoking graphql handler in apollo-server-lambda v3
- Langage dominant
- JavaScript
- Étoiles
- 5.3k
- Forks
- 674
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
When programmatically invoking graphql handler in apollo-server-lambda v3, I receive the following error message: "POST body missing, invalid Content-Type, or JSON object has no keys.".
After reviewing the issue, I posted an [issue @ apollo-server](https://github.com/apollographql/apollo-server/issues/5504)
But it looks like the solution is to change the `@vendia/serverless-express` code as described below.
The body data is extracted by this code from utils.js (@vendia/serverless-express):
```javascript
function getEventBody ({
event,
body = event.body,
isBase64Encoded = event.isBase64Encoded
}) {
return Buffer.from(body, isBase64Encoded ? 'base64' : 'utf8')
}
function getRequestValuesFromEvent ({
...
if (event.body) {
body = getEventBody({ event })
const { isBase64Encoded } = event
headers['content-length'] = Buffer.byteLength(body, isBase64Encoded ? 'base64' : 'utf8')
}
...
}
```
But where is the code that `JSON.parse` the body data? Should it?
As an experiment, I changed the code from this...
```javascript
...
if (event.body) {
body = getEventBody({ event })
const { isBase64Encoded } = event
headers['content-length'] = Buffer.byteLength(body, isBase64Encoded ? 'base64' : 'utf8')
}
...
```
...to this:
```javascript
...
if (event.body) {
const decodedBody = getEventBody({ event })
const { isBase64Encoded } = event
headers['content-length'] = Buffer.byteLength(decodedBody, isBase64Encoded ? 'base64' : 'utf8')
body = JSON.parse(decodedBody);
}
...
```
and it worked as expected!
Should I submit a PR to @vendia/serverless-express ???
Guide de contribution
Ouvrir le guide de contribution
Piste de recherche
Commencez par utils.js, en particulier getEventBody et getRequestValuesFromEvent, et comparez la représentation du body attendue par le gestionnaire Apollo Server Lambda avec la valeur transmise par serverless-express. L’issue est résolue lorsque les appels GraphQL programmatiques traitent correctement le body de la requête sans casser le comportement existant de base64 et content-length, et que le comportement pertinent est vérifié.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- aws, express, graphql, javascript, nodejs
- Domaine
- api, backend, cloud
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- À clarifier
- Accessibilité débutants
- 25/100