-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Scalar coercion cleanup #1414
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
Scalar coercion cleanup #1414
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,7 +69,7 @@ describe('Type System: Scalar coercion', () => { | |
| 'Int cannot represent non-integer value: Infinity', | ||
| ); | ||
| expect(() => GraphQLInt.serialize([5])).to.throw( | ||
| 'Int cannot represent an array value: [5]', | ||
| 'Int cannot represent non-integer value: [5]', | ||
| ); | ||
| }); | ||
|
|
||
|
|
@@ -98,7 +98,7 @@ describe('Type System: Scalar coercion', () => { | |
| 'Float cannot represent non numeric value: ""', | ||
| ); | ||
| expect(() => GraphQLFloat.serialize([5])).to.throw( | ||
| 'Float cannot represent an array value: [5]', | ||
| 'Float cannot represent non numeric value: [5]', | ||
| ); | ||
| }); | ||
|
|
||
|
|
@@ -109,15 +109,6 @@ describe('Type System: Scalar coercion', () => { | |
| expect(GraphQLString.serialize(true)).to.equal('true'); | ||
| expect(GraphQLString.serialize(false)).to.equal('false'); | ||
|
|
||
| expect(() => GraphQLString.serialize([1])).to.throw( | ||
| 'String cannot represent value: [1]', | ||
| ); | ||
|
|
||
| const badObjValue = {}; | ||
| expect(() => GraphQLString.serialize(badObjValue)).to.throw( | ||
| 'String cannot represent value: {}', | ||
| ); | ||
|
|
||
| const stringableObjValue = { | ||
| valueOf() { | ||
| return 'something useful'; | ||
|
|
@@ -126,19 +117,41 @@ describe('Type System: Scalar coercion', () => { | |
| expect(GraphQLString.serialize(stringableObjValue)).to.equal( | ||
| 'something useful', | ||
| ); | ||
|
|
||
| expect(() => GraphQLString.serialize(NaN)).to.throw( | ||
| 'String cannot represent value: NaN', | ||
| ); | ||
|
|
||
| expect(() => GraphQLString.serialize([1])).to.throw( | ||
| 'String cannot represent value: [1]', | ||
| ); | ||
|
|
||
| const badObjValue = {}; | ||
| expect(() => GraphQLString.serialize(badObjValue)).to.throw( | ||
| 'String cannot represent value: {}', | ||
| ); | ||
| }); | ||
|
|
||
| it('serializes output as Boolean', () => { | ||
| expect(GraphQLBoolean.serialize('string')).to.equal(true); | ||
| expect(GraphQLBoolean.serialize('false')).to.equal(true); | ||
| expect(GraphQLBoolean.serialize('')).to.equal(false); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Converting non-empty strings to |
||
| expect(GraphQLBoolean.serialize(1)).to.equal(true); | ||
| expect(GraphQLBoolean.serialize(0)).to.equal(false); | ||
| expect(GraphQLBoolean.serialize(true)).to.equal(true); | ||
| expect(GraphQLBoolean.serialize(false)).to.equal(false); | ||
|
|
||
| expect(() => GraphQLBoolean.serialize(NaN)).to.throw( | ||
| 'Boolean cannot represent a non boolean value: NaN', | ||
| ); | ||
| expect(() => GraphQLBoolean.serialize('')).to.throw( | ||
| 'Boolean cannot represent a non boolean value: ""', | ||
| ); | ||
| expect(() => GraphQLBoolean.serialize('true')).to.throw( | ||
| 'Boolean cannot represent a non boolean value: "true"', | ||
| ); | ||
| expect(() => GraphQLBoolean.serialize([false])).to.throw( | ||
| 'Boolean cannot represent an array value: [false]', | ||
| 'Boolean cannot represent a non boolean value: [false]', | ||
| ); | ||
| expect(() => GraphQLBoolean.serialize({})).to.throw( | ||
| 'Boolean cannot represent a non boolean value: {}', | ||
| ); | ||
| }); | ||
|
|
||
|
|
@@ -148,6 +161,7 @@ describe('Type System: Scalar coercion', () => { | |
| expect(GraphQLID.serialize('')).to.equal(''); | ||
| expect(GraphQLID.serialize(123)).to.equal('123'); | ||
| expect(GraphQLID.serialize(0)).to.equal('0'); | ||
| expect(GraphQLID.serialize(-1)).to.equal('-1'); | ||
|
|
||
| const objValue = { | ||
| _id: 123, | ||
|
|
@@ -171,8 +185,8 @@ describe('Type System: Scalar coercion', () => { | |
| 'ID cannot represent value: true', | ||
| ); | ||
|
|
||
| expect(() => GraphQLID.serialize(-1.1)).to.throw( | ||
| 'ID cannot represent value: -1.1', | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh that's a great change: making the test clear the reason it fails is floating-point coercion not negative-number coercion. |
||
| expect(() => GraphQLID.serialize(3.14)).to.throw( | ||
| 'ID cannot represent value: 3.14', | ||
| ); | ||
|
|
||
| expect(() => GraphQLID.serialize({})).to.throw( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one more example why current coercion rules looks strange and confusing:
"true" => true"false" => true