Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

Scalar fields with resolvers don't work #23

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

Scalar fields with resolvers don't work #23

Jasonoro opened this issue Apr 8, 2020 · 3 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!

@lgnashold
Copy link

Looks like this issue is still present @ckarnell

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants