diff --git a/packages/gatsby/src/schema/__tests__/infer-graphql-type-test.js b/packages/gatsby/src/schema/__tests__/infer-graphql-type-test.js index c1be9892383d7..5952717c8b847 100644 --- a/packages/gatsby/src/schema/__tests__/infer-graphql-type-test.js +++ b/packages/gatsby/src/schema/__tests__/infer-graphql-type-test.js @@ -118,6 +118,16 @@ describe(`GraphQL type inferance`, () => { expect(result.data.listNode[0].number).toEqual(1.1) }) + 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) + }) + it(`handles date objects`, async () => { let result = await queryResult( [ diff --git a/packages/gatsby/src/schema/infer-graphql-type.js b/packages/gatsby/src/schema/infer-graphql-type.js index 187c9ba551ce9..40e5a5fd05ece 100644 --- a/packages/gatsby/src/schema/infer-graphql-type.js +++ b/packages/gatsby/src/schema/infer-graphql-type.js @@ -107,7 +107,7 @@ function inferGraphQLType({ // Check if this is a date. // All the allowed ISO 8601 date-time formats used. const momentDate = moment.utc(exampleValue, ISO_8601_FORMAT, true) - if (momentDate.isValid()) { + if (momentDate.isValid() && typeof exampleValue !== `number`) { return { type: GraphQLString, args: {