Fork me on GitHub
#graphql
<
2020-03-09
>
kwladyka08:03:34

#: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?

kwladyka08:03:20

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

kwladyka08:03:37

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

kwladyka09:03:52

for a mutation and query

kwladyka09:03:44

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

orestis11:03:59

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

orestis11:03:36

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.

orestis11:03:05

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.

orestis11:03:52

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.

kwladyka11:03:55

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

kwladyka11:03:18

Especially in context of database and graphql

kwladyka11:03:14

How it works in your systems?

kwladyka11:03:40

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

✔️ 1
pablore16:03:39

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

orestis17:03:22

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
orestis17:03:01

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.

orestis17:03:51

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.

gklijs20:03:52

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.

kwladyka21:03:10

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?

kwladyka21:03:57

At that moment I want this mainly for tests

gklijs07:03:56

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

kwladyka09:03:44

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

kwladyka09:03:02

it is always harder, than it looks

gklijs09:03:36

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.

isak23:03:39

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