Skip to content
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

Merged
merged 4 commits into from
Jan 27, 2020

Conversation

swac
Copy link
Contributor

@swac swac commented Jan 2, 2020

This addresses #148.

The first argument type in a Relay connection can now be non-nullable if backward pagination is disabled (likewise for last when forward pagination is disabled). So the following types are now permitted:

type Query {
  users(last: Int!, before: String): UserConnection
}
type Query {
  users(first: Int!, after: String): UserConnection
}

The following, however, are not permitted:

type Query {
  users(first: Int!, after: String, last: Int, before: String): UserConnection
}
type Query {
  users(first: Int, after: String, last: Int!, before: String): UserConnection
}

Copy link
Owner

@cjoudrey cjoudrey left a 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.
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
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') {
Copy link
Owner

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;
Copy link
Owner

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', () => {
Copy link
Owner

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.',
Copy link
Owner

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. 😂

@swac swac requested a review from cjoudrey January 24, 2020 05:28
@swac
Copy link
Contributor Author

swac commented Jan 24, 2020

Thanks for the review @cjoudrey! I've updated accordingly 😄

Copy link
Owner

@cjoudrey cjoudrey left a 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. ❤️

@cjoudrey cjoudrey merged commit 22f29f2 into cjoudrey:master Jan 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants