Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Proposal - RestLink chains #308

Open
willyboy opened this issue Jul 10, 2023 · 1 comment
Open

Feature Proposal - RestLink chains #308

willyboy opened this issue Jul 10, 2023 · 1 comment
Labels
enhancement💡 feature Feature: new addition or enhancement to existing solutions

Comments

@willyboy
Copy link

willyboy commented Jul 10, 2023

Chainable Rest Links

Background

The current architecture of the Rest Link poorly supports hitting multiple public APIs from our queries. Different APIs have different headers, different response formats and types, different credentialing mechanisms, and more.

There are many workarounds presented by a number of issues:
#264
#190

These are good one off solutions but aren't scalable patterns.

Take for instance an architecture where each feature is responsible for owning the setup for the backends it is going to use. This allows the feature to be used anywhere with no extra setup (a black box). It needs to be able to register the endpoints it is going to consume. Unfortunately, without composable rest links, to do this is hacky at best.

Proposal

Allow multiple RestLinks to be defined so that when you have situations like different headers for different endpoints, you can just add another RestLink to the chain. While maybe not a perfect solution for the problem (a perfect solution by be allowing everything for any call to be configurable from the directive), it's a healthy backstop that requires minimal effort to implement.

Implementation

Instead of deleting all @rest directives from a query in the RestLink, only delete the ones which have matching endpoints. If there is another RestLink in the chain (I think we can check the previous and next links? If not, we may have to have a toggle for saying we want composability). If a directive doesn't have a matching endpoint in one RestLink, we'll assume it's specified in the next. If we get to the end of the chain with no matches, then throw an error.

We also need to share data across the context so that as the query is processed, all data is available and we need to update the cache key for the query so that it incorporates the correct directives. I have a patch-package diff that handles all of this if the maintainers feel like this is a good enhancement.

@fbartho
Copy link
Collaborator

fbartho commented Jul 10, 2023

hey @willyboy! I’m definitely interested in seeing this approach. Conceptually I don’t have an objection to this approach. Particularly if it has a minimum of configuration options and/or doesn’t require much change to the @rest( graphql annotation.

Feel free to submit a PR and I’ll take a look!

@fbartho fbartho added enhancement💡 feature Feature: new addition or enhancement to existing solutions labels Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement💡 feature Feature: new addition or enhancement to existing solutions
Projects
None yet
Development

No branches or pull requests

2 participants