Skip to content
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

Integers are treated as String when they are a valid moment date #3459

Closed
Khaledgarbaya opened this issue Jan 10, 2018 · 1 comment
Closed

Comments

@Khaledgarbaya
Copy link
Contributor

Khaledgarbaya commented Jan 10, 2018

Description

If you have a number field with values like2018 Gatsby will think it is a date string and add it in the schema as a GraphQLString instead of GraphQLInt or GraphQLFloat. I think what is causing this problem is this check. It is mainly a problem of order for the checks so if we move that check here

I would like to create a PR to fix this. If there is a better place to fix this please direct me to it and any feedback is appreciated.

If you add this test to infer-graphql-test.js

  it(`handles integer with valid date format`, async () => {
    let result = await queryResult(
      [{ number: 2018 }, { number: 1987 }],
      `
        number
      `
    )
    expect(result.data.listNode[0].number).toEqual(2018)
  })

you will get this error

screen shot 2018-01-10 at 14 37 42

cc @KyleAMathews

Environment

Gatsby version: Latest
Node.js version: 8.4.x
Operating System: All

Actual result

If you have a number field with values like2018 Gatsby will think it is a date string and add it in the schema as a GraphQLString instead of GraphQLInt or GraphQLFloat

Expected behavior

Integer values are returned as GraphQLInt or GraphQLFloat

Steps to reproduce

I found out about this using gatsby-source-contentful

1. Create a content module with an integer field

2. enter a value that can be a valid date 2018

3. Use GeaphIQl to query the data

4. Observe the issue

@Khaledgarbaya
Copy link
Contributor Author

After more investigation adding typeof exampleValue !== 'number' here should do the trick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant