0xPlaygrounds / 0xPlaygrounds/subgrounds

Shorthand to grab the `Query` Object from the schema

Đang mở Phù hợp với người mới
#30 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
enhancement
Ngôn ngữ chính
Python
Star
73
Fork
12
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

**Is your feature request related to a problem? Please describe.**
Not a problem, but would reduced the need for unnecessary code.

Essentially, when playing around with a subgraph's schema, it is often useful to grab the `Query` GraphQL object which contains all toplevel fields that can be selected from the API. Currently, one has to go through the `SchemaMeta.type_map` dictionary, of which the type of the values is a union of all possible GraphQL types.

However, we know that `Query` will always be an `ObjectMeta` type. Moreover, we know that all GraphQL APIs have a `Query` object (it's part of the GraphQL specifications). Therefore, it would make sense to have a little helper for this.

**Describe the solution you'd like**
```python
schema: SchemaMeta = ...

# Instead of this
query_objectmeta = cast(TypeMeta.ObjectMeta, schema.type_map["Query"])

# This! query_objectmeta is correctly typed with TypeMeta.ObjectMeta
# SchemaMeta.query_object would be a property
query_objectmeta = schema.query_object
```

**Describe alternatives you've considered**
None. Apart from using a different name for the helper property (e.g.: `query_objectmeta`, or simply `query`)

**Additional context**
The same arguments could also be made for having helpers for the `Subscription` and `Mutation` objects, but these are not guaranteed to be present in a GraphQL API.

**Implementation checklist**
- [ ] Add `SchemaMeta.query_object` helper property

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

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

Hướng nghiên cứu

Look at the SchemaMeta class in the codebase to understand its structure and the type_map dictionary. The helper property should be added to SchemaMeta, likely in the same file. Check if there are existing tests for SchemaMeta to understand how to test the new property. The change is small and localized, focusing on adding a property that returns the 'Query' object from type_map with proper typing.

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

Đánh giá

Công nghệ
graphql, python
Lĩnh vực
api, developer-experience
Loại issue
Tính năng
Độ 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
65/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.