【发布时间】:2017-06-09 19:02:39
【问题描述】:
我正在开发一个符合 Relay 的 GraphQL 架构,并希望包含一个突变,该突变接受一个需要一个参数(记录的 ID)或两个其他参数(记录号和目录号)的输入对象作为记录)。我正在使用 Python 和 Graphene 库。这是当前输入对象的 sn-p,它不允许使用 ID 代替数字/目录:
class CreateRecord(relay.ClientIDMutation):
"The parameters of a newly created record."
# Relay-compliant mutations need to specify an input class.
class Input:
"The available inputs for the CreateRecord mutation."
part_id = graphene.Int(description='The ID of the record.')
part_number = graphene.String(description='The record number.',
required=True)
catalog = graphene.String(description='The catalog of the record.',
required=True)
为了实现这一点,我已经研究了接口和联合,但到目前为止还没有任何运气。如果没有更灵活的输入对象,我可能需要创建另一个突变(如CreateRecordUsingID)。有没有办法实现这一点,或者更普遍地在 GraphQL 模式中支持此功能?
【问题讨论】:
-
我对查询有同样的问题。例如,在查询用户时,应提供 ID 或用户名 - 但不能同时提供两者。我不确定这种类型的验证是否支持开箱即用。这似乎是一种常见的模式。
-
@jfizz 看看我的回答,它也适用于你的情况。
标签: python types schema graphql relay