graphql-python / graphql-python/gql

Automatically infer Type of Queries

未关闭
#373 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看
type: feature
主要语言
Python
星标
1.7k
派生
195
PR 合并指标
30 天内没有已合并 PR

描述

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

贡献指南

打开贡献指南

调研方向

Start by tracing the named .select(), DSLQuery, and dsl_gql entry points to understand how schema return types are currently handled. Compare the requested countries/name and nested continent/name examples with the existing selection behavior, then define and test the expected generated GraphQL for scalar and object selections.

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
api
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。