Mar*_*ere 6 python django graphql graphene-python
我正在graphene-django用来构建我的 API。我有一个 DjangoObjectType StoreType,它代表模型商店。这个模型有一个 MultiSelectField 命名opening_days,指示商店在一周中的哪几天营业。为了创建新商店,我使用了这个突变:
class Weekdays(graphene.Enum):
MO = "Mo"
TU = "Tu"
WE = "We"
TH = "Th"
FR = "Fr"
SA = "Sa"
SU = "Su"
class CreateStore(graphene.Mutation):
store = graphene.Field(StoreType)
class Arguments:
opening_days = graphene.Argument(graphene.List(Weekdays))
def mutate(self, info, opening_days):
store = Store(opening_days=opening_days)
store.save()
return CreateStore(store=store)
Run Code Online (Sandbox Code Playgroud)
突变完美地工作。但是,当我尝试查询商店时,我得到了"Expected a value of type \"StoreOpeningDays\" but received: Monday, Tuesday",真正有意义的错误,因为此字段将数据保存为单个字符串,值以逗号分隔。问题在于,石墨烯期待的graphene.List(Weekdays)是无法检索到的指定列表。
有想法该怎么解决这个吗?提前致谢!
Gal*_*tic -1
你有一行内容如下:
return CreateStore(store=store)
Run Code Online (Sandbox Code Playgroud)
= 两侧的store变量的小写使我相信出站或入站信息都指向其自身。
虽然不熟悉graphene-django...
检查存储变量的范围。如果左侧旨在引用 CreateStore 函数中的参数名称,则尝试重命名右侧以确保它们不冲突。
CreateStore 参数是否需要以特殊字符作为前缀,以便程序知道它直接引用 CreateStore 函数中定义的参数名称?就像 C# 中的 SQL 命令参数一样:
cmd.Parameters.AddWithValue("@myparmname", mylocalval);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
734 次 |
| 最近记录: |