oksa icon indicating copy to clipboard operation
oksa copied to clipboard

Support name transformers

Open ilmoraunio opened this issue 1 year ago • 0 comments

We should consider supporting non-standard compliant representations for field names through name transformers. The name transformers should convert the field names either at parse time or during unparse time.

Use cases / rationale

  1. Sometimes you need to use & preserve namespaces on keywords, see example from graphql-query library.

Paraphrasing the example behind the link:

(oksa.core/gql 
  [[:employee {:name-fn (fn [field-name]
                          (str (when (namespace field-name)
                                 (str (namespace field-name) "_"))
                               (name field-name)))}
    [:user/name :user/address]]])

; => ; => "{employee{user_name user_address}}"
  1. Some developers might prefer using kebab-casing on their field names even though the unparse could result in a camelCased output (or some other casing format), similar to how honeysql may sometimes transform hyphens to underscores for a more idiomatic Clojure~y representation.

Example:

(require '[camel-snake-kebab.core :as csk])

(oksa.core/gql 
  [[:employee {:name-fn csk/->camelCase}
    [:user-name :user-address]]])

; => ; => "{employee{userName userAddress}}"

ilmoraunio avatar Apr 25 '24 16:04 ilmoraunio