Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically infer Type of Queries #373

Open
amard33p opened this issue Nov 30, 2022 · 0 comments
Open

Automatically infer Type of Queries #373

amard33p opened this issue Nov 30, 2022 · 0 comments
Labels
type: feature A new feature

Comments

@amard33p
Copy link

amard33p commented Nov 30, 2022

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

@leszekhanusz leszekhanusz added the type: feature A new feature label Nov 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature A new feature
Projects
None yet
Development

No branches or pull requests

2 participants