When a user presses a button in my App, I want to make a series of AJAX calls. In JavaScript, it might looks something like
async function submit() {
const fooData = await fetch('https://example.com/foo')
const [barData, bazData] = await Promise.all(
fetch(`https://example.com/bar/${fooData.barID}`),
fetch(`https://example.com/baz/${fooData.bazID}`),
)
return Object.assign(fooData, {
bar: barData,
baz: bazData,
})
I can think of a couple ways to do this:
- Three Queries:
getFoo
,getBar
, andgetBaz
.getFoo
is triggered by the button click.getBar
andgetBaz
are both triggered bygetFoo
on success. I might use a Transformer to combineget{Foo,Bar,Baz}.data
after they’re all finished. - One
getFoo
query plus asynchronous code in its on-success transformer to fetch the Bar and Baz data. Can I even callfetch
in a Transformer?