-
Notifications
You must be signed in to change notification settings - Fork 29
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
How Can We Simplify Creating Connections #25
Comments
This is definitely a fun one. I may have some ideas as I'm currently implementing this in my own project. Will share my experience when I have more. It's super tricky building these out from what I've done so far. |
Agreed. It gets even trickier if you add a DataLoader. I've had this sample bookmarked for a while which shows how to implement it. Could definately be a lot simpler if we remove all the boilerplate. |
That sample looks fairly basic in that it's not calculating hasNext or hasPrev..., just setting true. But it's good to get a feel for the structure of that approach. I think I've got my code to a point where it works on a bidirectional example with dataloader in the mix. I'm basically building up a That's hopefully goin gto allow me to make it so I can do paging by passing a I don't see it happening yet, but I'm definitely foreseeing having a "sortBy" enum coming into a query that would need to toggle to use a different cursor, so there could even be multiple cursor properties on an entity that I'd need to toggle between accordingly. When I get it all working, I'll chuck up some source in a gist or something. There'll be code in it that doesn't apply specific to my implementation, but the general concept would be sound. |
Linking this here as it'll definitely pave the way for EF-based solutions once complete. dotnet/efcore#14104 |
@benmccallum The connection and data loader sample wasn't really meant to be anything more than a sample on how to wire it up. In the meantime I finished a long blogpost detailing how I implement connections myself (end to end). Find the post here. On a proper implementation of On the topic of ordering results, take a look at this section. Is this of any help? |
Thanks @corstian, I really like your solution and blog post; I think it's the best option around at the moment until we sort out the EF Core solution! |
Hi @corstian, Now, when EF.Core has finished to implement SkipWhile and TakeWhile methods, do you think about to write a post using EF implementation instead of using SqlKata? Tks |
@HorjeaCosmin I haven't really seen dotnet/efcore#17065 moving forward yet, though there has been some interesting work going on in dotnet/efcore#20967, which I might link to in a blog post later on. This still isn't an EF Core solution, or am I missing something? |
You are right, sorry, I was confused by SkipWhile Linq.Queryable extension. |
In my .NET Boxed GraphQL project template I have an example of creating a GraphQL connection. I feel like there is too much boilerplate you have to write to get one of these working and I'm wondering if there are some simple ways we can simplify their creation by providing some helper methods.
Connection
Here is the main code to create the connection on my query graph type:
Repository
I feel like I've got too many methods here:
Cursors
I created a Cursor helper class to help turn any property of any arbitrary type into an opaque base64 string cursor. The code looks like this:
I initially raised this as a PR at graphql-dotnet/graphql-dotnet#678 but got confused by @jquense. I'm hoping to pickup that coversation here.
Ideas
One idea I have is if creating a connection was as simple as implementing one of two interfaces that might looks something like this:
The text was updated successfully, but these errors were encountered: