最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

密码不Graphql和节点定义

IT培训 admin 3浏览 0评论

密码不Graphql和节点定义

我试图创建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(bcryptpare(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');

用户类型定义我们想保存什么来自用户的数据。

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});
            }
        }


    })
});

登录功能仍然不能识别输入的口令。

回答如下:

你是不是在你的AuthType定义密码字段,我想你应该这样做:

const AuthType = new GraphQLObjectType({
    name: 'Auth',
    fields: () => ({
        userId: {type: GraphQLString},
        username: {type: GraphQLString},
        email: {type: GraphQLString},
        password: {type: GraphQLString},
    })
});

此外,你必须在这一行一个拼写错误:

const RootQuery = new GraphQLObectType({

应该GraphQLObjectType代替GraphQLObectType

此外,在这一行:

const isEqual = new Promise(bcryptpare(password, args.password));

也许你得到的错误,因为password没有在代码中定义。你可能想要做user.password

密码不Graphql和节点定义

我试图创建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(bcryptpare(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');

用户类型定义我们想保存什么来自用户的数据。

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});
            }
        }


    })
});

登录功能仍然不能识别输入的口令。

回答如下:

你是不是在你的AuthType定义密码字段,我想你应该这样做:

const AuthType = new GraphQLObjectType({
    name: 'Auth',
    fields: () => ({
        userId: {type: GraphQLString},
        username: {type: GraphQLString},
        email: {type: GraphQLString},
        password: {type: GraphQLString},
    })
});

此外,你必须在这一行一个拼写错误:

const RootQuery = new GraphQLObectType({

应该GraphQLObjectType代替GraphQLObectType

此外,在这一行:

const isEqual = new Promise(bcryptpare(password, args.password));

也许你得到的错误,因为password没有在代码中定义。你可能想要做user.password

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论