简体   繁体   English

GraphQL AWS Amplify @connection 没有引入连接的数据

[英]GraphQL AWS AMplify @connection not bringing in connected data

I would like to have in the League tables all of the seasons and divisions as you can see with data > seasons .我希望在联赛表中包含所有赛季和分区,正如您在data > seasons看到的那样。 I have set it up as I believe would work using @connection.我已经设置了它,因为我相信可以使用@connection。

So the question is, how would I have to change my division schema so that divisions are included in the League .所以问题是,我将如何更改我的分区架构,以便将分区包含在League

I have spent a good time reading over @connections &@key and understand that when using the key a hash is created with the ID that I have given them.我花了很多时间阅读@connections &@key并了解使用密钥时,会使用我提供的ID创建哈希。 But I do not understand enough having read the connections documentation multiple times as to why this wouldn't work.但是我对多次阅读连接文档的理解不够了解为什么这不起作用。

I would love to understand this better, so i am giving all I can to try to develop an understanding!我很想更好地理解这一点,所以我尽我所能尝试发展一种理解!

nb I believe it is worth mentioning also, that each time I change my schema and the amplify mock rebuilds the hash keys, they get added. nb 我相信还值得一提的是,每次我更改架构并且amplify mock重建哈希键时,它们都会被添加。 I wonder if this has some impact?我想知道这是否有一些影响? Should I be cleaning the SQLite completely with each schema change when keys are involved?当涉及到键时,我应该在每次模式更改时完全清理 SQLite 吗? 在此处输入图片说明

League Schema联赛架构

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"])
}

Seasons Schama四季沙玛

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"])
}

Division Schema分区模式

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!
}

Queries查询

  listLeagues {
    items {
      name
      division {
        items {
          name
        }
      }
      seasons {
        items {
          name
          division {
            items {
              name
            }
          }
        }
      }
    }
  }

Data数据

I have shown here that the structure is correct as the Seasons included in the League have the Divisions as expected我这里显示的结构是正确的,因为在Seasons包括在LeagueDivisions如预期

{
  "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": []
                }
              },
            ]
          }
        }
      ]
    }
  }
}

Edit编辑

Since reducing just the keys on division to seasonID and leagueID on each key, when clearing the data it appears to throw an unusual error.由于仅将分区上的键减少到每个键上的seasonIDleagueID ,因此在清除数据时似乎会引发异常错误。 I had believed that return null on a @connection was perfectly valid?我曾相信 @connection 上的 return null 是完全有效的?

在此处输入图片说明

Maybe this should be more a comment than an actual answer, but I need to describe the schema, I will delete it later if you consider it appropriate.也许这更像是评论而不是实际答案,但我需要描述架构,如果您认为合适,我稍后会删除它。

Jamie, just for testing, can you please try the following schema?杰米,只是为了测试,你能试试下面的模式吗? It is basically the same schema proposed by Nader, just removing the field name from the key s on Division :它基本上与 Nader 提出的模式相同,只是从Division上的key s 中删除字段name

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!
}

I think the error you obtained, ie:我认为您获得的错误,即:

"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" } ] }

can be motivated by running a query using the condition name .可以通过使用条件name运行查询来激发。

Because you are setting two different types of query patterns on the division (one from the League using the league ID and one from the Season using the season ID), you should create two indexes.因为您在分区上设置两种不同类型的查询模式(一种使用联赛 ID 来自联赛,一种使用季节 ID 来自赛季),所以您应该创建两个索引。 Try something like this:尝试这样的事情:

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", "name"])
  @key(name: "byDivision", fields: ["leagueID", "seasonID", "name"]) {
  id: ID!
  name: String!
  faId: ID!
  leagueID: ID!
  seasonID: ID!
  league: League! @connection(fields: ["leagueID"])
  season: Season! @connection(fields: ["seasonID"])
  ageInput: String!
  level: Int!
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM