Fork me on GitHub
#graphql
<
2022-11-01
>
R.A. Porter01:11:04

Preface: recently took over a project using Lacinia, but haven't used it before, or GraphQL for several years. Unsurprisingly, we have an N+1 query issue, for which I plugged in superlifter today pretty easily. It's a query-only app with not much meat to it yet, so it was easy enough to add. The problem I'm having is that the unit tests and some Clerk notebooks that were provided don't currently go through the endpoint, but through lacinia directly. When I try to run them, I'm getting an error regarding a nil future. Is there some way I can tweak the environment for superlifter to work in those cases, or will I need to • change those cases to hit endpoints instead • or, switch to another library, such as Plusinia?

oliy18:11:31

You might be using the interceptors in lacinia-pedestal to set up the superlifter context before lacinia executes the query. In this case, your tests will need to init superlifter and pass it in to the lacinia context

R.A. Porter18:11:13

Thanks. I'll give that a try. I hacked around it for now, by redeffing the resolver for those test/notebook paths, but I'll see if I can get it working correctly based on your comment.

R.A. Porter16:11:07

I got it to work, but there is a bit of weirdness that maybe should be documented. Because the superlifter.lacinia/with-superlifter macro extracts the context from the nested path, [:request :superlifter], to pass along to the superlifter.api/with-superlifter macro, I ended up doing this...

(let [ctx (superlifter/start! server/superlifter-args)]
    (try
      (lacinia/execute schema query variables {:request {:superlifter ctx}})
      (finally
        (superlifter/stop! ctx))))
It's a result of trying to mix both pedestal and non-pedestal access, I guess. Not sure where, how, or even if that should be documented or I'd open a PR for it. It is a weird corner case.

oliy20:11:13

Glad you got it working. The weirdness being that you are passing a request into lacinia, which should be agnostic of http? Yeah, that doesn't look quite right. Could be easily fixed in superlifter to just stick it on the pedestal context rather than nesting it inside the request. This would break your tests of course, but would also have a trivial fix