graphene-django icon indicating copy to clipboard operation
graphene-django copied to clipboard

How to add description to fields?

Open Dawidpol opened this issue 7 years ago • 4 comments

It is connected to #208, to this comment Let's say I have this model:

class Country(models.Model):
    code = models.CharField(max_length=5, null=True)
    name = models.CharField(max_length=100, null=True)

and in schema i have

class CountryNode(DjangoObjectType):
    class Meta:
        model = Country
        description = "This is a Country Node"

I can add a description for CountryNode itself, but how to do it for Country code and name?

Dawidpol avatar Aug 12 '19 02:08 Dawidpol

code = models.CharField(max_length=5, null=True, help_text="This is a code field")

dan-klasson avatar Aug 12 '19 07:08 dan-klasson

you can define a field with same name in your DjangoObjectType if you do not want update the model 😄

class CountryNode(DjangoObjectType):`
    class Meta:
        model = Country
        description = "This is a Country Node"

    code = graphene.String(description="This is a code field")

liupengf12 avatar Aug 25 '19 02:08 liupengf12

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Nov 23 '19 03:11 stale[bot]

Closing this issue @Dawidpol because @dan-klasson and @liupengf12 have provided some solutions to the problem.

jkimbo avatar Nov 28 '19 10:11 jkimbo