Ответ 1
Вы определяете тип поля как UserType. Несмотря на то, что это мутация, она по-прежнему следует тем же правилам и поведению, что и запрос. Поскольку UserType является типом объекта, для него требуются вложенные поля.
mutation _ {
updateCurrentUser(fullName: "Syava", email: "[email protected]") {
fullName
email
}
}
// would respond with { fullName: 'Syava', email: '[email protected]' }
Если вы не хотите, чтобы мутация возвращала пользователя, вы можете объявить его тип GraphQLBoolean, например, - скаляр и не имеет вложенных полей.
{
type: GraphQLBoolean,
args: {
fullName: { type: GraphQLString },
email: { type: new GraphQLNonNull(emailType) },
password: { type: GraphQLString },
},
resolve: async (root, { fullName, email, password }, { rootValue }) => {
const user = await User.findById(rootValue.req.user.id);
user.fullName = fullName;
user.password = password; // or hashed to not store plain text passwords
return user.save(); // assuming save returns boolean; depends on the library you use
}
}