Automatically infer Type of Queries
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
Research direction
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.
Written by the indexing model from the issue text.
Description
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
- Dominant language
- Python
- Stars
- 1.7k
- Forks
- 195
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from graphql-python/gql
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
graphql-python/gql#613 · 2 comments ·
-
type: feature
Difficulty 3/5 1-2 days Newbie friendliness 42/100
graphql-python/gql#434 ·
-
type: feature
Difficulty 3/5 1-2 days Newbie friendliness 42/100
graphql-python/gql#355 · 1 comment ·
-
type: feature
Difficulty 5/5 Over a week Newbie friendliness 25/100
graphql-python/gql#316 · 5 comments · 3 reactions ·
All issues in graphql-python/gql
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
learningequality/ricecooker#747 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
BSData/horus-heresy-3rd-edition#3171 ·
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
run-llama/llama_index#23199 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
KhronosGroup/glTF-Blender-IO#2769 ·