Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
How Can We Simplify Creating Connections #25
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.
Here is the main code to create the connection on my query graph type:
I feel like I've got too many methods here:
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:
One idea I have is if creating a connection was as simple as implementing one of two interfaces that might looks something like this:
This was referenced
Jul 27, 2018
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.
@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 the topic of ordering results, take a look at this section.
Is this of any help?