Error updating Function from JS: [InvalidValue: Provided Function must take at least 1 argument.]

Using fauna shell this works right:

Update(Select("ref",Get(Function("verify_user"))), {
    body: 
      Query(
        Lambda(
          ["account", "verified"],
          Update(
            Select(["ref"], Get(Match(Index("unique_User_account"), Var("account")))),
            { data: { isVerified: Var("verified") } }
          )
        )
      )
})

However trying to update same funciton through JS driver gives me an error:

await client.query(
        q.Update(q.Select('ref', q.Get(Function('verify_user'))), {
          name: 'verify_user',
          body: q.Query(
            q.Lambda(
              ['account', 'verified'],
              q.Update(
                q.Select(
                  ['ref'],
                  q.Get(
                    q.Match(q.Index('unique_User_account'), q.Var('account'))
                  )
                ),
                { data: { isVerified: q.Var('verified') } }
              )
            )
          ),
        })
      )

[InvalidValue: Provided Function must take at least 1 argument.] {
description: undefined
}

Any hints?

In the JS version of your query, you have Function instead of q.Function. Function is a JavaScript built-in class.

Also, the clause q.Select('ref', q.Get(Function('verify_user'))) is doing work that is unnecessary.

The reference to a function is just Function('function_name'), for example:

> Get(Function("double"))
{
  ref: Function("double"),
  ts: 1619547061190000,
  name: 'double',
  body: Query(Lambda("X", Add(Var("X"), Var("X"))))
}

Notice that the ref field shows just Function('double').

So, you can avoid using Select and Get and just do:

Update(Function('verify_user'), { ... })`

or, in JavaScript:

q.Update(q.Function('verify_user'), { ... })`
1 Like

Dammit I missed that one :blush:

Thanks for the answer and the extra tip @ewan

1 Like