I am trying to run a graphql mutation to create a user to dynamoDB. When I run the mutation, I am expecting it to return the newly create User. But even though my data is added to the DB successfully and my resolver is returning the correct type, the data coming back is always null.
My Mutation schema:
input UserInput {
active: Boolean!
email: String!
fullname: String!
description: String!
tags: [String!]!
}
type User {
active: Boolean!
email: String!
fullname: String!
description: String!
tags: [String!]!
}
type Mutation {
createUser(input: UserInput!): User!
}
My resolver:
Mutation: {
createUser: (_, user, { dataSources }) => {
return dataSources.userAPI.createUser(user)
}
}
Lastly, my userAPI is:
class UserAPI extends DataSource {
initialize(config) {
this.context = config.context;
}
createUser(user) {
const params = {
TableName: "Users",
Item: {
active: {BOOL: user.input.active},
email: { S: user.input.email },
fullname: { S: user.input.fullname },
description: { S: user.input.description },
tags: { SS: user.input.tags.map(tag => tag) },
id: {S: uuidv4()}
}
};
return dynamodb.putItem(params, function(err) {
if (err) {
console.log("Error: ", err);
} else {
console.log("Success");
return user.input;
}
});
}
I keep getting an error saying "Cannot return null for non-nullable field ...." Any idea why this is happening?