无法设置未定义的 属性 'clientMutationId'”错误
Cannot set property 'clientMutationId' of undefined" Error
outputFields: {
token: {
type: GraphQLString,
resolve: (token) => token
}
},
outputfields 永远不会被调用,不确定我是否以正确的方式做事,在从 mutateAndGetPayload 方法返回数据时不会调用 resolve 函数。
mutateAndGetPayload: (credentials) => {
console.log('credentials', credentials);
userprof.findOne({email: credentials.email}).exec(function(err, r) {
if(!r) {
return new Error('no user')
} else if(r) {
if(r.password != credentials.password) {
return new Error('password error');
} else {
var token = jwt.getToken(r);
console.log(token);
return {token};
}
}
});
}
我认为您需要 return mutateAndGetPayload 方法中的某些内容。那可能是一个承诺。尝试 return userprof.findOne.
解决方案
token: {
type: GraphQLString,
resolve: ({token}) => token
}
},
mutateAndGetPayload: (credentials) => {
return UserProf.findOne({ email: credentials.email }).then((r) => {
if (!r) {
return new Error('no user');
} else if (r) {
if (r.password != credentials.password) {
return new Error('password error');
} else {
return { token: jwt.getToken(r) };
}
}
});
}
outputFields: {
token: {
type: GraphQLString,
resolve: (token) => token
}
},
outputfields 永远不会被调用,不确定我是否以正确的方式做事,在从 mutateAndGetPayload 方法返回数据时不会调用 resolve 函数。
mutateAndGetPayload: (credentials) => {
console.log('credentials', credentials);
userprof.findOne({email: credentials.email}).exec(function(err, r) {
if(!r) {
return new Error('no user')
} else if(r) {
if(r.password != credentials.password) {
return new Error('password error');
} else {
var token = jwt.getToken(r);
console.log(token);
return {token};
}
}
});
}
我认为您需要 return mutateAndGetPayload 方法中的某些内容。那可能是一个承诺。尝试 return userprof.findOne.
解决方案
token: {
type: GraphQLString,
resolve: ({token}) => token
}
},
mutateAndGetPayload: (credentials) => {
return UserProf.findOne({ email: credentials.email }).then((r) => {
if (!r) {
return new Error('no user');
} else if (r) {
if (r.password != credentials.password) {
return new Error('password error');
} else {
return { token: jwt.getToken(r) };
}
}
});
}