на стороне клиента (реагировать / apollo) не получает запросы на нумерацию страниц, возвращает ошибки:
"message": "Невозможно запросить поле \" курсор \ "
" message ":" Неизвестный аргумент \ "last \"
"message": "Невозможно запросить поле \" pageInfo \ "
" message ":" Неизвестный аргумент \ "page \" on
Вот как я сделал свою модель, запросы и схемы мутаций на стороне сервера (узел / экспресс / mongoogse):
Модель:
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const userSchema = new Schema({
identification: { type: String, trim: true, required: true, unique: true },
name: { type: String, trim: true, required: true },
lastName: { type: String, trim: true, required: true },
status: { type: String, trim: true, required: true },
username: { type: String, trim: true, required: true, unique: true },
password: { type: String, required: true },
roleid: { type: String, trim: true, required: true },
description: { type: String, trim: true },
email: { type: String, trim: true, unique: true }
});
module.exports = mongoose.model("User", userSchema);
Shema:
const UserType = new GraphQLObjectType({
name: "User",
fields: () => ({
id: { type: GraphQLID },
identification: { type: GraphQLID },
name: { type: GraphQLString },
lastName: { type: GraphQLString },
status: { type: GraphQLString },
username: { type: GraphQLString },
password: { type: GraphQLString },
description: { type: GraphQLString },
email: { type: GraphQLString },
roleid: { type: GraphQLID },
role: {
type: RoleType,
resolve(parent, args) {
return Role.findById(parent.roleid);
},
},
}),
});
const RootQuery = new GraphQLObjectType({
name: "RootQueryType",
fields: {
users: {
type: new GraphQLList(UserType),
resolve(parent, args) {
return User.find();
},
},
user: {
type: UserType,
args: { id: { type: GraphQLID } },
resolve(parent, args) {
return User.findById(args.id);
},
},
},
});
const Mutation = new GraphQLObjectType({
name: "Mutation",
fields: {
addUser: {
type: UserType,
args: {
identification: { type: GraphQLString },
name: { type: GraphQLString },
lastName: { type: GraphQLString },
status: { type: GraphQLString },
username: { type: GraphQLString },
password: { type: GraphQLString },
description: { type: GraphQLString },
email: { type: GraphQLString },
roleid: { type: GraphQLID },
},
resolve(parent, args) {
return bcrypt
.hash(args.password, 12)
.then((hashedPassword) => {
let user = new User({
identification: args.identification,
name: args.name,
lastName: args.lastName,
status: args.status,
username: args.username,
password: hashedPassword,
description: args.description,
email: args.email,
roleid: args.roleid,
});
return user.save();
})
.then((result) => {
return { ...result._doc, password: null, id: result.id };
})
.catch((err) => {
throw err;
});
},
},
updateUser: {
type: UserType,
args: {
id: { type: GraphQLID },
identification: { type: GraphQLString },
name: { type: GraphQLString },
lastName: { type: GraphQLString },
status: { type: GraphQLString },
username: { type: GraphQLString },
password: { type: GraphQLString },
description: { type: GraphQLString },
email: { type: GraphQLString },
roleid: { type: GraphQLID },
},
resolve(parent, args) {
return bcrypt
.hash(args.password, 12)
.then((hashedPassword) => {
let user = User.findByIdAndUpdate(
args.id,
{
identification: args.identification,
name: args.name,
lastName: args.lastName,
status: args.status,
username: args.username,
password: hashedPassword,
description: args.description,
email: args.email,
roleid: args.roleidupduu,
},
{ new: true }
);
return user;
})
.then((result) => {
return { ...result._doc, password: null, id: result.id };
})
.catch((err) => {
throw err;
});
},
},
deleteUser: {
type: UserType,
args: { id: { type: GraphQLID } },
resolve(parent, args) {
return User.findByIdAndDelete(args.id);
},
},
},
});