CodeGenieApp / CodeGenieApp/serverless-express
Body data is not being parsed when programmatically invoking graphql handler in apollo-server-lambda v3
- 主要言語
- JavaScript
- スター
- 5.3k
- フォーク
- 676
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
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 ???
コントリビューションガイド
調査の方向性
utils.js、特に getEventBody と getRequestValuesFromEvent から始め、Apollo Server Lambda ハンドラーが想定する body の表現と、serverless-express が渡す値を比較します。プログラムによる GraphQL 呼び出しがリクエスト body を正しく処理し、既存の base64 と content-length の動作を壊さず、関連する動作が検証されれば、issue は解決です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- aws, express, graphql, javascript, nodejs
- 領域
- api, backend, cloud
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 25/100