Validate resolver types against field types
See original GitHub issueCurrent we don’t throw errors in cases like this:
def example() -> str:
...
@strawberry.type
class Q:
x: int = strawberry.field(resolver=example)
We should raise an error when this happens. We should also maybe allow to change the error to a warning, to make it easier to upgrade.
We could also prevent this (maybe as opt-in/out behaviour):
def example(): # missing type
...
@strawberry.type
class Q:
x: int = strawberry.field(resolver=example)
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Resolvers - Apollo GraphQL Docs
Each resolver function belongs to whichever type its corresponding field belongs to. ... Here's a valid query against that schema: GraphQL.
Read more >Resolvers - TypeGraphQL
Besides declaring GraphQL's object types, TypeGraphQL allows us to easily create queries, mutations and field resolvers - like normal class methods, ...
Read more >Resolvers – GraphQL Tools
To respond to queries, a schema needs to have resolvers for all fields. Resolvers are per field functions that are given a parent...
Read more >The Spec, Simplified: Validation & Execution
Introspection, which defines the query fields and types that GraphQL ... against fields in the schema and calls resolvers to generate the ...
Read more >Custom Function Resolver examples for complex types
This is a one-time check used when compiling the application. Since data-types are invariant during execution, the one-time check is all that is ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m generating some of my resolvers dynamically. I don’t define the return type or use
Any
in this case. If you implement this feature please don’t forget this case as a resolver might return the right type at runtime but is unknown at the time it’s created.In my code it looks somewhat like that:
In #1449 I added a unit test for that. The PR is about resolvers in different modules, but the test also includes the part of a generic resolver (no type annotation).