I'm using react native and aws amplify to interface with graphQL. However when making this mutation I receive the error ""Variable 'input' has coerced Null value for NonNull type 'ID!'".
addStudent = async (classData) => {
try {
let user = await Auth.currentAuthenticatedUser();
const emailAttribute = user.attributes.email;
const studentObj = {
name: this.state.studentName,
email: emailAttribute,
class: classData.id,
}
await API.graphql(graphqlOperation(mutations.createStudent, { input: studentObj }));
} catch (err) {
console.error(err);
}
}
Here is my schema:
type Class @model @auth(rules: [{ allow: owner, queries: null}]) {
id: ID!
name: String!
password: String!
email: String!
students: [Student] @connection(name: "ClassStudents")
}
type Student @model @auth(rules: [{ allow: owner, queries: null}]) {
id: ID!
name: String!
email: String!
class: Class! @connection(name: "ClassStudents")
attendance: [Attendance] @connection(name: "StudentAttendance")
}
And here is the mutation I'm trying to call that AWS generated:
export const createStudent = `mutation CreateStudent($input: CreateStudentInput!) {
createStudent(input: $input) {
id
name
email
class {
id
name
password
email
students {
nextToken
}
}
attendance {
items {
id
date
}
nextToken
}
}
}
`;
I have tried solutions from similar questions such as changing the syntax of the mutator argument but the error persists. Any idea of how to solve this?
id
property defined in input object (mutation parameter)studentObj
- xadmid
nullable inCreateStudentInput
- xadm