(Relay) connection codegen #1900
Replies: 7 comments 1 reply
-
Its something we've been wanting to express via plugins for a while - #228 |
Beta Was this translation helpful? Give feedback.
-
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Beta Was this translation helpful? Give feedback.
-
@MichaelMure I was also interested in this and tried to implement some relay specific codegen. I thought of 4 ideas that could be implemented
After creating a PR with some of the work #851 I managed to get relay connection codegen working but I was not entirely happy with the result. The gqlgen parser will error if any types are missing. E.g. an example I have seen a different graphql implementation:
This fails with gqlgen because the ShipConnection type does not exist. You then have to do something along the lines of this:
This is very clunky and probably not worth it. I then came across this project https://nexus.js.org/ and have decided to try a different approach. Generate the full schema and all relay types with nexus and then feed the resulting schema into gqlgen. I haven't looked too closely if #851 needs to modify resolvers, but if it is only modifying the schema that can also be done at schema generation time. Ciaran |
Beta Was this translation helpful? Give feedback.
-
@MichaelMure any news on this? |
Beta Was this translation helpful? Give feedback.
-
I'm not working on that. |
Beta Was this translation helpful? Give feedback.
-
Any updates? How can someone contribute? |
Beta Was this translation helpful? Give feedback.
-
What happened?
I had a shower-thought.
What did you expect?
Nothing really, but it happened anyway.
Stop having fun, what is this about ?
Ok, here it goes. In my project (https://github.com/MichaelMure/git-bug), I implemented a Relay-compliant set of connections using a code generator (genny). It works but it's a bit crude, in particular because I have to feed it the type of everything (node, edge, connection) and also because I'm not an expert in code generation. It seems to me that gqlgen would be a much better place to do this, because the types are already known and there is a codegen infrastructure.
Here is some pointers to how it works:
There is two types of connections, one that directly paginate the source and one that lazy-load (paginate a list of identifier and load only what is useful). The template is the same, the difference is what data is given to it from the resolver and the implementation of the "connection maker".
Normal connection: https://github.com/MichaelMure/git-bug/blob/master/graphql/resolvers/bug.go#L22-L51
Lazy-loading connection: https://github.com/MichaelMure/git-bug/blob/master/graphql/resolvers/repo.go#L18-L78
Is that something you would consider ? I can relicense my code to MIT if that helps.
Beta Was this translation helpful? Give feedback.
All reactions