apollographql / apollographql/fullstack-tutorial

Bug in cancelTrip method from User datasource

Đang mở
#116 0 bình luận 0 reaction 1 người được giao Được @stemmlerjs nhận Xem trên GitHub
bug
Ngôn ngữ chính
TypeScript
Star
1.2k
Fork
808
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

https://github.com/apollographql/fullstack-tutorial/blob/66431a74abbdfd432157ec36a2fb7cd9f0b80be4/start/server/src/datasources/user.js#L60

Due to this line `cancelTrip` throws an error.

```sh
{
"errors": [
{
"message": "Cannot read property 'flight_number' of undefined",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"cancelTrip"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"stacktrace": [
"TypeError: Cannot read property 'flight_number' of undefined",
// ....
```
Following change will fix the error.

```
async cancelTrip({ launchId }) {
const userId = this.context.user.id;
const numberOfDeletedTrips = await this.store.trips.destroy({ where: { userId, launchId } });
return numberOfDeletedTrips !== 0;
}
```
As per the [doc of `destroy`](https://sequelize.org/master/class/lib/model.js~Model.html#static-method-destroy) it returns number of deleted resources wrapped in Promise. So it should be resolved to get the count to decide if resources are deleted or not.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.