【问题标题】:How to store multiple key values in an Array on one field如何将多个键值存储在一个字段的数组中
【发布时间】:2021-01-29 09:20:31
【问题描述】:

我有一个足球队模型,如图所示

type Team @model
  {
    id: ID!
    name: String!
    faId: ID!
    seasonID: ID!
    seasons: [seasonID] @connection(fields: ["seasonID"])
  }

球队将参加多个赛季。我想将数据存储在一个数组中

seasonID: [ID]!

然后在获取数据时,我可以返回团队参与的所有赛季。

Dynamodb 可以做到这一点吗?当我尝试这样说时,它会说:

InvalidDirectiveError: All fields provided to an @connection must be non-null scalar or enum fields.

【问题讨论】:

    标签: amazon-web-services graphql amazon-dynamodb aws-amplify


    【解决方案1】:

    InvalidDirectiveError: All fields provided to an @connection must be non-null scalar or enum fields. 表示您拥有[seasonID] 的部分不应是IDStringInt 等类型中的任何一个,如图所示和描述的here

    通过创建一个名为Season 的单独模型来实现基数一对多1..* 的连接。例如:

    # Separate model for Season
    type Season @model{
       id: ID!
       name: String!
    }
     
    type Team @model
    {
        id: ID!
        name: String!
        faId: ID!
        seasonID: ID!
        seasons: [Season] @connection(fields: ["seasonID"])
    }
    

    你可以看到更多你可以做的例子here

    【讨论】:

    • 这似乎不起作用。在尝试创建团队时,seasonID 仍然只是一个需要 ID 的字段。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-23
    • 2022-06-18
    • 2019-05-01
    • 1970-01-01
    • 2016-06-21
    • 2015-07-20
    • 1970-01-01
    相关资源
    最近更新 更多