-
Notifications
You must be signed in to change notification settings - Fork 62
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
allow non-nullable first and last arguments in relay-connection-arguments-spec #203
Conversation
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.
Thanks for the pull request @swac. Really appreciate the help! ❤️ I apologize for the delayed review.
I left a few comments, but overall this looks good to me. 🎉
README.md
Outdated
@@ -236,6 +236,8 @@ More specifically: | |||
- To enable forward pagination, two arguments are required: `first: Int` and `after: *`. | |||
- To enable backward pagination, two arguments are required: `last: Int` and `before: *`. | |||
|
|||
Note: If only forward pagination is enabled, the `first` argument be specified as non-nullable (i.e., `Int!` instead of `Int`). Similarly, if only backward pagination is enabled, the `last` argument can be specified as non-nullable. |
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.
Note: If only forward pagination is enabled, the `first` argument be specified as non-nullable (i.e., `Int!` instead of `Int`). Similarly, if only backward pagination is enabled, the `last` argument can be specified as non-nullable. | |
Note: If only forward pagination is enabled, the `first` argument can be specified as non-nullable (i.e., `Int!` instead of `Int`). Similarly, if only backward pagination is enabled, the `last` argument can be specified as non-nullable. |
const type = isFirstArgumentNullable | ||
? firstArgument.type | ||
: firstArgument.type.type; | ||
if (type.kind != 'NamedType' || type.name.value != 'Int') { |
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.
I think you can simplify this entire block by using the unwrapType
function that is defined at the top of this file. 😄
const type = unwrapType(firstArgument);
lastArgument.type.kind !== 'NonNullType'; | ||
const type = isLastArgumentNullable | ||
? lastArgument.type | ||
: lastArgument.type.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.
Same comment as above 😄
@@ -59,7 +59,7 @@ describe('RelayConnectionArgumentsSpec rule', () => { | |||
); | |||
}); | |||
|
|||
it('accepts connection with proper foward and backward pagination arguments', () => { | |||
it('accepts connection with proper forward and backward pagination arguments', () => { |
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.
Ha! Nice catch! Thanks for the fix.
@@ -122,7 +206,7 @@ describe('RelayConnectionArgumentsSpec rule', () => { | |||
}, | |||
], | |||
message: | |||
'Fields that support forward pagination must include a `last` argument that takes a non-negative integer as per the Relay spec.', | |||
'Fields that support backward pagination must include a `last` argument that takes a non-negative integer as per the Relay spec.', |
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.
Oops! 🤦♂ Thanks for catching this too. That previous message would be super confusing. 😂
Thanks for the review @cjoudrey! I've updated accordingly 😄 |
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.
Thanks again for the contribution. I'll include this in the next release. ❤️
This addresses #148.
The
first
argument type in a Relay connection can now be non-nullable if backward pagination is disabled (likewise forlast
when forward pagination is disabled). So the following types are now permitted:The following, however, are not permitted: