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

Adding functionality to specify a PageSize to AllPages #126

Merged
merged 9 commits into from
Jul 19, 2018

Conversation

StanleyGoldman
Copy link
Collaborator

@StanleyGoldman StanleyGoldman commented Jul 17, 2018

  • Functionality to provide a custom page size when using AllPages

This is integral when dealing with very large queries. Queries are limited by the amount of objects they can possibly return. Not by how many objects they actually return.

Using AllPages(int) will allow the user to change the $first value and reduce the possible combination in order to craft an operational query.

@@ -12,13 +12,23 @@ class AllPagesExpression : Expression
/// Initializes a new instance of the <see cref="AllPagesExpression"/> class.
/// </summary>
/// <param name="method">The method that AllPages() was called on.</param>
public AllPagesExpression(MethodCallExpression method) => Method = method;
/// <param name="constant">The ConstantExpression that AllPages was sent</param>
public AllPagesExpression(MethodCallExpression method, ConstantExpression constant = null)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this called constant rather than something more descriptive like pageSize?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I might've been overthinking things...

Copy link
Collaborator

@grokys grokys 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, but I wonder - do we need to limit ourselves to ConstantExpression for pageSize?

@@ -736,6 +738,10 @@ private Expression RewritePagingConnectionExtensions(MethodCallExpression expres
// is visited.
return new AllPagesExpression((MethodCallExpression)expression.Arguments[0]);
}
else if (expression.Method.GetGenericMethodDefinition() == PagingConnectionExtensions.AllPagesCustomSizeMethod)
{
return new AllPagesExpression((MethodCallExpression)expression.Arguments[0], (ConstantExpression)expression.Arguments[1]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

What if the value passed into AllPages isn't a ConstantExpression? We should at least throw a helpful exception rather than an InvalidCastException here if we don't support it. Would it be difficult to support non-constant expressions?

@@ -787,16 +793,16 @@ private void AddIdSelection(ISelectionSet set)
}
}

private ISubquery AddSubquery(
MethodCallExpression expression,
private ISubquery AddSubquery(MethodCallExpression expression,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why change the formatting here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Resharper is greedy sometimes...

private Expression CreateNodeQuery(
MethodCallExpression expression,
MethodCallExpression selector)
private Expression CreateNodeQuery(MethodCallExpression expression,
Copy link
Collaborator

Choose a reason for hiding this comment

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

And here...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

And here..

MethodCallExpression RewritePagingMethodCall(
MethodCallExpression methodCall,
Expression instance)
MethodCallExpression RewritePagingMethodCall(MethodCallExpression methodCall,
Copy link
Collaborator

Choose a reason for hiding this comment

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

And here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

And here..

@@ -52,8 +52,8 @@ public void Viewer_By_GraphyQL_Matches_Api()
Assert.NotNull(graphqlUser);

Assert.Equal(apiUser.AvatarUrl, graphqlUser.AvatarUrl);
Assert.Equal(apiUser.Bio ?? string.Empty, graphqlUser.Bio);
Assert.Equal(apiUser.Company ?? string.Empty, graphqlUser.Company);
Assert.Equal(apiUser.Bio, graphqlUser.Bio);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This change is from #120, but as I mentioned there, it's causing the test to fail.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll rebase it out.

@@ -16,13 +16,6 @@ public class PagingTests

public class Repository_Issues_AllPages
{
ICompiledQuery<IEnumerable<int>> TestQuery { get; } = new Query()
.Repository("foo", "bar")
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This query being a field caused it to run on every test in this fixture.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Well to split hairs it wasn't a field, it was a property ;) But yeah it was an auto-property so it was backed by a field.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

lol

Copy link
Collaborator

@grokys grokys 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! Just one question but it's not important.

.Compile();
}

private static ICompiledQuery<IEnumerable<int>> GetTestQueryCustomSize()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this method static when GetTestQuery isn't?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oversights..

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

@@ -16,13 +16,6 @@ public class PagingTests

public class Repository_Issues_AllPages
{
ICompiledQuery<IEnumerable<int>> TestQuery { get; } = new Query()
.Repository("foo", "bar")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Well to split hairs it wasn't a field, it was a property ;) But yeah it was an auto-property so it was backed by a field.

@StanleyGoldman StanleyGoldman merged commit cc4e3a3 into master Jul 19, 2018
@StanleyGoldman StanleyGoldman deleted the fixes/all-pages-custom-size branch July 19, 2018 19:32
@StanleyGoldman StanleyGoldman added this to the v0.1.1-beta milestone Aug 10, 2018
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