Skip to content

Commit

Permalink
handles integer with valida date format correctly (gatsbyjs#3461)
Browse files Browse the repository at this point in the history
  • Loading branch information
Khaledgarbaya authored and jastack committed Jan 24, 2018
1 parent 3492447 commit 771f241
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
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 @@ -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(
[
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/schema/infer-graphql-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 771f241

Please sign in to comment.