#: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?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
How do you return custom JSON like in my example config
? As a string?
for a mutation and query
So I have JSONB in postgresql and trying to figure out how to work with this in the best way in graphql
Graphql doesn't have the notion of namespaced keywords, so you can't define namespaced keys in the spec.
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.
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.
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.
So just thinking if I want to use namespaces keywords at all. When do you use them and when not?
Especially in context of database and graphql
How it works in your systems?
So there is no solution for JSON like https://hasura.io/blog/postgres-json-and-jsonb-type-support-on-graphql-41f586e47536/ ?
It is funny to can’t use JSON type in JSON response ;)
Given the current graphql ecosystem, would you choose lacinia or apollo + cljs for a new graphql project?
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.
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.
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.
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.
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?At that moment I want this mainly for tests
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
yes, but definitely I would like to use something what already exist
it is always harder, than it looks
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.
@kwladyka I haven't tried it, but saw this: https://github.com/Vincit/venia