what version of biff are you on? if it’s a version prior to 2.0.5, the problem could be https://github.com/jacobobryant/biff/commit/77afee0f093494648dcdac1f74ca395ed075c414 where the exception data included an infinite sequence which causes a hang if you try to serialize it.
Assuming there is an exception being thrown, I think the problem is that the resolver function needs to take two arguments, i.e. (fn [ctx _input] …). (as syntactic sugar you can also omit the (fn …) bit and just do (defresolver user-emails {:output …} [ctx _input] …)--the (fn …) form is only required if you want to have your resolver use biff.fx)
Besides that, to get the resolver to return data in the correct shape you’ll have to restructure it a little, since {:output [:user/email]} means “return a single email address”, not “return all the email addresses”. there are a couple options:
;; option 1: return `{:global/all-user-emails ["" ...]}`
(biff.graph/defresolver all-user-emails
{:output [:global/all-user-emails]}
[ctx _input]
{:global/all-user-emails
(mapv :user/email
(biff.sqlite/execute
ctx
{:select :user/email
:from :user}))})
(comment
(biff.graph/query @myapp/system [:global/all-user-emails]))
;; option 2: return `{:global/all-users [{:user/id 1} ...]}`, then rely on the
;; builtin batch resolver from biff.sqlite to go from :user/id to :user/email
(biff.graph/defresolver all-users
{:output [{:global/all-users [:user/id]}]}
[ctx _input]
{:global/all-users
(biff.sqlite/execute
ctx
{:select :id
:from :user})})
(comment
(biff.graph/query @myapp/system [{:global/all-users [:user/email]}]))
(I like to use global as a namespace for resolvers that don’t take input)
I’d recommend option 2 since it fits better with biff.graph. e.g. if you wanted some other attribute(s) from all the users, you can add it to your query without having to write additional resolvers, e.g. (biff.graph/query @myapp/system [{:global/all-users [:user/email {:user/pet [:pet/name]}]}]) etcI’m on com.biffweb/defaults {:mvn/version "2.0.4"} so that could be the issue. Will try upgrading. Thanks also for the help about the output shape.
Working! Thanks!
awesome!
Naive question, how would an experienced Clojure person find out what the latest version of Biff was?
There are a few ways. The most authoritative way is to go to http://clojars.org and type in one of the biff libs, like com.biffweb/defaults. then you’ll find https://clojars.org/com.biffweb/defaults which lists the latest version.
Besides that, I keep this CHANGELOG file up to date: https://github.com/jacobobryant/biff/blob/master/CHANGELOG.md
and all of the individual biff libraries have a Dependency section which I also keep up to date: https://github.com/jacobobryant/biff/tree/master/libs/core#dependency
FYI there’s a new version of biff 2.0.7 out which addresses some nippy vulnerabilities:
• https://clojurians.slack.com/archives/C06MAR553/p1796188844426289
• https://clojurians.slack.com/archives/C06MAR553/p1796188844426289
biff.ring prior to 2.0.7 used nippy to encode/decode rich data in query params. Nippy versions prior to 3.10.0 have a vulnerability which allows an attacker to instantiate an arbitrary class from your classpath. My understanding is that an attacker can’t run arbitrary code unless you have certain additional things on your classpath. Regardless, I recommend upgrading immediately.
Biff 2.0.7 upgrades nippy to 3.10.0 and also stops using it for query parameter encoding (it switches to transit instead). This does mean any bookmarked URLs with npy= won’t work completely (the page will load but the query params will be ignored).