Fork me on GitHub
#graphql
<
2023-03-07
>
R.A. Porter17:03:26

I’m using superlifter in my lacinia-pedestal app and have a problem I can’t find a clean way around. There will be occasions where one or more of the remote lookups in a batch will not have a response e.g. ten ids provided and only nine of them are valid. Superlifter gets stuck looping until it can satisfy that tenth. I have looked, but I can’t find anyway to configure an operation timeout, so I’ve had to update my function called within my superfetcher so that if it is missing one of the responses, it adds an empty map with meta for the key :com.walmartlabs.lacinia.schema/type-name set to the schema type. That gives us the unfortunate situation where I return an empty object where I’d prefer there be none. Is there anyway around this situation? I would expect a means of setting a timeout, either directly on superlifter or on urania, but I’ve seen nothing in the docs or in my code search so far.

oliy19:03:08

This behaviour comes from Urania - you need to return a value for a fetch, although it should be possible for that value to be nil

oliy19:03:34

Timeouts apply to a remote call like an http request but are irrelevant to Urania / superlifter - all fetches must resolve to something

R.A. Porter19:03:32

I would have expected a nil to work as well, but then I got VERY strange behavior when things were stitched back together. Anyway, there ended up being other issues which made my hack a better solution than trying to do anything else. Thanks for a great library!

oliy19:03:46

Looking at the code I can't see an issue with a nil, unless the issue occurred later on in lacinia maybe? Either way if you have some generic code for your workaround I'd be interested to see it just to help me understand

R.A. Porter20:03:19

No generic code, but it’s pretty straightforward. I’m looping over the input ids, looking for each matched response in turn. If I have it, it gets conj’d into a result vector; if I’m missing one I put an empty map with with meta under the :com.walmartlabs.lacinia.schema/type-name key of the schema key that I’m dealing with. I tried just padding the results with empty maps including that meta, but that seemed to lead to weird results (which shocked me). It seemed like the order of the output had to match the input. (But it was late, so I might have been wrong on that last point.)

oliy20:03:26

If you look at the implementation of superfetcher, you will see that the order is important, you can't pad at the end

oliy20:03:26

You might be better off implementing u/BatchedSource yourself rather than using the convenience superfetcher

R.A. Porter20:03:25

This just released about a week ago, so I’m disinclined to change that now. But will put it on our backlog. Thanks.

R.A. Porter16:03:03

For my project, I did create my own implementation of u/BatchedSource to solve my problem, but in doing so realized I could generalize the solution back into the superfetcher macro. I’ve put up a PR if you’re interested, but would understand if you’re not. https://github.com/oliyh/superlifter/pull/28

🚀 2
R.A. Porter15:03:32

@U076R6N1L Any thoughts on when you might release 0.1.4?

oliy15:03:10

happy to do that now i guess

🙏 2
oliy15:03:10

done 🎉