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

Move StrawberryConfig to a typed dict #2942

Open
patrick91 opened this issue Jul 12, 2023 · 4 comments
Open

Move StrawberryConfig to a typed dict #2942

patrick91 opened this issue Jul 12, 2023 · 4 comments
Labels

Comments

@patrick91
Copy link
Member

patrick91 commented Jul 12, 2023

as suggested in #2698 (comment)

we should change strawberry's schema config to be a type dictionary, I think this will make the dx a bit nicer, since you can do this:

import strawberry

...

schema = strawberry.Schema(..., config={"auto_camel_case": False})

which is a reduction of one import (and bit less characters) 😊

The main disadvantage for users it that they might not get autocompletion if their editor is not setup well.

The main disadvantage for us is that it might get a bit cumbersome to get values (or fallback to default values).

In any case if we do this, we should deprecate the old config, and write a codemod, which should be easy to do 😊

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
@skilkis
Copy link
Contributor

skilkis commented Aug 4, 2023

@patrick91 https://peps.python.org/pep-0705/ might be useful if it allows us to inherit from a base class that specifies the defaults

@jgadling
Copy link

jgadling commented Sep 7, 2023

As an alternative to TypedDict, which is pretty basic - the pydantic_settings module has an excellent configuration interface: https://docs.pydantic.dev/latest/usage/pydantic_settings/

It allows setting default values, enforces type/value validation, can take overrides from env vars by default, and be extended to read settings from a variety of different sources (config files, etc).

@patrick91
Copy link
Member Author

@jgadling thanks for the suggestion! I think that would be neat, but I'd prefer to keep the base dependencies at a minimum if possible 😊

@DoctorJohn DoctorJohn added the good first issue Good for newcomers label Nov 8, 2023
@Checho3388
Copy link

Hi @patrick91 ,
I'd like to contribute on this one. If you're Ok I'll create a MR with a proposal.

Changing straweery.Schema to expect a dict instead of a dataclass, would change the signature of the constructor in an incompatible manner. Have I understood this properly? Would this be a major change in RELEASE.md then?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants