99designs / 99designs/gqlgen

Weak type validation?

Đang mở
#1,522 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Go
Star
10.8k
Fork
1.3k
Merge trung bình
2 ngày 36 phút
Pull request đã merge (30 ngày)
26

Mô tả

### What happened?
The GraphQL type definition is not being respected.
In the definition we force the quantity to be an integer. However, the consumer of the API can bypass that validation by passing a string. The gqlgen library will try to parse it internaly anyway.

### What did you expect?
We expect that gqlgen respects the definition and returns a `GRAPHQL_VALIDATION_FAILED` error code in case the consumer passes an invalid type, which in this case is a string instead of an integer.

### Minimal graphql.schema and models to reproduce
```
updateItems(
"A list of item data."
items: [UpdateItemInput!]!

"Language code (two-letter code: ISO 639-1)."
languageCode: String
): Cart

input UpdateItemInput {
"The item number."
itemNo: ID!

"The item quantity."
quantity: Int!
}
```

```
curl --request POST \
--url https://app.com/graphql \
--data '{"query":"\n mutation UpdateItems(\n $items: [UpdateItemInput!]!\n $languageCode: String\n ) {\n updateItems(items: $items, languageCode: $languageCode) {\n items {\n quantity\n }\n }\n }\n ","variables":{"items":[{"itemNo":"12345678","quantity":"test"}],"languageCode":"cs"},"operationName":"UpdateItems"}'
```

### versions
- `gqlgen version 1.15`
- `go version 0.13.0`?

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

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Hãy xem xét logic validation của thư viện gqlgen dành cho các input type, đặc biệt là cách nó xử lý các field Int!. Issue này hiển thị một GraphQL schema và một curl request truyền một string cho một field integer. Trước tiên, hãy tìm nơi type coercion hoặc validation diễn ra trong codebase, nhiều khả năng là trong một package như graphql/executor hoặc graphql/parser. Chạy ví dụ được cung cấp để xem behavior hiện tại, sau đó kiểm tra cách xử lý validation error hiện có. Mục tiêu là để thư viện trả về lỗi GRAPHQL_VALIDATION_FAILED thay vì cố gắng parse string.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
go, graphql
Lĩnh vực
api, backend
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
45/100

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.