New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
halkeye opened this Issue May 20, 2018 · 3 comments

Comments

Projects
None yet
4 participants
@halkeye
Contributor

halkeye commented May 20, 2018

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

@rametta

This comment has been minimized.

Contributor

rametta commented May 28, 2018

i also have the same problem

@ds300

This comment has been minimized.

Contributor

ds300 commented May 31, 2018

I'm also suffering from this particular problem. More discussion of the wider issue: #3344

@pieh

This comment has been minimized.

Contributor

pieh commented Jun 1, 2018

PR with fix if anyone would like to track it - #5654

@pieh pieh closed this in #5654 Jun 1, 2018

@ds300 ds300 referenced this issue Jun 6, 2018

Open

Things to do before go-live #91

1 of 16 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment