【问题标题】:Can an array of data be assigned single value in GraphQL Schema?可以在 GraphQL Schema 中为数据数组分配单个值吗?
【发布时间】:2019-07-01 01:25:22
【问题描述】:

在 GraphQL 中为数据模型分配类型时,有没有办法可以将一组已定义类型分配给更大的类型?抱歉,我真的不知道最好的方式来表达这个问题。下面的例子。

type Creature {
  id: ID! @unique
  creature_name: String!
  creature_type: String!
  creature_size: String!
  description: String!
  creature_stats: [Health: Int!, Stamina: Int!, Endurance: Int!...]
}

我想调用 animal_stats 并一次性取回所有统计数据。

【问题讨论】:

    标签: graphql


    【解决方案1】:

    实际上,我认为您正在寻找的是与另一个数据模型的关系。你可以这样做:

    type Creature {
      id: ID! @unique
      creature_name: String!
      creature_type: String!
      creature_size: String!
      description: String!
      creature_stats: CreatureStats!
    }
    
    type CreatureStats {
      id: ID! @unique
      Health: Int!
      Stamina: Int!
      Endurance: Int!
      ...
    }
    

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-11
      • 2020-05-22
      • 1970-01-01
      • 2016-06-29
      • 2018-10-20
      • 2014-12-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多