Skip to content

Conversation

@ghost
Copy link

@ghost ghost commented Jan 16, 2018

Add a couple of simple scalars that were missed in the first version.

@ghost ghost requested a review from cfnelson January 16, 2018 19:38
Copy link
Contributor

@cfnelson cfnelson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few comments here that I think might be important to address before merging. Otherwise looks good 👍

}

export default new GraphQLScalarType({
name: 'PositiveFloat',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this name was meant to be NegativeFloat ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

}

export default new GraphQLScalarType({
name: 'PositiveInt',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe name is meant to be NegativeInt?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

import { Kind } from 'graphql/language';

function processValue(value) {
if (isNaN(value)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure if this check is for detecting if the value passed is only a valid number or testing for NaN. Making an assumption based on the error message, maybe Number.isFinite(value) would be better suited to validate that the value is not a Number. Assuming that you wish to disallow NaN & Infinity.

Would recommend the changes for the other Number scalar types if the above assumption is correct.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check isFinite. I may also want to use Number.isNaN(). Thanks.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some other things I can do to maybe make this more robust like checking against Number.MAX_SAFE_INTEGER, etc. for example.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ccuilla I realised that I should check the reference implementation as the Number.isFinite() will fail for strings. Check out how graphq.js are checking & coercing to numbers.

Copy link
Contributor

@cfnelson cfnelson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍 Will be curious to see how this pkg progresses.

@ghost ghost requested a review from rdickert January 19, 2018 20:06
},
"dependencies": {
"peerDependencies": {
"graphql": "^0.10.1"
Copy link
Contributor

@cfnelson cfnelson Feb 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ccuilla You will want to also add graphql as a devDependency in addition to having it as a peerDependency to allow for a simple quick install if someone clones your repo directly and wishes to run tests etc.

@ghost ghost merged commit 4ce0e4e into master Feb 16, 2018
@ghost ghost deleted the feat/add-negative-number-scalars branch February 16, 2018 17:40
vespertilian pushed a commit to vespertilian/graphql-scalars that referenced this pull request Oct 2, 2020
…r-scalars

Added NegativeInt and NegativeFloat scalars
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants