Following this tutorial, I have a mongoose model: (I\'m using the term \"Account\" instead of \"Todo\", but it\'s the same thing)
const Account = mongoose.m
I didn't find an issue and ran this code with one of my existing code bases. Except I wrapped the mutation in the GraphQLObjectType
.
const Mutation = new GraphQLObjectType({
name: 'Mutation',
fields: {
addAccount: {
type: AccountType,
description: 'Create new account',
args: {
name: {
name: 'Account Name',
type: new GraphQLNonNull(GraphQLString)
}
},
resolve: (root, args) => {
const newAccount = new Account({
name: args.name
});
newAccount.id = newAccount._id;
return new Promise((resolve, reject) => {
newAccount.save(err => {
if (err) reject(err);
else resolve(newAccount);
});
});
}
}
});
To get the working example: Clone the repo. In this repo, the app uses v0.13.2
and you are using v14.0.2
installed via npm i graphql
. Downgrade graphql
to v0.13.2
.