diff --git a/packages/gatsby/src/schema/data-tree-utils.js b/packages/gatsby/src/schema/data-tree-utils.js index 5e53167da2668..d53a33be41384 100644 --- a/packages/gatsby/src/schema/data-tree-utils.js +++ b/packages/gatsby/src/schema/data-tree-utils.js @@ -7,6 +7,7 @@ const invariant = require(`invariant`) const createKey = require(`./create-key`) const { typeConflictReporter } = require(`./type-conflict-reporter`) const DateType = require(`./types/type-date`) +const is32BitInteger = require(`../utils/is-32-bit-integer`) import type { TypeEntry } from "./type-conflict-reporter" @@ -118,7 +119,7 @@ const getExampleScalarFromArray = values => values, (value, nextValue) => { // Prefer floats over ints as they're more specific. - if (nextValue && _.isNumber(nextValue) && !_.isInteger(nextValue)) { + if (nextValue && _.isNumber(nextValue) && !is32BitInteger(nextValue)) { return nextValue } else if (value === null) { return nextValue diff --git a/packages/gatsby/src/schema/infer-graphql-input-fields.js b/packages/gatsby/src/schema/infer-graphql-input-fields.js index 14824128ab453..7ce564b0a1513 100644 --- a/packages/gatsby/src/schema/infer-graphql-input-fields.js +++ b/packages/gatsby/src/schema/infer-graphql-input-fields.js @@ -21,6 +21,7 @@ const { const { findLinkedNode } = require(`./infer-graphql-type`) const { getNodes } = require(`../redux`) +const is32BitInteger = require(`../utils/is-32-bit-integer`) import type { GraphQLInputFieldConfig, @@ -76,7 +77,7 @@ function inferGraphQLInputFields({ let headType = typeOf(headValue) if (headType === `number`) - headType = _.isInteger(headValue) ? `int` : `float` + headType = is32BitInteger(headValue) ? `int` : `float` // Determine type for in operator. let inType diff --git a/packages/gatsby/src/schema/infer-graphql-type.js b/packages/gatsby/src/schema/infer-graphql-type.js index be2d510ff1c2f..7c4b856fd03ca 100644 --- a/packages/gatsby/src/schema/infer-graphql-type.js +++ b/packages/gatsby/src/schema/infer-graphql-type.js @@ -19,6 +19,7 @@ const createKey = require(`./create-key`) const { getExampleValues, isEmptyObjectOrArray } = require(`./data-tree-utils`) const DateType = require(`./types/type-date`) const FileType = require(`./types/type-file`) +const is32BitInteger = require(`../utils/is-32-bit-integer`) import type { GraphQLOutputType } from "graphql" import type { @@ -117,7 +118,7 @@ function inferGraphQLType({ }), } case `number`: - return _.isInteger(exampleValue) + return is32BitInteger(exampleValue) ? { type: GraphQLInt } : { type: GraphQLFloat } default: diff --git a/packages/gatsby/src/utils/is-32-bit-integer.js b/packages/gatsby/src/utils/is-32-bit-integer.js new file mode 100644 index 0000000000000..79571106bcf23 --- /dev/null +++ b/packages/gatsby/src/utils/is-32-bit-integer.js @@ -0,0 +1,3 @@ +module.exports = function(x) { + return (x | 0) === x +} \ No newline at end of file