graphql-python / graphql-python/graphene

Root Value example doesn't work

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

Mô tả

The [Root Value](https://docs.graphene-python.org/en/latest/execution/execute/#root-value) example in the documentation:

```
from graphene import ObjectType, Field, Schema

class Query(ObjectType):
me = Field(User)

def resolve_user(root, info):
return {'id': root.id, 'firstName': root.name}

schema = Schema(Query)
user_root = User(id=12, name='bob')
result = schema.execute(
'''
query getUser {
user {
id
firstName
lastName
}
}
''',
root=user_root
)
assert result.data['user']['id'] == user_root.id
```

doesn't work. Throws `NameError: name 'User' is not defined`.

What's not clear is:

- Where `User` is defined -- is it defined somewhere else in the documentation? (hyperlink/inline)
- The `Query` field is named `me` yet the resolver function is named `resolve_user`.
- The executed query asks for `user` (not `me`).
- The created `User` object (assigned to `user_root`) is constructed to have a `name` field, yet the query asks for the `firstName` and `lastName` fields. Sure, `resolve_user` returns a dict with `id`, and `firstName`, but this adds to the confusion.

Having various combinations of `name`, `firstName` and `lastName` is confusing, especially in an example that doesn't work.

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

Hướng nghiên cứu

Bắt đầu với phần Root Value được liên kết trong tài liệu và kiểm tra toàn bộ ví dụ xung quanh phần đó. Làm cho định nghĩa User, tên trường, tên resolver, trường được truy vấn và các giá trị mẫu nhất quán để ví dụ có thể tự đầy đủ và thực thi được; xác minh ví dụ được ghi trong tài liệu sau khi chỉnh sửa.

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

Đánh giá

Công nghệ
python
Lĩnh vực
documentation
Loại issue
Tài liệu
Độ khó
2/5
Thời gian dự kiến
1-3 giờ
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
55/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.