0

现在,我正在使用 React + Amplify 构建一个社交媒体网站。而文章特征是它的主要特征之一。但现在,我面临一个难题。

我正在尝试从我的 API 中获取这种 JSON 对象。

{
  "Article": {
    "id": "some ID",
    "title": "some String",
    "content": "some Content",
    "comments": [
      "0": {
        "comment": {
          "id": "some ID",
          "content": "some Content",
          "owner": {
            "id": "some ID",
            "name": "name",
            "avatar": "avatar"
          },
          "replys": [
            "0": {
              "reply": {
                "id": "some ID",
                "content": "some Content",
                "owner": {
                  "id": "some ID",
                  "name": "name",
                  "avatar": "avatar"
                }
              }
            ]
          }
        }
      }
    ]
  }
}

为此,我在我的后端(Amplify API)上创建了这样的模式。

    type Article
      @model
      @key( name: "articleByOwner" fields: ["ownerID", "createdAt"] queryField: "articleByOwner")
      @key( name: "articleByStatus" fields: ["status", "createdAt"] queryField: "articleByStatus") {
      id: ID!
      title: String!
      content: String!
      comments: [Comment] @connection(keyName: "commentByArticle", fields: ["id"])
      createdAt: AWSDateTime!
    }
    
    type Comment
      @model
      @key(name: "commentByArticle" fields: ["articleID", "createdAt"] queryField: "commentByArticle") 
    {
      id: ID!
      content: String!
      ownerID: ID!
      owner: Userinfo @connection(fields: ["ownerID"])
      articleID: ID!
      replys: [Reply] @connection(keyName: "replyByComment", fields: ["id"])
      createdAt: AWSDateTime!
    }
    
    type Reply
      @model
      @key(name: "replyByComment" fields: ["commentID", "createdAt"] queryField: "replyByComment" ) 
    {
      id: ID!
      content: String!
      ownerID: ID!
      owner: Userinfo @connection(fields: ["ownerID"])
      commentID: ID!
      createdAt: AWSDateTime!
    }

type Userinfo @model {
  id: ID!
  name: String
  avatar: String
  createdAt: AWSDateTime!
}

但现在,我只能得到评论。

我希望在所有者和回复之前完成此操作。

目前的状态是这样的。执行 getArticle 查询后。当我使用“amplify push”命令将我的项目推送到云端时,会生成此查询。

{
  "Article": {
    "id": "some ID",
    "title": "some String",
    "content": "some Content",
    "comments": [
      "0": {
        "comment": {
          "id": "some ID",
          "content": "some Content",
          "owner": { nextToken: null },
          "replys": { nextToken : null }
        }
      }
    ]
  }
}

有什么解决办法吗?

4

0 回答 0