0

I spent hours on this and no luck it looks like a bug. All fields show up in the results of my query but the "type" and there is no difference between the "type" and the "issuer" for example, both are foriegn keys. Graphene randomly removes the type while it is there and when I print it in the resolver i see it has a value. When I try to query the field type in graphiql i get the following error: "Cannot query field \"type\" on type \"Post\"." Any thought?

class T(models.Model):
    type=models.CharField(default="type 1",null=False,blank=False,max_length=40)

    def str(self):
        return self.type

class Post(models.Model):
    slug=models.SlugField(unique=True)
    issuer=models.ForeignKey(User,on_delete=models.SET_NULL,blank=False,null=True,related_name="posts")
    date_created=models.DateTimeField(default=timezone.now)
    last_edited=models.DateTimeField(null=True)
    num_interests = models.IntegerField(verbose_name="Number of interests so far",default=0)
    status=models.CharField(max_length=30,default="posted")
    tags=TaggableManager()
    title=models.CharField (max_length=200,blank=False)
    description =models.TextField(max_length=settings.MAX_TEXTAREA_LEN,default="",
    validators=[MaxLengthValidatorFactory(settings.MAX_TEXTAREA_LEN)],blank=False)
    goodUntil = models.DateField(verbose_name=_("Date"),default=datetime.now()+timedelta(days=7))
    subjects=models.ManyToManyField(to=Subject,related_name='posts',blank=False)
    type=models.ForeignKey(T,on_delete=models.SET_NULL,blank=False,null=True,related_name="type")
Kevin
  • 959
  • 10
  • 14
Hamid
  • 59
  • 2

1 Answers1

0

If I recall correctly, this is a bug in graphene -- graphene uses type internally which interferes with a model field with that name. I believe that I may have encountered this problem in the past and solved it by renaming my model fields.

In your case, for example, rename type -> post_type.

It's understandable that graphene has this limitation, because __type has a specific meaning in graphQL. For example, this is a valid query for a DjangoObjectType called "MyType":

{ __type(name:"MyType") {
    fields {
      name
      description
      }  
    }
}
Mark Chackerian
  • 21,866
  • 6
  • 108
  • 99