graphql

kwladyka 2020-03-09T08:08:34.025200Z

#:shop{:uuid #uuid"00000000-0000-0000-0000-000000000000",
       :name "shop foo",
       :engine "atomstore",
       :config {:foo "bar"},
       :updated_at #inst"2020-03-08T21:49:41.246726000-00:00",
       :created_at #inst"2020-03-08T21:49:41.246726000-00:00"}
How do you set lacinia with keywords like :shop/uuid
(-> (shop-db/get-shop-by-uuid uuid)
      (clojure.walk/stringify-keys)
      (clojure.walk/keywordize-keys)) 
It needs first change keywords to string to remove namespace from keyword. Next change strings to keywords. Then lacinia see them. Did you find best practice for this?

kwladyka 2020-03-09T08:09:20.025600Z

I can’t do this

{:fields {:shop/uuid {:type (non-null String)}
                  :shop/name {:type (non-null String)}
                  :shop/engine {:type (non-null String)}
                  :shop/config {:type (non-null String)}}}
because
Execution error - invalid arguments to com.walmartlabs.lacinia.schema/compile at (schema.clj:1569).
:shop/uuid - failed: simple-keyword? at: [:schema :objects 1 :fields 0] spec: :com.walmartlabs.lacinia.schema/schema-key

kwladyka 2020-03-09T08:32:37.026Z

How do you return custom JSON like in my example config? As a string?

kwladyka 2020-03-09T09:03:52.026200Z

for a mutation and query

kwladyka 2020-03-09T09:09:44.026800Z

So I have JSONB in postgresql and trying to figure out how to work with this in the best way in graphql

orestis 2020-03-09T11:18:59.027400Z

Graphql doesn't have the notion of namespaced keywords, so you can't define namespaced keys in the spec.

orestis 2020-03-09T11:20:36.028800Z

So with GraphQL you either have to type everything, or if it gets too messy, you need to resort to a String. What I did when I needed something not easily typeable, I defined an EDN_foo scalar, which at decode/encode time validate with a spec.

orestis 2020-03-09T11:21:05.029500Z

Does it make sense? So your config would be of type EDN_shop_config or something like that, then you can validate at encode/decode time.

orestis 2020-03-09T11:21:52.030500Z

If you don't care about typing at all, just make an EDN scalar and use clojure.edn to read/print stuff. Or of course, if you want JSON because your UI can't read EDN, this all applies for JSON too.

kwladyka 2020-03-09T11:49:55.031900Z

So just thinking if I want to use namespaces keywords at all. When do you use them and when not?

kwladyka 2020-03-09T11:50:18.032500Z

Especially in context of database and graphql

kwladyka 2020-03-09T11:51:14.033600Z

How it works in your systems?

kwladyka 2020-03-09T11:53:23.034200Z

So there is no solution for JSON like https://hasura.io/blog/postgres-json-and-jsonb-type-support-on-graphql-41f586e47536/ ?

kwladyka 2020-03-09T11:55:40.035200Z

It is funny to can’t use JSON type in JSON response ;)

✔️ 1
pablore 2020-03-09T16:56:39.036100Z

Given the current graphql ecosystem, would you choose lacinia or apollo + cljs for a new graphql project?

orestis 2020-03-09T17:19:22.038100Z

Apollo server? I really don’t like Node.js for writing server stuff so I’d choose Lacinia for the server. I haven’t used Apollo server “in anger” so I’m just going by the online tutorials.

✔️ 1
orestis 2020-03-09T17:22:01.042300Z

Apollo client? The value there is bigger, but based on past research, it doesn’t really play well with CLJS (they use some string literal tags to compile query strings to query “objects” which you’d have to code from scratch). Also, the fact that the project is in flux right now (new version with hooks in the works, API changes) and that they didn’t have cache invalidation at all up until now doesn’t fill me with confidence.

orestis 2020-03-09T17:22:51.043700Z

So for me Clojure wins, but if I had a team of React / Apollo experts, I’d probably go with Apollo client and JS/TypeScript.

gklijs 2020-03-09T20:30:52.048200Z

If it was to integrate with an existing JVM project I would probably use graphql-kotlin. Given most of the objects involved already exist, it can generate the schema, and most of the resolve code. And it plays nice with Apollo Federation, if needed. I also really don't like Node.js.

kwladyka 2020-03-09T21:55:10.049500Z

What do you use to not write string like

"{ shop(uuid: \"00000000-0000-0000-0000-000000000000\") {uuid name engine config}}"
or
"mutation { add_shop(name: \"qqq\" engine: \"atomstore\" config: \"{}\") {uuid name engine config}}"
to use EDN map instead Do you recommend something?

kwladyka 2020-03-09T21:55:57.049800Z

At that moment I want this mainly for tests

gklijs 2020-03-10T07:58:56.052Z

Since GraphQL is not json I think you need to parse it yourself. If you just want different variables, query variables work nice, like https://github.com/openweb-nl/kafka-graphql-examples/blob/9c2a63c2b0142746df915082ce69c2edf8830c08/test/src/nl/openweb/test/generator.clj#L26

kwladyka 2020-03-10T09:01:44.052300Z

yes, but definitely I would like to use something what already exist

kwladyka 2020-03-10T09:02:02.052500Z

it is always harder, than it looks

gklijs 2020-03-10T09:09:36.053300Z

You could use re-graph now, you can use it with clj as well, but at the time it had a few bugs to use with clj.

isak 2020-03-09T23:45:39.050200Z

@kwladyka I haven't tried it, but saw this: https://github.com/Vincit/venia