首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在GraphQL变异中为字段分配类型

在GraphQL变异中为字段分配类型
EN

Stack Overflow用户
提问于 2019-02-09 05:39:50
回答 1查看 37关注 0票数 0

在下面的例子中,我试图在我的数据库中创建一个生物,每个生物都有许多属性,所以我创建了一个具有许多不同的字符串和CreatureAttribute字段的Int。如何将该类型附加到生物类型变异?

代码语言:javascript
运行
复制
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

  }
}

提前感谢您的回答:)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-02-11 22:26:41

根据我的理解,你想创建一个“生物有可能的属性”的关系。所以属性应该接受数组,如下面的示例所示。

代码语言:javascript
运行
复制
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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54600611

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档