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

fix: ConnectionMiddleware and IEnumerable + IConnection #2378

Merged
merged 4 commits into from
Sep 27, 2020

Conversation

benmccallum
Copy link
Collaborator

Don't assume an IEnumerable/IQueryable isn't already an IConnection

Don't assume an `IEnumerable`/`IQueryable` isn't already an `IConnection`
@michaelstaib
Copy link
Member

We should write one test to prove that it works.

michaelstaib
michaelstaib previously approved these changes Sep 25, 2020
@@ -30,7 +30,11 @@ public ConnectionMiddleware(FieldDelegate next)
context.Argument<string>("after"),
context.Argument<string>("before"));

if (connectionResolver is { } && context.Result is TSource source)
if (context.Result is IConnection)
Copy link
Member

Choose a reason for hiding this comment

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

I will have to look at the new implementation so that this will work with 11 as well.

@benmccallum
Copy link
Collaborator Author

benmccallum commented Sep 27, 2020

Added a unit test for this scenario (checked without my fix and the test failed as I was seeing, so that's a good sign :P).

I'm not too clued up on the other scenarios, which don't currently have unit tests, so perhaps you'd want to quickly bang out some of those for the other types the middleware can handle (like IQueryable, IEnumerable that's not an IConnection, etc.)? Added basic coverage.

I'm just wondering one thing. Should the IConnection scenario check inside to make sure that the Edge<T>, that T is TEntity? I'm thinking not, as it's more flexibile. Essentially we're saying if you're returning an IConnection, you know what you're doing and we'll take it as is. e.g. in my case I'm returning an IConnection of Supplier, but the field is typed as a connection of SupplierResult (a union that includes supplier) as I have middleware that swaps out supplier's for GoneSupplier when the supplier has left our platform as the user isn't an admin.

@benmccallum
Copy link
Collaborator Author

benmccallum commented Sep 27, 2020

Added basic coverage of IQueryable and IEnumerable scenarios.

@michaelstaib michaelstaib merged commit e672e62 into main Sep 27, 2020
@michaelstaib michaelstaib deleted the bugfix/connection-middleware branch September 27, 2020 21:58
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