簡體   English   中英

在GraphQL突變中為字段分配類型

[英]Assigning a Type to a field in GraphQL Mutation

在下面的示例中,我嘗試在數據庫中創建一個Creature,每個生物都具有許多屬性,因此我創建了一個CreatureAttribute Type,其中包含許多不同的必需String和Int字段。 如何將該類型附加到生物類型突變?

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

  }
}

預先感謝您的回答:)

根據我的理解,您想創建一個“生物具有屬性”關系。 因此屬性應接受數組,如以下示例所示。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM