mirror of
https://github.com/strapi/strapi.git
synced 2025-08-13 11:17:42 +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';
|
let type = 'String';
|
||||||
|
|
||||||
switch (definition.type) {
|
switch (definition.type) {
|
||||||
case 'string':
|
// TODO: Handle fields of type Array, Perhaps default to [Int] or [String] ...
|
||||||
case 'text':
|
|
||||||
type = 'String';
|
|
||||||
break;
|
|
||||||
case 'boolean':
|
case 'boolean':
|
||||||
type = 'Boolean';
|
type = 'Boolean';
|
||||||
break;
|
break;
|
||||||
@ -567,7 +564,10 @@ module.exports = {
|
|||||||
|
|
||||||
const entry = withRelated && withRelated.toJSON ? withRelated.toJSON() : withRelated;
|
const entry = withRelated && withRelated.toJSON ? withRelated.toJSON() : withRelated;
|
||||||
|
|
||||||
|
// Set the _type only when the value is defined
|
||||||
|
if (entry[association.alias]) {
|
||||||
entry[association.alias]._type = _.upperFirst(association.model);
|
entry[association.alias]._type = _.upperFirst(association.model);
|
||||||
|
}
|
||||||
|
|
||||||
return entry[association.alias];
|
return entry[association.alias];
|
||||||
}
|
}
|
||||||
@ -651,8 +651,8 @@ module.exports = {
|
|||||||
[ref.primaryKey]: arrayOfIds,
|
[ref.primaryKey]: arrayOfIds,
|
||||||
...where.where
|
...where.where
|
||||||
}).where;
|
}).where;
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
// falls through
|
// falls through
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -10,6 +10,11 @@ const path = require('path');
|
|||||||
// Public node modules.
|
// Public node modules.
|
||||||
const _ = require('lodash');
|
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 */
|
/* eslint-disable prefer-template */
|
||||||
/*
|
/*
|
||||||
* Set of utils for models
|
* Set of utils for models
|
||||||
@ -453,11 +458,10 @@ module.exports = {
|
|||||||
let result;
|
let result;
|
||||||
let formattedValue;
|
let formattedValue;
|
||||||
|
|
||||||
try {
|
// Check if the value if a valid candidate to be converted to a number value
|
||||||
formattedValue = !_.isNaN(_.toNumber(value)) ? _.toNumber(value) : value;
|
formattedValue = isNumeric(value)
|
||||||
} catch(err) {
|
? _.toNumber(value)
|
||||||
formattedValue = value;
|
: value;
|
||||||
}
|
|
||||||
|
|
||||||
if (_.includes(['_start', '_limit'], key)) {
|
if (_.includes(['_start', '_limit'], key)) {
|
||||||
result = convertor(formattedValue, key);
|
result = convertor(formattedValue, key);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user