Skip to content

Commit

Permalink
Prefer floats over integers (#1229)
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleAMathews authored Jun 22, 2017
1 parent 404a27c commit 1cb4cf8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/gatsby/src/schema/__tests__/infer-graphql-type-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ describe(`GraphQL type inferance`, () => {
)
})

it(`prefers float when multiple number types`, async () => {
let result = await queryResult(
[{ number: 1.1 }, { number: 1 }],
`
number
`
)
expect(result.data.listNode[0].number).toEqual(1.1)
})

it(`filters out empty objects`, async () => {
let result = await queryResult(
[{ foo: {}, bar: `baz` }],
Expand Down
2 changes: 2 additions & 0 deletions packages/gatsby/src/schema/data-tree-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ const extractFieldExamples = (nodes: any[]) =>
if (!isSameType(obj, next)) return INVALID_VALUE

if (!_.isArray(obj || next)) {
// Prefer floats over ints as they're more specific.
if (obj && _.isNumber(obj) && !_.isInteger(obj)) return obj
if (obj === null) return next
if (next === null) return obj
return undefined
Expand Down

0 comments on commit 1cb4cf8

Please sign in to comment.