Dynamic pull selector

I wan’t to pass inn a pull selector as an argument to a query, like this:

(d/q '[:find (pull ?e ?fields)
         :in $ ?fields
         :where [?e :game/name _]] 
  (d/db conn) [:db/id :game/name])

But this results in a “Invalid pull syntax” exception. The alternative (which I’m doing now) is to use the find query to get out all the entity ids I’m interested in, and then running pull on each of those ids. But since I’m using the client.api, that would result in a lot of overhead in communicating with the peer server, right?

Is there a way to pass in the pull selector dynamically that I’ve missed in the documentation?

Hey @Robin, poking around the query I got this to work:

(d/q '[:find (pull ?e fields)
:in $ fields
:where [?e :game/name _]]
(d/db conn) '[*])

Which can be rewritten as:

(d/q '[:find (pull ?e fields)
:in $ fields
:where [?e :game/name _]]
(d/db conn) '[:db/id :game/name])

Not sure why though =)…

Hope it helps!

1 Like

I’m sure you’ve figured this out since June, but in case someone else encounters this:

You can pass pull expressions as arguments to a query, but you don’t prefix a ?. That’s reserved for logic variables, or something. Renaming ?fields to fields should fix this.