【以下的问题经过翻译处理】 具体的错误如下所示:
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"message": "1 validation error detected: Value '[object Object]' at 'tableName' failed to satisfy constraint: Member must satisfy regular expression pattern: [a-zA-Z0-9_.-]+",
"code": "ValidationException",
"time": "2019-07-25T05:43:18.119Z",
"requestId": "xxx",
"statusCode": 400,
"retryable": false,
"retryDelay": 42.11544763698385,
"stacktrace": [ ...
我猜问题可能是表的名称,但是表名已经命名正确。下面是实现的代码:
const putItem = (tableName, newItem) =>
new Promise((resolve, reject) => {
const params = {
TableName: tableName,
Item: newItem,
};
docClient.put(params, (err, data) => {
if (err) {
return reject(err);
}
return resolve(newItem);
});
});
由于我在使用GraphQL,下面是resolver:
const resolvers = {
Mutation: {
createUser: (root, { params }) => {
const tableName = 'Users';
return bcrypt
.hash(params.password, 12)
.then(hashedPassword => {
const newUser = {
_id: uuidv5(params.email, nameSpaces.usersTable),
email: params.email,
password: hashedPassword,
};
return dynamoConnection.putItem(newUser, tableName);
})
.then(result => ({ ...result, password: null }))
.catch(err => {
throw err;
});
},
},
};
为了调试这个错误,我应该怎么做?