Will the planned implementation support GraphQL Relay spec extension?
What's needed here?
My understanding is you just need to implement a node field in the root query object for refetching?
The directive support landing now should enable some codegen hooks to make dealing with connections easier, but it hasn't been specced out yet.
Are you talking about Relay's GraphQL Server Specification? It's not an extension of the GraphQL spec, so much as a specification that your server needs to conform to. It's perfectly possible to construct a Relay compatible server currently using gqlgen.
I mean, yes, as long as the GraphQL featureset is complete, it is possible to construct a server that complies to the Relay spect. But, since we're talking about code generation and reducing boilerplate, a lot of what Relay requires is generally a lot of repetitive code.
Relay community outside JS isn't much, and I feel that proper support for its structures/logic would really mean a lot if implemented by this project. I am painfully aware though that it might not be a priority.
FYI, I managed to implement Relay in my project, including lazy loading for heavy types. I used genny as a code generator.
Connection example: https://github.com/MichaelMure/git-bug/blob/64354c7ce3ff8d1c8c780a93b46c933781851edf/graphql/resolvers/bug.go#L38-L54
Connection with lazy loading: https://github.com/MichaelMure/git-bug/blob/64354c7ce3ff8d1c8c780a93b46c933781851edf/graphql/resolvers/repo.go#L16-L60
Closing this, these kind of use cases should be supported by plugins https://github.com/vektah/gqlgen/issues/228
I wasn't able to have any luck with genny, so I built my own generator for Relay: https://github.com/hookactions/gqlgen-relay also includes types for PageInfo and Node
I played around with plugins but didn't have any luck either. PRs are welcome!
@tizz98 sweet!
One issue/inconvenience with relay is that there's a decent amount of boilerplate in the _schema_ itself. Code-first servers don't really need to worry about this, but since gqlgen is schema-first, is it possible to use directives and/or plugins to autogenerate the connection and edge types from a "simpler" GraphQL schema that contains only the "base" types relating to each other? Would that be too magic?
@alecbz this is being discussed in #752
FWIW I think anything that is in the relay spec can be autogenerated given some direction from the config yaml:
connections
- type: User
cursor: ID
can yield
type UserConnection {
edges: [UserEdge!]!
# etc.
}
type UserEdge {
node: User!
cursor: ID!
}
This would require substantial engineering to offer the range of options schema authors tend to expect, but the codegen for the schema falls neatly into multiple-schema file merging — i.e. the generated files can be rewritten every time and annotated as protected as with other codegen resources.
Most helpful comment
I wasn't able to have any luck with genny, so I built my own generator for Relay: https://github.com/hookactions/gqlgen-relay also includes types for
PageInfoandNodeI played around with plugins but didn't have any luck either. PRs are welcome!