I am starting to get the hang of FQL but often just want to see what an expression evaluates to, especially when I’m a few nested Lets into my query with a multiple variables set. Is there a way to print/log at intermediary steps in the Shell for debugging purposes?
I understand completely why you would want that .
Of course, that means we need to print somewhere that makes sense since that FQL is, of course, executed on the FaunaDB’s side. At this point we do not have a mechanism to log and send these logs back to the client. Similar to this request, there are feature-requests in our backlog to have feedback on the results of ABAC FQL-based roles as well, we are definitely considering these ideas but have not implemented them yet.
The best advice I can give you atm is to build your FQL step by step. I typically construct everything with Let constructs and initially return each step of the Let to see the result while I’m writing a query. I often try it out in the dashboard shell and/or write unit tests immediately if I’m writing complex ABAC roles.
Check out Format. Specifically, the %@ conversion parameter. It states
The result is formatted as the FaunaDB wire protocol. (This is a debug conversion which applies to all non-scalar values)
That means you can wrap any query, or portion of a query, in Abort(Format('%@', ... )) to force the query to stop and just give you a portion of the wire protocol. Quite handy.
Credit goes at least to @gahabeen, @eigilsagafos and maybe others, for bringing to my attention.
For this is might be easiest to inspect just CurrentIdentity() using one of the drivers.
const userClient = new Client({ secret: USER_TOKEN })
userClient.query(CurrentIdentity())
You can be confident that the Identity for the role predicate comes from the token used to create the client, so just running the query for it directly will work.
You can Abort(Format(...)) this if you really want to see the wire protocol, but the Ref results, or even Get(CurrentIdendity()) might give you all the clues you’re looking for.