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

Scalar fields with resolvers don't work #23

Open
Jasonoro opened this issue Apr 8, 2020 · 2 comments
Open

Scalar fields with resolvers don't work #23

Jasonoro opened this issue Apr 8, 2020 · 2 comments

Comments

@Jasonoro
Copy link
Contributor

Jasonoro commented Apr 8, 2020

According to the graphene documentation, the following is the same:

class Person(graphene.ObjectType):
    name = graphene.String()

# Is equivalent to:
class Person(graphene.ObjectType):
    name = graphene.Field(graphene.String)

However, graphene-stubs doesn't allow the above example when using resolvers.

from graphene import ObjectType, String
from graphql import ResolveInfo


class Person(ObjectType):
    name = String()

    @staticmethod
    def resolve_name(_, __: ResolveInfo) -> str:
        return "Test"
$ mypy test.py
test.py:11: error: No field with name "name" defined
Found 1 error in 1 file (checked 1 source file)

When wrapping it in a Field it's fine. Is this a known limitation or would this classify as a bug that can be fixed?

@ckarnell
Copy link

ckarnell commented Apr 9, 2020

Yeah, as long as that's valid at runtime, this is a bug and there should be no type error. Feel free to make a PR if you'd like to fix! Otherwise I'll try to get to it at some point.

@matclayton
Copy link

We've just come across this exact issue as well, and its throwing hundreds of errors for us :( I'm not quite sure I understand the MyPy plugin structure or graphene-stubs well enough to make a patch, but I'll see if we have time to. Did anyone else manage to make this work?

Thank you for such a fantastic project!

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

No branches or pull requests

3 participants