Skip to content

@graphty/graphty-element / index / replayFetch

Function: replayFetch() ​

replayFetch(recordings, options?): ReplayFetch

Defined in: graph-io/dist/src/sources/testing.d.ts:79

A fetch that answers every request from recordings: the first unused recording that matches (method, URL with its query in any order, body when recorded, and whether a credential was sent), else the last one that matched, so a recording answers every repeat. A request with no matching recording rejects with an Error naming its method and URL, which a source never retries. Like fetch, a request whose signal is already aborted rejects with the signal's reason. Pass it as the fetch option. Experimental.

Parameters ​

recordings ​

readonly Recording[]

the recorded exchanges

options? ​

ReplayOptions

which headers and query parameters hold a credential

Returns ​

ReplayFetch

the fetch

Example ​

ts
const fetch = replayFetch([{ url: "https://example.com/api/people.json?team=core", body: [{ id: "ana", knows: [] }] }]);
await loadFromSource("people", { team: "core" }, { endpoint: "https://example.com", fetch });