我有一个案例类Inventory
:
case class Inventory(
organizationId: UUID,
inventoryId: UUID,
name: String,
schema: String
)
输入类型:
private val NewInventoryInputType =
deriveInputObjectType[Inventory](
InputObjectTypeName("NewInventory"),
ExcludeInputFields("organizationId", "inventoryId")
)
一个论点:
val NewInventory = Argument("inventory", NewInventoryInputType)
最后是一个字段:
val MutationType = ObjectType("Mutation", fields[GraphQLContext, Unit](
Field("createInventory", OptionType(UuidType),
Some("Creates a new inventory."),
NewInventory :: Nil,
resolve = c => {
val inventoryId = UUID.randomUUID
val inventory = c arg NewInventory
println(s"Inventory($inventory)")
inventoryId
}
)
))
我想做的是能够Inventory
用这样的查询创建一个:
{
"query": "mutation ($inventory: NewInventory!) { createInventory(inventory: $inventory) }",
"variables": {
"inventory": {
"name":"i1",
"schema":"s"
}
}
}
缺少的部分是在Sangria 尝试使用它拥有的变量实例化域对象之前organizationId
和之前创建 UUID 的位置。inventoryId
Inventory
目前,我收到此错误:
Argument 'inventory' has invalid value: At path '/inventoryId': error.path.missing (line 1, column 67):
mutation ($inventory: NewInventory!) { createInventory(inventory: $inventory) }
^
(当然,我可以只创建一个NewInventory
没有 ID 字段的案例类并Inventory
手动实例化一个,但我想避免为每个实体类型创建和维护两个类。)