Graphql始终返回null

时间:2019-10-20 20:17:43

标签: node.js mongoose graphql

我正在尝试使用graphql和mongoose从mongodb集合中获取数据,但是graphql始终解析为null。这是我正在尝试的查询:

getUser(电子邮件:“ john@gmail.com”){        名称 }

const userModel = new Mongoose.model("db.users", {
    _id: String,
    email: String,
    name: String
});

const userType = new GraphQLObjectType({
    name: "user",
    fields : {
        _id: {type: GraphQLID},
        email: {type: GraphQLString},
        name: {type: GraphQLString}

    }
});


// Construct a schema
const schema = new GraphQLSchema({

    query: new GraphQLObjectType({
        name:"query",
        fields: {
            getUser: {
                type: userType,
                args: {
                    email: {
                        type: GraphQLString,
                    }
                },
                resolve: async(root, args, context, info) => {
                    return await(userModel.findOne(args).exec());

                }               
            }
        }
    })
});


0 个答案:

没有答案