api-platform / api-platform/core

[GraphQL] Exception thrown when child nodes do not contain non-nullable fields

Đang mở
#2,132 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
GraphQL
Ngôn ngữ chính
PHP
Star
2.6k
Fork
980
Merge trung bình
2 ngày 5 giờ
Pull request đã merge (30 ngày)
48

Mô tả

Not sure how else to name this issue, but I'm having a bizarre issue.

I have a recursive relationship of User->ReferredBy (also a User). When I issue a request to retrieve Users, I ask for most of the data on the main user, but keep the data I request on the ReferredBy relationship to a minimum. But if I don't request non-nullable fields on the ReferredBy relationship, the response ends up being an HTTP 400 with errors attached.

In the example below, one of the non-nullable fields on my User entity is `points`. It always an int and has a value of >= 0. If I do not request `points` on the ReferredBy relation, then an exception is thrown. However, I can skip `points` on the top level User without any issues.

This is the request I am issuing:

```
query GetUsers($cursor: String, $query: String) {
users(after: $cursor, order: {name: "ASC"}, query: $query) {
edges {
cursor
node {
...UserFields
}
}
pageInfo {
endCursor
hasNextPage
}
}
}

fragment UserFields on User {
id
referredBy {
id
name
email
referralToken
}
name
email
referralToken
points
}
```

This results in an exception being thrown with the following response:

```json
{
"errors": [
{
"debugMessage": "Cannot return null for non-nullable field User.points.",
"message": "Internal server error",
"category": "internal",
"locations": [
{
"line": 29,
"column": 3
}
],
"path": [
"users",
"edges",
2,
"node",
"points"
]
}
],
"data": {
"users": {
"edges": [
{
"cursor": "MA==",
"node": {
"id": "/users/84cc1b30-6875-11e8-8dd5-f393655f85db",
"referredBy": null,
"name": "Administrator",
"email": "admin@test.com",
"referralToken": "623C33",
"points": 50
}
},
{
"cursor": "MQ==",
"node": {
"id": "/users/3d2f955c-8005-11e8-925e-ffad03401b2c",
"referredBy": {
"id": "/users/65dc3b1e-69de-11e8-8be9-5beebe7a0b50",
"name": "Test User 1",
"email": "test1@test.com",
"referralToken": "058D51"
},
"name": "Test User 2",
"email": "test2@test.com",
"referralToken": "A4965A",
"points": 50
}
},
{
"cursor": "Mg==",
"node": null
}
],
"pageInfo": {
"endCursor": "Mg==",
"hasNextPage": false
}
}
}
```

The only way I can get rid of this error is to request all non-nullable fields on the ReferredBy User relation. The weird part is that I can completely skip these non-nullable fields on the top level User, but I must always request them on child User nodes.

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

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

Đá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.