Fork me on GitHub
#graphql
<
2021-02-16
>
fabrao09:02:28

Hello all, can I use field names with "-" instead of "_"?

fabrao09:02:48

in lacinia?

vlaaad09:02:57

I don’t think so, IIRC it’s prohibited by GraphQL spec

vlaaad09:02:09

Name
/[_A-Za-z][_0-9A-Za-z]*/

fabrao09:02:12

(defn hyphenating-default-field-resolver
  "An alternative to [[default-field-resolver]], this converts underscores in the field name
  into hyphens.  At one time, this was the default behavior."
  {:added "0.17.0"}
  [field-name]
  (-> field-name
      name
      (str/replace "_" "-")
      keyword
      default-field-resolver))
what is it means? Can I use with '-' and it change after?

hlship01:02:24

This is a mapping between the names of the GraphQL fields (“a_name_like_this”) and the keyword keys of the maps being selected (:a-name-like-this).

hlship01:02:49

Otherwise, if you want snake-case names in your GraphQL you have to provide an explicit resolver for every single field, no matter how trivial.

Lennart Buit09:02:34

You can customise the default resolver in your compile call: https://walmartlabs.github.io/apidocs/lacinia/com.walmartlabs.lacinia.schema.html#var-compile . Meaning that you can automatically convert between underscores and hyphens. That said, the convention I see most in GraphQL endpoints is actually camelCase, not snake_case.

gklijs10:02:01

I tried upgrading lacinia-pedestal to 0.15.0 from 0.12.0, making use of the 'new' pedestal2/default-service. But to no success. Does the compiled-schema also need to look different? Does someone maybe know of an example project using 0.15.0?

gklijs17:02:43

Specifically it goes wrong when trying to run aot compiled from docker. When run locally with lein run it does work.

gklijs18:02:12

So now I've found a way to create a uberjar without aot all. And when running the jar loccaly it works. But when running the jar in docker it seems like it's not doing anything. Maybe I need to set the hostname?

hlship02:02:52

What is “it goes wrong”? Does the service not start? Does it not handle requests? Is there some issue with the mapping of the container’s port to a host port?

gklijs06:02:20

It did not handle the request, and was indeed the hostname I had to change. https://github.com/gklijs/bob2021 is all updated and aside from the docs ready for BOB the 26th. I might also send a pr to change ‘my’ demo project in the lacinia from open-bank-mark to this.

👍 3