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

Misleading static type for "execution result" attribute (introduced in 0.240.0) #3635

Open
kkom opened this issue Sep 19, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@kkom
Copy link

kkom commented Sep 19, 2024

I think #3554 introduce a static typing bug in the execution result attribute.

It's statically typed as graphql.ExecutionResult type from graphql-core:

from graphql import ExecutionResult as GraphQLExecutionResult

result: Optional[GraphQLExecutionResult] = None

But in reality it's this custom dataclass from Strawberry's codebase (at least in some situations):

@dataclasses.dataclass
class ExecutionResult:
data: Optional[Dict[str, Any]]
errors: Optional[List[GraphQLError]]
extensions: Optional[Dict[str, Any]] = None
@dataclasses.dataclass
class PreExecutionError(ExecutionResult):
"""Differentiate between a normal execution result and an immediate error.
Immediate errors are errors that occur before the execution phase i.e validation errors,
or any other error that occur before we interact with resolvers.
These errors are required by `graphql-ws-transport` protocol in order to close the operation
right away once the error is encountered.
"""

PS: The specific problem is the typechecker makes us think it's okay to access the formatted property, which is actually missing:

https://github.com/graphql-python/graphql-core/blob/26701397d84338a42c7acbce78368ae8f9d97271/src/graphql/execution/incremental_publisher.py#L97-L105

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
@kkom kkom added the bug Something isn't working label Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant