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

Add __include__ to explicitly define exposed fields. #110

Open
1 of 3 tasks
foxyblocks opened this issue Jan 3, 2024 · 1 comment
Open
1 of 3 tasks

Add __include__ to explicitly define exposed fields. #110

foxyblocks opened this issue Jan 3, 2024 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@foxyblocks
Copy link

foxyblocks commented Jan 3, 2024

Feature Request Type

  • Core functionality
  • Alteration (enhancement/optimization) of existing feature(s)
  • New behavior

Description

I see that the __exclude__ property is available to specify the model fields that should be excluded from the graphql API but i'm wonder how you would go the other direction and only expose the fields that explicitly specified in an __include__ list.

The reason for this is that, with the current functionality, it would be easy for a developer to add a sensitive field to the data model and forget to exclude it from the graphql schema definition, thus exposing it to the API.

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
@erikwrede
Copy link
Member

erikwrede commented Jan 4, 2024

Sounds very useful! Maybe we can explicitly define the fields instead of doing include, such as in strawberry-django:

@strawberry_sqlalchemy.type
class OnlyIncluded:
  fieldA: strawberry.auto
  fieldB: strawberry.auto

and have the following rule:

If at least one field of the type is annotated with strawberry.auto, only fields listed with .auto will be included.

Of course we can map this to an __include__ internally, but this seems like a nice, readable and explicit case compared to a long list of excluded field names. Additionally, we can later expand it into strawberry_sqlalchemy.field(auto) to extend the functionality.

/cc @mattalbr

@erikwrede erikwrede added enhancement New feature or request help wanted Extra attention is needed labels Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants