mirror of
https://github.com/strapi/strapi.git
synced 2025-09-22 14:59:07 +00:00
Correctly detect an enum field
This commit is contained in:
parent
aedf09bdcb
commit
25eab80f64
@ -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) => ({
|
||||
|
Loading…
x
Reference in New Issue
Block a user