masumsoft / express-cassandra

Cassandra ORM/ODM/OGM for NodeJS with support for Apache Cassandra, ScyllaDB, Datastax Enterprise, Elassandra & JanusGraph.
http://express-cassandra.readthedocs.io
GNU Lesser General Public License v3.0
227 stars 67 forks source link

Error displays "undefined" on type error #182

Closed AlexisWilke closed 5 years ago

AlexisWilke commented 5 years ago

Sorry about the noise... I create a Pull Request instead. See #183

I'm starting with express-cassandra and I got the following error

(node:13187) UnhandledPromiseRejectionWarning: apollo.model.validator.invalidschema: Invalid field type "undefined" for field: content_id

Looking at the code I see that the type can either be a field or a string;

get_field_type(modelSchema, fieldName) {
  var fieldObject = modelSchema.fields[fieldName];

  if (typeof fieldObject === 'string') {
    return fieldObject;
  }
  if (_.isPlainObject(fieldObject)) {
    return fieldObject.type;
  }
  throw new Error('Field type not defined properly');
},

However, in the code generating the error:

var fieldtype = this.get_field_type(modelSchema, fieldName);
if (!_.has(datatypes, fieldtype)) {
  throw new Error(util.format('Invalid field type "%s" for field: %s', fieldObject.type, fieldName));
}

I suggest changing the fieldObject.type with fieldtype as follow:

  throw new Error(util.format('Invalid field type "%s" for field: %s', fieldtype, fieldName));

Then I can see that it's not happen with 'long' as a field type:

(node:13187) UnhandledPromiseRejectionWarning: apollo.model.validator.invalidschema: Invalid field type "long" for field: content_id

Which is strange, but at least makes a lot more sense.