This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-09-11
Channels
- # aleph (4)
- # beginners (68)
- # boot (21)
- # chestnut (1)
- # cljs-dev (72)
- # clojure (64)
- # clojure-austin (9)
- # clojure-dusseldorf (16)
- # clojure-gamedev (2)
- # clojure-italy (32)
- # clojure-russia (80)
- # clojure-spec (9)
- # clojure-uk (20)
- # clojurescript (105)
- # cursive (5)
- # data-science (5)
- # datomic (23)
- # defnpodcast (3)
- # emacs (22)
- # fulcro (2)
- # graphql (63)
- # hoplon (7)
- # lein-figwheel (17)
- # lumo (63)
- # mount (2)
- # nrepl (4)
- # off-topic (66)
- # om (6)
- # onyx (3)
- # portkey (54)
- # re-frame (12)
- # reagent (12)
- # specter (42)
- # uncomplicate (1)
- # unrepl (38)
- # vim (9)
- # yada (3)
@hlship: we’ve been playing with lacinia and it’s been really great so far… One thing I’d really like to do is support content negotiation formats other than JSON… In particular EDN but also others too (depending on the query). Is this currently possible with lacinia-pedestal?
@rickmoynihan irrc lacinia-pedestal uses a multimethod to extract the query
@hmaurer: is that for the request or the response? I meant the response, I should’ve been clearer.
@rickmoynihan ah! that was for the request
might be able to just assoc a new response interceptor over the existing one after constructing the server, but before starting it… not that familiar with pedestal though…
@rickmoynihan that’s the interceptor which converts the response to json: https://github.com/walmartlabs/lacinia-pedestal/blob/master/src/com/walmartlabs/lacinia/pedestal.clj#L92
yeah was thinking I could just dissoc that and add my own, that does some content-neg on the accept header, returning either json or EDN
though I wonder if that would be a nice addition to lacinia-pedestal…
I want to implement kebab case schema support for lacinia, it should not be very hard, but I want to make it working only when explicit flag to compile function provided, it's really needed for adding graphql to our project. Any suggestions from users/maintainers of lacinia?
@andrewtropin why do you want to do this? GraphQL does not support kebab case, so I assume it’s only for aestetic reasons?
I don’t particularly care about having kebab case, but I wish graphql had support for namespaces
I think it would be good for interop if graphql would let you identify that a particular endpoint supported the schemas that your client requires. And that schemas could be shared, and think namespaces are basically a way to do that.
for example the __
prefix seems like a bit of a hack in lieu of having proper namespace support.
@hmaurer We already have a huge codebase with REST api and kebab-cased names is all over the code. I want to do following: add graphql endpoint, keep all internals kebabish, add kebabed lacinia schema, but provide camelCase responses and accept camelCase request based on accept and content type headers. It will make all downstream apps like graphiql still working, but also allows us not to change existing codebase too much.
@andrewtropin you can do it by converting back and forth between kebab case and camelCase in resolvers
Yes, I can, but it's necessary to do it in each resolver, which seems like copy-pasting, takes out params destructuring and other little, but annoying things.
you could even automatically wrap each resolver in a function that does this conversation
(I have the very problem you describe in my current project, and solved it in a similar way)
Thought about it, but it looks a little hacky, also will decrease perfomance.
whether it’s implement in lacinia or in your code doesn’t matter much performance-wise
and even then, I wouldn’t be worried about performance on this kind of operation unless you have huuuge input/outputs
the time it takes to convert the keys of a small map to kebab case should be negligible compared to everything else happening in your app
There is some truth in your words : ) Anyway, It will be much simpler to have all internals in kebab case and only change case between delivering response then transforming data back and forth in many places (even automatically). Isn't it?
for example, in my case I not only want to do conversion to kebab-case, but I also want to namespace fields
I feel those things are best left to be implemented in userland, leaving Lacinia as an unopinionated implementation of GraphQL
if you want to push those conversions as far out of your way as possible. write a function on the resolvers map (right before passing it to lacinia.util/attach-resolvers
)
you could wrap each resolver in a function which does the conversion on args and on the output
by default, Lacinia will resolve fields by doing something like (get object field-name)
https://github.com/walmartlabs/lacinia/blob/master/src/com/walmartlabs/lacinia/schema.clj#L1096
(defn keyword-field-resolver
[field-name]
(fn [_ _ obj] (get obj (->kebab-case field-name)))
)
(lacinia/compile schema {:default-field-resolver keyword-field-resolver})
@hmaurer Thanks a lot for those tips. Will think about such a way.
@hmaurer: how are you handling namespaces? Do you just name your fields like myapp_somenamespace_fieldname
and map them to myapp.somenamespace/fieldname
by convention?
and I have a function which, given input data and an input graphql type, re-constructs the namespaced-qualified map
and do you do the same with enums etc?
@hmaurer: sounds like you’re taking a similar approach to graphql as we are, i.e. dynamically generating schemas based on existing data
the other approach to namespacing that occured to me would be to nest your stuff inside a field e.g.
{
my_namespace {
foo
bar
baz
}
}
/users/hlship/dev