Search code examples
faunadb

How can I print an FQL query from JavaScript as a string (e.g. to test it in the Fauna shell)?


FQL queries are constructed in JS as objects. How can I print one of these objects as a string query, for debugging purposes? For example:

q.Get(q.Ref(q.Collection("Patterns"), req.params.id))

I want to know the FQL string this makes, such as:

Get(Ref(Collection("Patterns"), "300223720476116480"))

Solution

  • You can use the toFQL method for the Expr class.

    const expr = q.Get(q.Ref(q.Collection("Patterns"), "1234"))
    
    console.log(expr.toFQL())