HI! I’m going to be fishing for opinions here/experiences here, both from you with actual experience and those who are yet contemplating it.
Apollo Federation does great things for GraphQL but GraphQL itself has edges that are sharp and prickly (pun fully intended). I’ll mention just two - namespacing, but there are numerous others (read this proposal of mine if you’re interested).
Now, while I would very much like to get that proposal going faster, it can’t happen immediately and can’t change the past or some other things. We’re at the stage where we:
- May already have legacy GraphQL services that aren’t federation-ready in structure/model and not just directives.
- May want to expose additional or different models (schemas) to specific clients beyond just filtering them down.
- We had our fun with the federation, learned some lessons, and now want to do a better job while retaining the compatibility with existing federation clients and would appreciate help in that respect.
Now, what I’ve done in the past is to perform model/graph transformations at run-time to present a GraphQL schema that appears different from what it is backed by, back in ~2021. Now, that specific case wasn’t federated but the principles are the same and, at least analogous. What I had to do, in order of increasing complexity:
- Rename types to make them more publicly appropriate. This can also be useful for shoehorning namespacing.
- Remap values - you can easily see how this can work for enums but it also applies to representation forms of other types - dates and timestamps are easy examples, blank strings and magic values misused in place of
null
s, but there are many others. - Transform raw ids into links and, perhaps, hide those raw ids.
- Add extra documentation and directives not present in the source (think sample/test data, requests, ownership, etc)
- Change link cardinality between “…-to-one” and “…-to-many” to align with the future direction. Yes, …to-many can change to …-to-one if it never had more than one value.
- Introduce link shortcuts - these can either expose a longer chain as a single link or apply criteria to match specific values from -to-many mixed bags or a combination of those.
- Rework edge case and error handling, convert/move between in-data embedded errors and GraphQL errors.
- Much of the above on the input/argument side, in the other direction. This gets especially tricky when trying to present a common approach to expressing search criteria across otherwise varied subgraphs.
There are few extra things of interest here:
- This could be done as a wrapper, too.
- It would be nice to be able to run this outside federation too, to test a subgraph in isolation
- This could be used in front of Federation, as a part of the “Contracts” feature too, to add extra power there.
- It could support AOP cross-cutting so that repeated transformational patterns don’t need to be explicitly duplicated and reduplicated, many times (pun intended, again).
- Depending on how it is done, it may form a “core” that could be applied to other connectors, such as REST but also others.
How many of you would consider this helpful, either to continue your federation journey or to eliminate fears of starting one?
I’d be, given time to dedicate to this, very interested in working on the above. Anyone else? Apollo?