Skip to content

Commit

Permalink
Expose Sink type from relay-runtime (#4516)
Browse files Browse the repository at this point in the history
Summary:
I want to suggest exporting `Sink` & `Source` types so they can be used to type the argument of `Observable.create`, e.g. something like this:

```js
import { Observable } from 'relay-runtime';

const responseHandler = () => {} // Here I would like to use either Source or Sink types

export const createRequestHandler =
  (customFetcher: Fetcher) =>
  (request: RequestParameters, variables: Variables, cacheConfig: CacheConfig) => {
    const observable = Observable.create(sink => {
      void customFetcher(request, variables, cacheConfig)
        .then(responseHandler(sink))
        .catch((error: Error) => {
          sink.error(error);
        })
        .then(() => {
          sink.complete();
        });
    });

    return observable;
  };
```

Pull Request resolved: #4516

Reviewed By: captbaritone

Differential Revision: D51027312

Pulled By: alunyov

fbshipit-source-id: 9f2cff94e70c436acc9c8498ec890293584dc36b
  • Loading branch information
jaroslav-kubicek authored and facebook-github-bot committed Nov 6, 2023
1 parent 9e0acc1 commit 5c7555b
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/relay-runtime/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ export type {
export type {
ObservableFromValue,
Observer,
Sink,
Source,
Subscribable,
Subscription,
} from './network/RelayObservable';
Expand Down

0 comments on commit 5c7555b

Please sign in to comment.