0

I'm trying to query cassandra with id but I get this error

apollo.model.validator.invalidvalue: Invalid Value: "{ id: [Uuid] }" for Field: id (Type: uuid)

In my code I have :

const reqId = models.uuidFromString(req.params.id); 
    const queryObj = { id: reqId };  
    this.findById(queryObj, function(err, user)

My model:

id: {
   type: "uuid",
   rule: {required: true},
   default: {$db_function: "uuid()"}
}
Masum
  • 1,678
  • 15
  • 19
sotewa
  • 1
  • 1
  • It's difficult to say without knowing the method definition of "findById". Just guessing, you might need to put the reqId directly into findById instead of making a queryObj. – Masum Apr 30 '20 at 13:23
  • This is my findById method: exports.findById = (id) => { return new Promise(resolve => { models.instance.Person.findAsync({id: id}) .then(function(user) { resolve(user.length > 0 ? user[0] : null); }) .catch(function(err) { console.log(err); throw err; }); }); } – sotewa Apr 30 '20 at 17:17
  • The problem is that it seems that express-cassandra doesn't recognise the uuid returned from models.uuidFromString(str) method as a valid type which is quite strange to me. This is visible from the error message. – sotewa Apr 30 '20 at 17:20
  • Nope. From your code and the error message, it is obvious that you are building a query object twice. Hence instead of getting a UUID typed value, express-cassandra is getting an object {id: [UUID]}. Just pass the reqId directly to your findById method like this: `this.findById(reqId, function(err, user)` instead of passing a query object again. – Masum May 01 '20 at 12:03
  • Thank you alot. Now I see the problem. – sotewa May 01 '20 at 21:35

0 Answers0