strawberry-graphql / strawberry

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

feat: Excluding a field from a type by making it private #3539

Open Eraldo opened 5 months ago

Eraldo commented 5 months ago

Describe the Bug/Feature

How to exclude a field from a type?

@strawberry.type(name="File")
class FileType(DjangoFileType):
    path: strawberry.Private[str]

Current: The path field still shows up in the schema. Expected: No more path field exposed.

Upvote & Fund

Fund with Polar

brunodantas commented 5 months ago

Hmm that's already a feature. Is it not working for Django types?

https://play.strawberry.rocks/?gist=5a61a5784811fa8f38d67f259ecde617

patrick91 commented 5 months ago

@brunodantas I think the issue is with overriding another type's file (DjangoFileType in this case)

erikwrede commented 4 months ago

For me this seems to be a strawberry-django issue. The django orm extension should respect field overrides when building the fields dict. Should we move it over? @bellini666 @patrick91

bellini666 commented 4 months ago

For me this seems to be a strawberry-django issue. The django orm extension should respect field overrides when building the fields dict. Should we move it over? @bellini666 @patrick91

Actually, I think it is what @patrick91 said.

That DjangoFileType is a general @strawberry.type inside strawberry-django. Here is the reproduction in the playground: https://play.strawberry.rocks/?gist=ef717257ca7a2db9085bbe1a44da5192

In this case, marking bar as Private in BarType should exclude it from the schema, while still showing on FooType in that example