Open parafoxia opened 4 months ago
@parafoxia I think the types might be wrong, this was changed a year ago: https://github.com/encode/starlette/pull/2180
but our code still works, no?
Yeah it still works. In fact when done like this (on mobile so might be wrong but you get the idea):
app = Starlette(
routes=[
...,
GraphQL[None, None](schema),
]
)
Mypy doesn't complain like it did. I haven't run it on strict though, but at least normal Mypy is fine with it.
Btw, slight tangent, would there be something better to use than [None, None]
? I'm not really sure what those two types are -- I've seen Context
used in the first around the place.
@parafoxia I'll make a PR to remove the need for [None, None]
that should only be used when subclassing π
Yeah it still works. In fact when done like this (on mobile so might be wrong but you get the idea):
app = Starlette( routes=[ ..., GraphQL[None, None](schema), ] )
Mypy doesn't complain like it did. I haven't run it on strict though, but at least normal Mypy is fine with it.
I'll ask @Kludex if this is expected tomorrow π if so I can make a PR to adjust the typing on Starlette π
Awesome, cheers!
Wrt subclassing, I am actually subclassing now to overload the encode_json to use orjson
-- would there be something better than [None, None]
in this case?
something like this:
class MyGraphQL(GraphQL[MyContextType, MyRootType]:
...
MyContextType is the return type of get_context and MyRootType is the return type of get_root_value π
Oooh I see, that makes a lot of sense! That could actually prove useful -- thanks for explaining that!
Describe the Bug
The following code is more or less a copy of what appears in the docs:
However, it raises the following typing error:
While the code does actually run and appears to function correctly, Mypy is flagging incompatible signatures.
The signature for the
route
parameter for theadd_route
method:The signature of the
GraphQL.__call__
method:The latter signature is the same as the signature for Starlette middleware. I'm presuming Mypy is getting confused, or something isn't properly deliniated to Mypy and it's assuming something it shouldn't be, as the code does work.
It's also worth noting that the documentation should be updated to use full type annotations.
System Information
Additional Context
Starlette version 0.37.2.
Upvote & Fund