【问题标题】:How can I add a field to relational table in amplify graphql?如何在 amplify graphql 中向关系表中添加字段?
【发布时间】:2022-05-02 05:08:30
【问题描述】:

我使用 Amplify/graphQl transformer V2,我尝试做同样的事情,比如 Amplify 的官方文档:https://docs.amplify.aws/cli/graphql/data-modeling/#many-to-many-relationship

所以在@manyToMany 关系部分,我知道关系表是自动生成的,并且在放大工作室中我找到了该表的所有查询和突变...。

我的问题是如何在这个表(关系表)中添加一些字段。

N.B:我使用的是相同的文档示例:https://docs.amplify.aws/cli/graphql/data-modeling/#many-to-many-relationship 那么如何在PostTags 表中添加例如字段 City

type Post @model {
id: ID!
title: String!
content: String
tags: [Tag] @manyToMany(relationName: "PostTags")
}



type Tag @model {
id: ID!
label: String!
posts: [Post] @manyToMany(relationName: "PostTags")
}

【问题讨论】:

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


    【解决方案1】:

    试试下面这个,我认为它满足你的需要。

    type Post @model {
      id: ID!
      title: String!
      content: String
      tags: [Tag] @hasMany
    }
    
    type Tag @model {
      id: ID!
      label: String!
      posts: [Post] @hasMany
    }
    
    type PostTags @model {
      id: ID!
      city: String!
      post_id: ID!
      tag_id: ID!
      post: Club! @belongsTo(fields: ["post_id"])
      tag: Championship! @belongsTo(fields: ["tag_id"])
    }
    

    【讨论】:

    • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 2021-04-02
    • 2020-01-05
    • 2021-06-13
    • 2015-01-19
    • 1970-01-01
    • 2019-05-08
    • 2017-02-19
    • 1970-01-01
    • 2018-10-04
    相关资源
    最近更新 更多