Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Differentiate between terminating and non-terminating links on the type level #1244

Open
anka-213 opened this issue Feb 4, 2020 · 0 comments

Comments

@anka-213
Copy link

anka-213 commented Feb 4, 2020

The behavior and usage of a terminating ApolloLink and the non-terminating variant is fundamentally different and there is no reason that they should be the same type.

  • You can combine two non-terminating links and get a non-terminating link
  • You can combine a non-terminating link with a terminating link and get a terminating link
  • All other combinations are forbidden/useless
  • Only terminating links can be executed

If the two kinds of links had separate types we could enforce correct usage (always ending the chain with a single terminating link) automatically for typescript users and have clearer documentation for everyone. The only question is if it can be done easily in a backwards-compatible way.


The type signature of concat could be something like this:

export class ApolloLinkMiddleware {
  public concat(next: ApolloLinkMiddleware | NonTerminatingRequestHandler): ApolloLinkMiddleware;
  public concat(next: ApolloLink | TerminatingRequestHandler): ApolloLink;
}

where

export type NonTerminatingRequestHandler = (operation: Operation, forward: NextLink) => Observable<FetchResult> | null;
export type TerminatingRequestHandler = (operation: Operation) => Observable<FetchResult> | null; 
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant