Correctly detect an enum field

This commit is contained in:
Kamal Bennani 2018-06-26 18:23:18 +02:00
parent aedf09bdcb
commit 25eab80f64
No known key found for this signature in database
GPG Key ID: 4513063CDB1A1C25

View File

@ -29,15 +29,18 @@ module.exports = {
type === 'Float' ||
type === 'String' ||
type === 'Boolean' ||
type === 'DateTime'
type === 'DateTime' ||
type === 'JSON'
);
},
/**
* Checks if the field is of type enum
*
* @returns {Boolean}
*/
isEnumType: (_type) => {
return _.startsWith(_type, 'ENUM_');
isEnumType: (type) => {
return type === 'enumeration';
},
/**
@ -66,18 +69,24 @@ module.exports = {
/**
* Convert non-primitive type to string (non-primitive types corresponds to a reference to an other model)
*
* @returns {String}
*
* @example
*
* extractType(String!)
* // => String
*
* extractType(user)
* // => ID
*
* @returns {String}
* extractType(ENUM_TEST_FIELD, enumeration)
* // => String
*
*/
extractType: function (_type) {
extractType: function (_type, attributeType) {
return this.isPrimitiveType(_type)
? _type.replace('!', '')
: this.isEnumType(_type)
: this.isEnumType(attributeType)
? 'String'
: 'ID';
},
@ -336,12 +345,11 @@ module.exports = {
* @return {String}
*/
generateConnectionFieldsTypes: function (fields, model) {
const { globalId } = model;
const { globalId, attributes } = model;
const primitiveFields = this.getFieldsByTypes(
fields,
this.isNotOfTypeArray,
type => this.extractType(type),
(type, name) => this.extractType(type, (attributes[name] || {}).type),
);
const connectionFields = _.mapValues(primitiveFields, (fieldType) => ({