graphql-python / graphql-python/gql

Automatically infer Type of Queries

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

Mô tả

For the following query on https://countries.trevorblades.com/
```
query GetCountries {
countries {
name
}
}
```
The snippet to generate this dynamically using gql is:
```
dsl_gql(
GetCountries=DSLQuery(
ds.Query.countries.select(ds.Country.name)
)
)
```
Notice that in the raw graphql I just mentioned `name` instead of `Country.name`. As the schema already lays out the return types of all queries, graphql is able to figure it out automatically.
```
""" schema.graphql """
type Query {
...
countries(filter: CountryFilterInput): [Country!]!
...
}

type Country {
...
name: String!
...
}
```
Would it be possible to modify `.select()` to auto-select objects of the query type by their name?
Maybe something like:
```
dsl_gql(
GetCountries=DSLQuery(
ds.Query.countries.select("name", DSLAutoSelectable("continent").select("name"))
)
)
```
Resulting graphql
```
query GetCountries {
countries {
name
continent {
name
}
}
}
```

Note: The sgqlc library has a `__fields__()` method which can get the *immediate* scalars by name: https://github.com/profusion/sgqlc/blob/465a5e800f8b408ceafe25cde45ee0bde4912482/sgqlc/operation/__init__.py#L390

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.