graphql-weaver icon indicating copy to clipboard operation
graphql-weaver copied to clipboard

Relay support

Open FX-HAO opened this issue 7 years ago • 5 comments

Hi! Thank you so very kindly for the work! This is a tremendous piece of work!

However, I'd one question regarding "production-ready" status of the project.

Does graphql-weaver support Relay?

FX-HAO avatar Sep 14 '17 02:09 FX-HAO

Hi,

thanks for the feedback. I'd consider graphql-weaver in the public beta status. We tested a wide range of use cases and edge cases (see these regression tests). But I'm sure there are still some cases where you might stumble upon a problem, see e.g. issue #3. Those are relatively easy to fix, but it's hard to anticipate every case in advance. We use it for active app development, but not in production yet.

Regarding relay: From a graphql perspective, there is nothing special about relay, so it should work just fine. Our special features like join however do not have support for relay-style connections, so no paging in joined fields yet.

Yogu avatar Sep 14 '17 08:09 Yogu

But there are some special cases, such as Relay Classic needs the node field on the root of Query, see: https://github.com/apollographql/graphql-tools/pull/382#issuecomment-329097473. BTW, Relay Modern seems that it does not need the node field.

FX-HAO avatar Sep 14 '17 08:09 FX-HAO

So I guess that would require a field node in the root type that accepts an id and decides from this id which endpoint it needs to call to resolve this field. This is currently not supported, but would fit well into the architecture. I think it would be a valuable addition, even if relay modern does not need it. I see if I find time to implement it in the near future. If you want to contribute, I can also give you some pointers where to start.

Yogu avatar Sep 14 '17 08:09 Yogu

I don't have much time right now, but i'd like to contribute it when i am free. It's nice to provide your advices, it's helpful to me or someone who wants to contribute.

FX-HAO avatar Sep 14 '17 10:09 FX-HAO

Ok, a rough outline:

  • This would be a new postMergeModule, see Custom Transformations in the README for an introduction.
  • Somehow, the module needs to be able to assign ids to endpoints. I don't think this can be done in a generic way (except from prefixing the IDs which is not necessary what we want). One possibility would be for the module to accept a callback as argument which returns an endpoint name for an id
  • The module then uses transformExtendedSchema to add a new field node to the root query type. (use transformFields like described in the README)
  • The type of node would be a union of all node fields of the endpoints.
  • transformQuery in the pipeline module would just remove the node field so that it is not directly sent to the underlying schemas
  • The resolver of node calls the callback to find out the endpoint, then queries this endpoint. See ProxyResolversModule on how to do such a query.

Yogu avatar Sep 14 '17 11:09 Yogu