mirror of
https://github.com/strapi/strapi.git
synced 2025-09-22 23:09:47 +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 === 'Float' ||
|
||||||
type === 'String' ||
|
type === 'String' ||
|
||||||
type === 'Boolean' ||
|
type === 'Boolean' ||
|
||||||
type === 'DateTime'
|
type === 'DateTime' ||
|
||||||
|
type === 'JSON'
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the field is of type enum
|
* Checks if the field is of type enum
|
||||||
|
*
|
||||||
|
* @returns {Boolean}
|
||||||
*/
|
*/
|
||||||
isEnumType: (_type) => {
|
isEnumType: (type) => {
|
||||||
return _.startsWith(_type, 'ENUM_');
|
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)
|
* Convert non-primitive type to string (non-primitive types corresponds to a reference to an other model)
|
||||||
*
|
*
|
||||||
|
* @returns {String}
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
*
|
||||||
* extractType(String!)
|
* extractType(String!)
|
||||||
* // => String
|
* // => String
|
||||||
*
|
*
|
||||||
* extractType(user)
|
* extractType(user)
|
||||||
* // => ID
|
* // => ID
|
||||||
*
|
*
|
||||||
* @returns {String}
|
* extractType(ENUM_TEST_FIELD, enumeration)
|
||||||
|
* // => String
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
extractType: function (_type) {
|
extractType: function (_type, attributeType) {
|
||||||
return this.isPrimitiveType(_type)
|
return this.isPrimitiveType(_type)
|
||||||
? _type.replace('!', '')
|
? _type.replace('!', '')
|
||||||
: this.isEnumType(_type)
|
: this.isEnumType(attributeType)
|
||||||
? 'String'
|
? 'String'
|
||||||
: 'ID';
|
: 'ID';
|
||||||
},
|
},
|
||||||
@ -336,12 +345,11 @@ module.exports = {
|
|||||||
* @return {String}
|
* @return {String}
|
||||||
*/
|
*/
|
||||||
generateConnectionFieldsTypes: function (fields, model) {
|
generateConnectionFieldsTypes: function (fields, model) {
|
||||||
const { globalId } = model;
|
const { globalId, attributes } = model;
|
||||||
|
|
||||||
const primitiveFields = this.getFieldsByTypes(
|
const primitiveFields = this.getFieldsByTypes(
|
||||||
fields,
|
fields,
|
||||||
this.isNotOfTypeArray,
|
this.isNotOfTypeArray,
|
||||||
type => this.extractType(type),
|
(type, name) => this.extractType(type, (attributes[name] || {}).type),
|
||||||
);
|
);
|
||||||
|
|
||||||
const connectionFields = _.mapValues(primitiveFields, (fieldType) => ({
|
const connectionFields = _.mapValues(primitiveFields, (fieldType) => ({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user