Skip to content

add rudimentary typing to default_field_resolver #88

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

Merged
merged 1 commit into from
May 4, 2020

Conversation

hoefling
Copy link
Contributor

@hoefling hoefling commented May 1, 2020

It's me again with a type hints issue. I'm writing a custom field resolver:

def custom_field_resolver(source: Any, info: GraphQLResolveInfo, **args: Any) -> Any:
    if info.field_name == "foo" and hasattr(source, "bar"):
        return source.bar
    return default_field_resolver(source, info, **args)


result = await graphql_execute(
    ...,
    field_resolver=custom_field_resolver,
)

and have disallow_untyped_calls = True in my mypy config. Running the type check yields

<mymod>.py:<line>: error: Call to untyped function "default_field_resolver" in typed context

I'd thus propose to add at least a rudimentary typing to graphql.execute.default_field_resolver for now. Once Python 3.6 and 3.7 are dropped, I suppose a better typing using protocols could be possible.

Signed-off-by: oleg.hoefling oleg.hoefling@gmail.com

Verified

This commit was signed with the committer’s verified signature.
hoefling Oleg Höfling
Signed-off-by: oleg.hoefling <oleg.hoefling@gmail.com>
@hoefling hoefling requested a review from Cito as a code owner May 1, 2020 10:14
@Cito
Copy link
Member

Cito commented May 4, 2020

LGTM, thank you. I have created #89 to solve this more radically in the long run.

@Cito Cito merged commit b70dc63 into graphql-python:master May 4, 2020
Cito added a commit that referenced this pull request May 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants