简体   繁体   中英

Assigning a Type to a field in GraphQL Mutation

In the example below I am trying to create a Creature in my database each creature has many attributes so I created an CreatureAttribute Type with many different required String and Int fields. How do I attach that Type to the Creature Type Mutation?

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

  }
}

Thank you for your answers in advance :)

As per my understanding you want to create a relation "Creature has may attributes". So attribute should accept array as shown in following sample.

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! 
...}

Ref - https://graphql.org/learn/schema/#object-types-and-fields

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM