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

Shorthand to grab the Query Object from the schema #30

Open
1 task
cvauclair opened this issue May 30, 2023 · 0 comments
Open
1 task

Shorthand to grab the Query Object from the schema #30

cvauclair opened this issue May 30, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@cvauclair
Copy link
Contributor

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

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
@cvauclair cvauclair added the enhancement New feature or request label May 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant