0

I have the following setup in my 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"])
}

When I add a new TrainingInfo data in the Amplify DB with properly set fields I get the following error on iOS when adding the data:

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

It seems like only 'creator' field is the problem and it is the only one with hasOne relationship.

When I tried running the same code on Android I got similar error where all creator fields are null while id != null.

I've tried renaming, deleting and adding the field again but I keep getting the same error.

I am using the version 0.2.10 for amplify_flutter and amplify_datastore.

PetarA
  • 51
  • 1
  • 3

1 Answers1

0

It seems that your schema is pretty much unclear and wrong. I will give you my connection example that shows how you can create connection between collections.

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"])
}
Dharman
  • 30,962
  • 25
  • 85
  • 135
mkaya387
  • 368
  • 2
  • 10
  • Hi @mkaya387, I just updated the question. I missed add the first line of the schema by an accident. – PetarA Jan 13 '22 at 19:28
  • Basically one instance of TrainingInfo object is supposed to have 1 instance of Users object. – PetarA Jan 13 '22 at 19:37