Я пытаюсь создать функцию входа в систему с GraphQL и узлом.Я получил регистрацию на работу, но при запросе функции входа в систему он говорит, что пароль не определен.
AuthType
const AuthType = new GraphQLObjectType({
name: 'Auth',
fields: () => ({
userId: {type: GraphQLString},
username: {type: GraphQLString},
email: {type: GraphQLString},
})
});
Это содержит данные, которые я ожидаю обратно.
const RootQuery = new GraphQLObectType({
login: {
type: AuthType,
args: {
password: {
type: GraphQLString
},
email: {
type: GraphQLString
}
},
resolve(parent, args) {
return User.findOne({
email: args.email
})
.then(user => {
const isEqual = new Promise(bcrypt.compare(password, args.password));
if (!isEqual) {
throw new Error('Password is incorrect!');
}
}).then(result => {
return {
userId: result.id,
username: result.username
};
}).catch(err => {
throw err
});
}
}
});
Это логика для проверки данных, спасибо.
schema.js
const graphql = require('graphql');
const bcrypt = require('bcryptjs');
const jwt = require('jsonwebtoken');
const {GraphQLObjectType,
GraphQLInt,
GraphQLString,
GraphQLSchema,
GraphQLID,
GraphQLList,
GraphQLNonNull } = graphql;
const User = require('../models/user');
const Event = require('../models/event');
Тип User определяет, какие данные от пользователя мы хотели бы сохранить.
const UserType = new GraphQLObjectType({
name: 'User',
fields: () => ({
id: {type: GraphQLID},
firstname: {type: GraphQLString},
lastname: {type: GraphQLString},
username: {type: GraphQLString},
email: {type: GraphQLString},
password: {type: GraphQLString},
location: {type: GraphQLString},
about: {type: GraphQLString},
gender: {type: GraphQLString},
yob: {type: GraphQLString}, //Year of Birth;
events: {
type: new GraphQLList(EventType),
resolve(parent, args){
// return _.filter(events, {userId: parent.id});
return Event.find({creator: parent.id});
}
}
})
});
Функция входа в систему по-прежнему не распознает ввод пароля.