我想在data > seasons中看到所有赛季和分区的联赛表。我已经设置好它,因为我相信它可以使用@connection进行工作。
所以问题是,我将如何更改我的除法模式,以便将除法包含在League中。
我花了很多时间阅读@connections@key,并了解使用键时,会使用我给他们的ID创建哈希。但是,我多次阅读连接文档以了解为什么它不起作用,对此我还是不太了解。
我想更好地理解这一点,因此,我将竭尽所能去加深理解!
n.b我相信也值得一提,每次更改架构并amplify mock重建哈希键时,它们都会被添加。我想知道这是否会产生影响吗?涉及键时,是否应该在每次模式更改时彻底清理SQLite?
javascript - GraphQL AWS AMplify @connection没有引入连接的数据-LMLPHP
联赛架构

type League @model
{
  id: ID!
  name: String!
  faId: ID!
  logo: String
  seasons: [Season] @connection(keyName: "bySeason", fields: ["id"])
  division: [Division] @connection(keyName: "byDivision", fields: ["id"])
}
四季沙玛
type Season @model @key(name: "bySeason", fields: ["leagueID"])
{
  id: ID!
  name: String!
  faId: ID!
  yearStart: AWSDate
  yearEnd: AWSDate
  leagueID: ID!
  league: League! @connection(fields: ["leagueID"])
  division: [Division] @connection(keyName: "byDivision", fields: ["id"])
}
分区方案
type Division @model
@key(name: "byDivisionFromSeason", fields: ["leagueID" "name"])
@key(name: "byDivision", fields: ["seasonID", "leagueID"])
{
  id: ID!
  name: String!
  faId: ID!
  divisionSeasonFaId: String
  leagueID: ID!
  seasonID: ID!
  league: League! @connection(fields: ["leagueID"])
  season: Season! @connection(fields: ["seasonID"])
  teams: [TeamConnection] @connection(keyName: "byTeamDivision", fields: ["id"])
  games: [Game] @connection(keyName: "byGameForDivision", fields: ["id"])
  ageInput: String!
  level: Int!
}
查询
  listLeagues {
    items {
      name
      division {
        items {
          name
        }
      }
      seasons {
        items {
          name
          division {
            items {
              name
            }
          }
        }
      }
    }
  }
数据
我在这里已显示结构正确,因为Seasons中包含的League具有预期的Divisions
{
  "data": {
    "listLeagues": {
      "items": [
        {
          "name": "Southern Amateur League",
          "division": {
            "items": []
          },
          "seasons": {
            "items": [
              {
                "name": "2020-21",
                "division": {
                  "items": [
                    {
                      "name": "Junior Section Division 5B South"
                    },
                    {
                      "name": "Junior Section Division 4 South"
                    },
                    {
                      "name": "Intermediate Division 3"
                    },
                  ]
                }
              },
              {
                "name": "2019-20",
                "division": {
                  "items": []
                }
              },
            ]
          }
        }
      ]
    }
  }
}
编辑
由于仅将分区上的键减少为每个键上的seasonIDleagueID,因此清除数据时似乎会引发异常错误。我曾经相信@connection上的return null是完全有效的吗?
javascript - GraphQL AWS AMplify @connection没有引入连接的数据-LMLPHP

最佳答案

也许这应该是注释而不是实际答案,但是我需要描述该架构,如果您认为合适的话,我会在以后删除它。
杰米(Jamie),仅用于测试,您可以尝试以下方案吗?基本上与Nader提出的模式相同,只是从name上的key中删除字段Division:

type League @model
{
  id: ID!
  name: String!
  faId: ID!
  logo: String
  seasons: [Season] @connection(keyName: "bySeason", fields: ["id"])
  division: [Division] @connection(keyName: "byDivision", fields: ["id"])
}

type Season @model @key(name: "bySeason", fields: ["leagueID"])
{
  id: ID!
  name: String!
  faId: ID!
  yearStart: AWSDate
  yearEnd: AWSDate
  leagueID: ID!
  league: League! @connection(fields: ["leagueID"])
  division: [Division] @connection(keyName: "byDivisionFromSeason", fields: ["id"])
}

type Division @model
@key(name: "byDivisionFromSeason", fields: ["seasonID", "leagueID"])
@key(name: "byDivision", fields: ["leagueID", "seasonID"])
{
  id: ID!
  name: String!
  faId: ID!
  divisionSeasonFaId: String
  leagueID: ID!
  seasonID: ID!
  league: League! @connection(fields: ["leagueID"])
  season: Season! @connection(fields: ["seasonID"])
  teams: [TeamConnection] @connection(keyName: "byTeamDivision", fields: ["id"])
  games: [Game] @connection(keyName: "byGameForDivision", fields: ["id"])
  ageInput: String!
  level: Int!
}
我认为您收到的错误是:
"errors": [ { "message": "Query condition missed key schema element", "errorType": "DynamoDB:ValidationException", "data": null, "errorInfo": null, "path": [ "listLeagues", "items", 1, "division" ], "locations": [ { "line": 10, "column": 9, "sourceName": "GraphQL request" } ] }
可以通过使用条件name运行查询来激发。

10-07 14:52