strawberry-graphql / strawberry-django

Strawberry GraphQL Django extension
https://strawberry.rocks/docs/django
MIT License
415 stars 121 forks source link

description and deprecation_reason parameters of enums values not used #512

Open stygmate opened 7 months ago

stygmate commented 7 months ago

description and deprecation_reason parameters of enums values are not used when enums are created from TextChoicesField. Only the global enum description is used.

example:

@strawberry.enum(description="global description")
class TypeDeBien(models.TextChoices):
    APPARTMENT = strawberry.enum_value(("App", "Appartment"), deprecation_reason="because", description="the best field !")
    OTHER = "Oth", "Other"

the schema produced only include the global description but not the value description or the deprecation reason.

Upvote & Fund

Fund with Polar

bellini666 commented 7 months ago

Hrmm, how does django handles that for you? I assumed strawberry.enum_value would be incompatible with django so I never tried to use it TBH

stygmate commented 7 months ago

@bellini666

It work. But...

TypeDeBien.choices contains:

[("EnumValueDefinition(value=('App', 'Appartment'), deprecation_reason='because', directives=(), description='the best field !')",
  'Appartment'),
 ('Oth', 'Other')]

So... it work but the db code used by Django may be the string containing the EnumValueDefinition... So... it don't really work 😅

Any workaround to add descriptions to enum_values ? (i need to document conditionally required fields when certain values are choosen)

bellini666 commented 7 months ago

Any workaround to add descriptions to enum_values ? (i need to document conditionally required fields when certain values are choosen)

That's a good question! Probably we would need to change strawberry itself to support adding those without actually changing the value itself.

@patrick91 any ideas here?

stygmate commented 7 months ago

Hi, Any news ?