为 GraphQL Mutation 中的字段分配类型
Assigning a Type to a field in GraphQL Mutation
在下面的示例中,我试图在我的数据库中创建一个生物,每个生物都有许多属性,因此我创建了一个具有许多不同的必需字符串和整数字段的 CreatureAttribute 类型。我如何将该类型附加到生物类型突变?
mutation{
createCreature(data: {
creature_name: "Drake"
creature_type: "Dragon"
creature_size: "Huge"
description: "description Text..."
habitat: "habitat text..."
combat: "combat text..."
additional_info: "additional info text..."
attributes: ********this is where I would like to bring in my CreatureAttributes Type********
)
{
creature_name
creature_type
description
habitat
combat
additional_info
attributes
}
}
提前感谢您的回答:)
根据我的理解,您想创建一个关系 "Creature has may attributes"。所以属性应该接受数组,如下例所示。
type Creature {
id: ID! @unique
creature_name: String!
creature_type: String!
creature_size: String!
description: String!
habitat: String!
combat: String!
additional_info: String!
attributes: [CreatureAttributes]!
}
type CreatureAttributes {
strength: Int!
health: Int!
stamina: Int!
mana: Int!
reaction: Int!
...}
参考 - https://graphql.org/learn/schema/#object-types-and-fields
在下面的示例中,我试图在我的数据库中创建一个生物,每个生物都有许多属性,因此我创建了一个具有许多不同的必需字符串和整数字段的 CreatureAttribute 类型。我如何将该类型附加到生物类型突变?
mutation{
createCreature(data: {
creature_name: "Drake"
creature_type: "Dragon"
creature_size: "Huge"
description: "description Text..."
habitat: "habitat text..."
combat: "combat text..."
additional_info: "additional info text..."
attributes: ********this is where I would like to bring in my CreatureAttributes Type********
)
{
creature_name
creature_type
description
habitat
combat
additional_info
attributes
}
}
提前感谢您的回答:)
根据我的理解,您想创建一个关系 "Creature has may attributes"。所以属性应该接受数组,如下例所示。
type Creature {
id: ID! @unique
creature_name: String!
creature_type: String!
creature_size: String!
description: String!
habitat: String!
combat: String!
additional_info: String!
attributes: [CreatureAttributes]!
}
type CreatureAttributes {
strength: Int!
health: Int!
stamina: Int!
mana: Int!
reaction: Int!
...}
参考 - https://graphql.org/learn/schema/#object-types-and-fields