0

我的 schema.graphql 中有以下设置:

type TrainingInfo @model @auth(rules: [{allow: public}]) {
  id: ID!
  title: String!
  description: String!
  rating: Int
  trainingInfoID: [AssigneeList] @connection(keyName: "byTrainingInfo", fields: ["id"])
  creator: Users @connection
  trainingVideos: [TrainingVideo] @connection(keyName: "byTrainingInfo", fields: ["id"])
  groups: [TrainingInfoGroups] @connection(keyName: "byTrainingInfo", fields: ["id"])
}

type Users @model @auth(rules: [{allow: public}]) @key(name: "byCompany", fields: ["companyID"]) {
  id: ID!
  firstname: String!
  lastname: String!
  email: AWSEmail
  username: String
  confirmed: Boolean
  companyID: ID
  groups: [UsersGroups] @connection(keyName: "byUsers", fields: ["id"])
}

当我在具有正确设置字段的 Amplify DB 中添加新的 TrainingInfo 数据时,我在添加数据时在 iOS 上收到以下错误:

{"onCreateTrainingInfo":{"id":"96902155-b5d8-4765-a8de-f5692e456989","description":"haha","rating":100,"title":"ADADADADADA","creator":null,"__typename":"TrainingInfo","_version":1,"_deleted":null,"_lastChangedAt":1640897426788}},"errors":[{"message":"Cannot return null for non-nullable type: 'String' within parent 'Users' (/onCreateTrainingInfo/creator/firstname)","path":["onCreateTrainingInfo","creator","firstname"]},{"message":"Cannot return null for non-nullable type: 'String' within parent 'Users' (/onCreateTrainingInfo/creator/lastname)","path":["onCreateTrainingInfo","creator","lastname"]},{"message":"Cannot return null for non-nullable type: 'Int' within parent 'Users' (/onCreateTrainingInfo/creator/_version)","path":["onCreateTrainingInfo","creator","_version"]},{"message":"Cannot return null for non-nullable type: 'AWSTimestamp' within parent 'Users' (/onCreateTrainingInfo/creator/_lastChangedAt)","path":["onCreateTrainingInfo","creator","_lastChangedAt"]}]}}

似乎只有“创建者”字段是问题所在,并且它是唯一具有 hasOne 关系的字段。

当我尝试在 Android 上运行相同的代码时,我遇到了类似的错误,其中所有创建者字段都为空,而 id != null。

我尝试再次重命名、删除和添加该字段,但我不断收到相同的错误。

我将 0.2.10 版用于 amplify_flutter 和 amplify_datastore。

4

1 回答 1

0

看来您的架构非常不清楚和错误。我会给你我的连接示例,展示如何在集合之间创建连接。

type User @model
{
  id: ID!
  username: String!
  name: String!
  surname: String!
  email: String
  departments: [UserDepartment] @connection(keyName: "departmentsByUser", fields: ["id"])
}

type Department @model {
  id: ID!
  name: String!
}

type UserDepartment @model 
@key(name: "departmentsByUser", fields: ["userID"])
{
  id: ID!
  userID: ID!
  departmentID: ID!
  user: User @connection(fields: ["userID"])
  department: Department @connection(fields: ["departmentID"])
}
于 2022-01-13T08:44:37.573 回答