Trying to execute a graphql mutation, where the mutation should take custom type. In the App Sync schema, I have defined these custom Types:
Schema:
input CreateConversationInput {
user: UserInput
doctor: DoctorInput
questionsAndAnsers: [ConversationQAInput]
pet: UpdatePetInput
}
React Native Code:
const createConversationInput = {
user: {
username: "deep",
userType: "Patient",
fullName: "Deep A"
},
doctor: {
name: "Raman",
speciality: "dog",
doctorId: "0bd9855e-a3f2-4616-8132-aed490973bf7"
},
questionsAndAnswers: [{ question: "Question 1", answer: "Answer 1" }, { question: "Question 2", answer: "Answer 2" }],
pet: { username: "deep39303903", petId: "238280340932", category: "Canine" }
}
API.graphql(graphqlOperation(CreateConversation, createConversationInput)).then(response => {
console.log(response);
}).catch(err => {
console.log(err);
});
I have define mutation like this:
export const CreateConversation = `mutation CreateConversation( $user: Object,
$doctor: Object, $questionsAndAnswers: Object, $pet: Object ) {
createConversation(
input : {
user: $user
doctor: $doctor
questionsAndAnswers: $questionsAndAnswers
pet: $pet
}
){
username
createdAt
}
}`;
The mutation is working properly from the AWS GraphQL console. However, in the react native app, I get error.
Error:
"Validation error of type UnknownType: Unknown type Object".
I believe the error is because I defined the type as Object in mutations instead of the actual type defined in the AWS Schema. How can I define custom types in the React Native code if this is the issue?