Skip to content

Conversation

@dpetran
Copy link
Contributor

@dpetran dpetran commented Jan 20, 2025

I've mapped a nil result when a selectOne query returns no results to the JSON string "null", which parses to null in Javascript. Without this support the response fails to conform to the QueryResponse schema.

@dpetran dpetran requested a review from a team January 20, 2025 20:42
(fn [handler]
(fn [req]
(let [{:keys [status body] :as result} (handler req)]
(if (and (= 200 status) (nil? body))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like something that should be handled by muuntaja instead of rolling our own conversion for this specific case. Is there no way to accomplish this using that library since we're already using it to convert between formats? I can see this causing issues if we ever decide to respond with edn as well as json.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gave it an honest try with muuntaja but wasn't willing to devote more than 2 hours to it. Once I couldn't get it working in that window I went back to this. I figure that if we ever do support edn there will need to be a lot of updates to the middleware anyways.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a problem with the QureryResponse schema? What happens when you just account for the possibility that :select-one query responses can also be nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then it converts the :body key to the empty string "", which isn't valid json.

Copy link
Contributor

@zonotope zonotope left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for letting this slip through the cracks.

@dpetran dpetran force-pushed the fix/select-one-nil-result branch from a5e00dd to 0571569 Compare October 28, 2025 15:52
@dpetran dpetran merged commit 48fb0cc into main Oct 28, 2025
18 of 19 checks passed
@dpetran dpetran deleted the fix/select-one-nil-result branch October 28, 2025 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants