strawberry-graphql / strawberry

A GraphQL library for Python that leverages type annotations 🍓
https://strawberry.rocks
MIT License
4.01k stars 533 forks source link

Move context out from info and expose it as a parameter #374

Open patrick91 opened 4 years ago

patrick91 commented 4 years ago

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

Fund with Polar

Speedy1991 commented 3 months ago

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