strawberry icon indicating copy to clipboard operation
strawberry copied to clipboard

mypy: Need type annotation for "graphql_app" [var-annotated]

Open yunzheng opened this issue 1 year ago • 3 comments

Since strawberry-graphql==0.169.0 mypy gives the following error on graphql_app = GraphQLRouter(schema):

app.py:16: error: Need type annotation for "graphql_app"  [var-annotated]
Found 1 error in 1 file (checked 1 source file)

Describe the Bug

pip install in your virtualenv:

pip install mypy fastapi strawberry-graphql==0.169.0

Take the example web application:

import strawberry

from fastapi import FastAPI
from strawberry.fastapi import GraphQLRouter


@strawberry.type
class Query:
    @strawberry.field
    def hello(self) -> str:
        return "Hello World"


schema = strawberry.Schema(Query)

graphql_app = GraphQLRouter(schema)

app = FastAPI()
app.include_router(graphql_app, prefix="/graphql")

Then run mypy:

$ mypy app.py

app.py:16: error: Need type annotation for "graphql_app"  [var-annotated]
Found 1 error in 1 file (checked 1 source file)

System Information

  • Operating system: Linux
  • Strawberry version (if applicable): 0.171.1

Additional Context

The problem does not happen in version 0.168.2:

$ pip install strawberry-graphql==0.168.2
$ mypy app.py
Success: no issues found in 1 source file

A workaround is to just annotate the graphql_app variable manually:

graphql_app: GraphQLRouter = GraphQLRouter(schema)

Of course it would be nicer if it can get fixed.

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar

yunzheng avatar Apr 13 '23 20:04 yunzheng