roam-research-private-api icon indicating copy to clipboard operation
roam-research-private-api copied to clipboard

Add inputs option to runQuery method

Open d4hines opened this issue 3 years ago • 1 comments

Closes #16.

d4hines avatar Dec 08 '21 20:12 d4hines

This doesn't work. It appears that closure variables aren't passed directly to the context that the callback is executed in. It also seems that roamAlphaAPI.q is variadic. So maybe the best thing to do is to overload this function - if query is a string, evaluate the query with roamAlphaAPI.q(query); but if query is an array, do roamAlphaAPI.q.apply(query).

EDIT: I tried this on an example query in the browser and got this error:

// example query
window.roamAlphaAPI.q.apply(null,[`[
  :find ?b
  :in $ ?target-date-title
  :where
  [?target-date :node/title ?target-date-title]
  [(ancestor ?b ?target-date)]
]`, targetDate, ancestorRule]);

// error
"Error: Extra inputs passed, expected: [$ ?target-date-title], got: 3
    at new <anonymous> (https://roamresearch.com/js/compiled/main.js?__WB_REVISION__=8bb0c07ce3839c921d406698a9df75d3:3831:193)
    at Function.zd (https://roamresearch.com/js/compiled/main.js?__WB_REVISION__=8bb0c07ce3839c921d406698a9df75d3:7250:325)
    at Function.xd (https://roamresearch.com/js/compiled/main.js?__WB_REVISION__=8bb0c07ce3839c921d406698a9df75d3:7250:277)
    at aua (https://roamresearch.com/js/compiled/main.js?__WB_REVISION__=8bb0c07ce3839c921d406698a9df75d3:4171:72)
    at Function.Ad (https://roamresearch.com/js/compiled/main.js?__WB_REVISION__=8bb0c07ce3839c921d406698a9df75d3:8395:191)
    at Function.Kd (https://roamresearch.com/js/compiled/main.js?__WB_REVISION__=8bb0c07ce3839c921d406698a9df75d3:8396:65)
    at Function.zd (https://roamresearch.com/js/compiled/main.js?__WB_REVISION__=8bb0c07ce3839c921d406698a9df75d3:6849:289)
    at Function.r4.Ad (/js/compiled/route-app.js:2236:311)
    at Function.r4.Kd (/js/compiled/route-app.js:2236:413)
    at Function.Dd (https://roamresearch.com/js/compiled/main.js?__WB_REVISION__=8bb0c07ce3839c921d406698a9df75d3:6849:428)
    at l (/js/compiled/route-app.js:1954:415)
    at k (/js/compiled/route-app.js:1954:369)
    at <anonymous>:1:23"

d4hines avatar Dec 09 '21 13:12 d4hines