问题描述
我正在尝试将 rest
端点更改为 graphql
,并且我有一个名为 TaggableManager
的库作为模型之一字段
.任何人都知道这可以与graphql一起使用吗?
I am trying to change my rest
end points to graphql
and I had a library called TaggableManager
as one of the model fields
. Anyone know how this can work with graphql?
预先感谢
推荐答案
您必须明确告诉graphene如何转换 TaggableManger
字段以在查询中使用.在将模型与查询
或中的
. TaggableManger
字段一起使用之前,从 graphene_django.converter
注册 @convert_django_field
.突变
You have to explicitly tell graphene how to convert the TaggableManger
field to be used in Queries. Register @convert_django_field
from graphene_django.converter
before using your model with the TaggableManger
field either in Queries
or Mutations
.
示例:
from graphene_django.converter import convert_django_field
from taggit.managers import TaggableManager
# convert TaggableManager to string representation
@convert_django_field.register(TaggableManager)
def convert_field_to_string(field, registry=None):
return String(description=field.help_text, required=not field.null)
这篇关于不知道如何转换Django现场技能(< class'taggit.managers.TaggableManager'>)?图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!