mirror of
https://github.com/strapi/strapi.git
synced 2025-08-11 02:07:51 +00:00
Merge pull request #1345 from kamalbennani/bug/graphql-do-not-formatted-values-of-type-object
Correctly determine the numeric value candidates in GraphQL
This commit is contained in:
commit
96a2e8e4a1
@ -157,10 +157,7 @@ module.exports = {
|
||||
let type = 'String';
|
||||
|
||||
switch (definition.type) {
|
||||
case 'string':
|
||||
case 'text':
|
||||
type = 'String';
|
||||
break;
|
||||
// TODO: Handle fields of type Array, Perhaps default to [Int] or [String] ...
|
||||
case 'boolean':
|
||||
type = 'Boolean';
|
||||
break;
|
||||
@ -567,7 +564,10 @@ module.exports = {
|
||||
|
||||
const entry = withRelated && withRelated.toJSON ? withRelated.toJSON() : withRelated;
|
||||
|
||||
entry[association.alias]._type = _.upperFirst(association.model);
|
||||
// Set the _type only when the value is defined
|
||||
if (entry[association.alias]) {
|
||||
entry[association.alias]._type = _.upperFirst(association.model);
|
||||
}
|
||||
|
||||
return entry[association.alias];
|
||||
}
|
||||
@ -651,8 +651,8 @@ module.exports = {
|
||||
[ref.primaryKey]: arrayOfIds,
|
||||
...where.where
|
||||
}).where;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
// falls through
|
||||
}
|
||||
default:
|
||||
|
@ -10,6 +10,11 @@ const path = require('path');
|
||||
// Public node modules.
|
||||
const _ = require('lodash');
|
||||
|
||||
// Following this discussion https://stackoverflow.com/questions/18082/validate-decimal-numbers-in-javascript-isnumeric this function is the best implem to determine if a value is a valid number candidate
|
||||
const isNumeric = (value) => {
|
||||
return !isNaN(parseFloat(value)) && isFinite(value);
|
||||
}
|
||||
|
||||
/* eslint-disable prefer-template */
|
||||
/*
|
||||
* Set of utils for models
|
||||
@ -453,11 +458,10 @@ module.exports = {
|
||||
let result;
|
||||
let formattedValue;
|
||||
|
||||
try {
|
||||
formattedValue = !_.isNaN(_.toNumber(value)) ? _.toNumber(value) : value;
|
||||
} catch(err) {
|
||||
formattedValue = value;
|
||||
}
|
||||
// Check if the value if a valid candidate to be converted to a number value
|
||||
formattedValue = isNumeric(value)
|
||||
? _.toNumber(value)
|
||||
: value;
|
||||
|
||||
if (_.includes(['_start', '_limit'], key)) {
|
||||
result = convertor(formattedValue, key);
|
||||
|
Loading…
x
Reference in New Issue
Block a user