Graphene: Django Model charField with choices : query field

Created on 14 Jun 2016  路  5Comments  路  Source: graphql-python/graphene

I have some problems when I try to query a Django charField with choices.

I have the following models.py :

class Vehicle(models.Model):
    TYPE_CHOICES = (
        ('MOTO', _('MOTORBIKE')),
        ('CAR', _('car')),
        ('BIKE', _('bike')),
    )

    name = models.CharField(max_length=100)

    vtype = models.CharField(
        _('Vehicle type'),
        max_length=5,
        choices=TYPE_CHOICES,
        default='MOTO',
        help_text=_('Lorem ipsum')
    )

    description = models.TextField(blank=True, default='')

    def __str__(self):
        return self.name

and the following schema.py :

  class VehicleNode(DjangoNode):
      class Meta:
          model = Vehicle

When I try to make this query :

query {
  allVehicles {
    edges {
      node {
        id,
        name,
        vtype
      }
    }
  }
}

I have the following error :

{
  "errors": [
    {
      "message": "Cannot query field \"vtype\" on type \"VehicleNode\".",
      "locations": [
        {
          "line": 7,
          "column": 9
        }
      ]
    }
  ]
}

To be able to query vtype I need to add vtype = String() into my schema like that :

class VehicleNode(DjangoNode):
    vtype  = String()
    class Meta:
        model = Vehicle

I don't know if I missed something ?

Most helpful comment

I have the same issue here

All 5 comments

Does it work if you define everything as plain strings instead of using _('xxxxx')?

No, I have the same issue

I have the same issue here

This should be fixed in graphene-django:master. Closing here :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mandx picture mandx  路  4Comments

romaia picture romaia  路  3Comments

defrex picture defrex  路  3Comments

Globegitter picture Globegitter  路  4Comments

tricoder42 picture tricoder42  路  4Comments