Skip to content

Commit

Permalink
createNode: Call toJSON() if defined (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
eemeli committed Dec 25, 2018
1 parent 8ef5c0d commit 9a97670
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions __tests__/createNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,3 +283,11 @@ y:
})
})
})

describe('toJSON()', () => {
test('Date', () => {
const date = new Date('2018-12-22T08:02:52Z')
const node = createNode(date)
expect(node.value).toBe(date.toJSON())
})
})
1 change: 1 addition & 0 deletions src/createNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function createMapNode(iterable, wrapScalars) {

export default function createNode(value, wrapScalars = true) {
if (value == null) return new Scalar(null)
if (typeof value.toJSON === 'function') value = value.toJSON()
if (typeof value !== 'object') return wrapScalars ? new Scalar(value) : value
if (Array.isArray(value)) {
const seq = new Seq()
Expand Down

0 comments on commit 9a97670

Please sign in to comment.