strawberry icon indicating copy to clipboard operation
strawberry copied to clipboard

Move context out from info and expose it as a parameter

Open patrick91 opened this issue 5 years ago • 1 comments

Being able to request info (and root) only when needed is a nice feature, but considering we haven't exposed a type for info yet, it might be nice to all to request for context as well

So, from this:

@strawberry.federation.type(extend=True)
class Query:
    @strawberry.field
    def strawberry(self, info) -> str:
        return info.context.strawberry_repo.get_one()

to this:

@strawberry.federation.type(extend=True)
class Query:
    @strawberry.field
    def strawberry(self, context: MyContextType) -> str:
        return context.strawberry_repo.get_one()

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

patrick91 avatar Jul 10 '20 13:07 patrick91

Ah this would be awesome! It would also solve the problem with PyCharm not autocompleting custom contextes without the mypy plugin!

Speedy1991 avatar Jul 25 '24 09:07 Speedy1991

I was thinking about this today, and I think it could be interesting to create a StrawberryContext type that we can use to understand which argument is the context

patrick91 avatar Sep 04 '25 19:09 patrick91