Return result of two queries

Hi my NodeJS web app in which I use Fauna is a guestbook/comment system. Whenever a user visits one of its pages, an array of messages is obtained through a query like this:

const messages = await faunaClient.query(
		Select([ 'data' ], Map(
		  Paginate(Match(Index('allMessages'))),
		  Lambda(['ts','name','email','url','message','reply'],{
			date:    Var('ts'),
			name:    Var('name'),
			email:   Var('email'),
			url:     Var('url'),
			message: Var('message'),
			reply: Var('reply')
})))); //the allMessages index returns these fields

So far so good, it works, but my app includes server side rendering of HTML pages, templates and other data for which are stored in a fauna document (in same DB) as well. Of course I can query the respective document, which will mean another Fauna API call and basically extra delay for associated network operations.

Is there a way to form a query that will combine results of two queries into an array or an object with two fields (one with array of messages like shown above and the second one with a result of another query)?

Hi @TheProject and welcome! :wave:

Objects and arrays are valid parts of an FQL query. You could for example do something like this in javascript:

const messages = Select([ 'data' ], Map(
  Paginate(Match(Index('allMessages'))),
  Lambda(['ts','name','email','url','message','reply'],{
  date:    Var('ts'),
  name:    Var('name'),
  email:   Var('email'),
  url:     Var('url'),
  message: Var('message'),
  reply: Var('reply')
})));

const otherResults = Paginate(/*...*/);

const payload = await client.query({
  messages,
  otherResults,
})