-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Change serialization for Int, Float and Boolean to work with objects #2382
Change serialization for Int, Float and Boolean to work with objects #2382
Conversation
… to have opportunity to pass objects which have valueOf() method in resolvers of Int and Float types.For example, I have such objects as "Money", "Price" and so on in my app, and they have valueOf() method which return value. Now I need to call valueof method in every resolver of such field or write custom scalar or directive.I think changes I did are implied in native type behavior of Int and Float fields.
!Array.isArray(outputValue) | ||
) { | ||
num = Number(outputValue.valueOf()); | ||
} |
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.
Please use serializeObject
instead and add it in Int
, Float
and Boolean
.
Also please update tests in https://github.com/graphql/graphql-js/blob/master/src/type/__tests__/serialization-test.js
So basically, please replicate how this is done for ID and String.
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.
@IvanGoncharov I did it.
Is it good idea to squash my 4 commits to one?
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.
Is it good idea to squash my 4 commits to one?
@alex-knyazev Both work, since it's small commit I can just "squash and merge" in GitHub UI.
Please don't forget to make the same changes and tests for GraphQLBoolean
type.
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.
@IvanGoncharov I've added the same logic for boolean type
@alex-knyazev Merged 🎉 |
It is good to have opportunity to pass objects which have valueOf() method in resolvers of Int and Float types.
For example, I have such objects as "Money", "Price" and so on in my app, and they have valueOf() method which return value. Now I need to call valueOf() method in every resolver of such field or write custom scalar or directive.
I think changes I did are implied in native type behavior of Int, Float and Boolean fields.