Skip to content

Graphql infer types gets broken with a mix of float and int #5486

Closed
@halkeye

Description

@halkeye

Description

As per danoc/gatsby-source-strava-activities#1 I was having isssues with graphql when the results were mixed int and float.

Steps to reproduce

You can use strava-activities and have some activities that have a max speed of a whole number.

I also tracked it down and was able to make a test case

diff --git a/packages/gatsby/src/schema/__tests__/infer-graphql-input-type-test.js b/packages/gatsby/src/schema/__tests__/infer-graphql-input-type-test.js
index 95d9f2b0..e0300c7b 100644
--- a/packages/gatsby/src/schema/__tests__/infer-graphql-input-type-test.js
+++ b/packages/gatsby/src/schema/__tests__/infer-graphql-input-type-test.js
@@ -229,6 +229,16 @@ describe(`GraphQL Input args`, () => {
     )
   })
 
+  it(`Handles a mix of float and int`, async () => {
+    let fields = inferInputObjectStructureFromNodes({
+      nodes: [
+        { speed: 1 },
+        { speed: 2.1 },
+      ],
+    }).inferredFields
+    expect(fields.speed.type.toString()).toContain(`Float`)
+  })
+
   it(`Replaces unsupported values in keys`, () => {
     // Add a key with unsupported values to test
     // if they're replaced.

Expected result

Graphql figures out the node field should be a float

Actual result

If the first result is an int, gatsby infers that its an int, not a float

Environment

  • Gatsby version (npm list gatsby):
    gatsby@1.9.260
  • gatsby-cli version (gatsby --version):
    1.9.260
  • Node.js version:
    v8.11.2
  • Operating System:
$ lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description:    CentOS Linux release 7.5.1804 (Core) 
Release:        7.5.1804
Codename:       Core

File contents (if changed)

Not applicable so not filling out, but i can
gatsby-config.js: N/A
package.json: N/A
gatsby-node.js: N/A
gatsby-browser.js: N/A
gatsby-ssr.js: N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugAn issue or pull request relating to a bug in Gatsby

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions