om

Please ask the channel first, not @dnolen directly!
2017-05-23T00:03:01.249176Z

@danieleneal i was looking into the redux extension and it should be possible to integrate cljs data into that

danielneal 2017-05-23T08:05:57.197835Z

dvingo: ooh interesting

2017-05-23T00:03:55.257615Z

apparently already some work on it too: http://gitlab.xet.ru:9999/publicpr/clojurescript-redux/tree/master#dev-setup

2017-05-23T00:21:20.410745Z

@sova did you figure out your problem?

2017-05-23T00:24:05.433995Z

(def sample-data
  {
   :blog/posts [[:blog/by-id 1]]
   :blog/by-id
   {1 {:blog/id       1
       :blog/title    "Blog post one"
       :blog/comments [[:comment/by-id 1] [:comment/by-id 2]]}}
   :comment/by-id
   {1 {:comment/id       1
       :comment/text     "Hello comment one"
       :comment/comments [[:comment/by-id 4] [:comment/by-id 3]]}
    2 {:comment/id       2
       :comment/text     "comment two"}
    3 {:comment/id       3
       :comment/text     "Hello comment threeee"}
    4 {:comment/id       4
       :comment/text     "Hello comment four"}}
   })

2017-05-23T00:25:50.448470Z

something like that will work, then you can make recursive queries for comments. to insert a new comment you can insert into the comment/by-id table and the ref to the new comment under an existing comment

1
😄 1
danielneal 2017-05-23T08:59:40.007960Z

[newbie question] If you want to compose om.next views at the root, but there is no corresponding server side/data query, what do you do?

danielneal 2017-05-23T09:01:14.034016Z

I was thinking I should do a union query, but because there is no server union query for the views, it doesn't work

2017-05-23T12:20:52.783916Z

I started experimenting with translating Om queries into 'equivalent' GraphQL queries, if anyone is interested: https://github.com/danielstockton/omql/blob/master/src/omql/core.cljc

👍 3
2017-05-23T12:21:13.788848Z

Relay style pagination, very early stages.

2017-05-23T12:24:23.836506Z

I guess lots of people will want to maintain a GraphQL API (popularity + familiarity) and I want to allow a smoothish integration with om on the client side, instead of forcing people to maintain two APIs.

2017-05-24T10:37:45.367895Z

You might be interested in these read helpers:

(defmulti read om/dispatch)
(defmulti mutate om/dispatch)

(defn read-join [{:keys [parser query target ast] :as env}]
  (let [ret (parser env query target)]
    (if target
      (when (seq ret)
        {target (assoc ast :query ret)})
      {:value ret})))

(defn read-union [{:keys [query] :as env} union-key]
  (let [union-query (cond-> query (map? query) (get union-key))]
    (read-join (assoc env :query union-query))))

(defmethod read :default
  [{:keys [ast state] :as env} key params]
  (let [st @state
        ns (namespace key)]
    (condp = ns
      "join" (read-join env)
      {:value (get st key)})))

2017-05-24T10:39:54.394348Z

It allows queries like [{:join/child (om/get-query Child)}] and you can write the Child query as though it were part of the root query.

2017-05-24T10:41:14.410660Z

It calls the parser recursively, there is some more explanation here: https://awkay.github.io/om-tutorial/#!/om_tutorial.E_State_Reads_and_Parsing

stijn 2017-05-23T12:29:33.917189Z

that's very useful

stijn 2017-05-23T12:30:54.939337Z

my idea to solving this problem had been from the server side, generate both APIs from a common schema

stijn 2017-05-23T12:32:10.959669Z

but that's quite a lot more work I think

2017-05-23T12:32:44.968513Z

I think that approach would be better but yeah... There are already GraphQL frameworks in all the major languages, my idea was to hook into those with minimal effort.

stijn 2017-05-23T12:33:24.979095Z

true

danielneal 2017-05-23T13:51:25.550495Z

danielstockton: mmm cool! Yeah this is what I'd like to do to too - use om next on the client, but graphql on the server because of popularity and familiarity (and tooling!). My attempt is at https://gist.github.com/danielneal/ae3a1b6ddfc52393dd18c859464a6ec3

danielneal 2017-05-23T13:51:38.555976Z

I'm still getting my head round om next on the client though

2017-05-23T13:56:55.685139Z

Oh nice, I like how you avoided string concatenation until the very end. I also decided to re-implement my own query->ast in spec unnecessarily, I just felt like playing with spec a bit. Looks like you got further than me, did you hit any challenges that didn't translate very well?

danielneal 2017-05-23T14:16:43.178675Z

haha not sure if I got any further, think we just focused on on different bits - I don't have any stuff on fragments or pagination yet... but I have a feeling that the approach should be possible - so long as you stick to a subset of the compatible bits of om.next/graphql

2017-05-23T14:43:09.854817Z

Yeah, it's about finding that subset.

danielneal 2017-05-23T14:43:27.862956Z

and hoping that it's enough to work with 🙏

danielneal 2017-05-23T14:43:52.873808Z

have you used om.next much?

danielneal 2017-05-23T14:44:08.880236Z

I'm just trying it out to see if it will be a better fit than reframe

danielneal 2017-05-23T14:44:18.884899Z

we've got a graphql server

2017-05-23T14:55:07.170410Z

Using it more and more but I don't have experience with reframe.

2017-05-23T14:58:06.252668Z

I just felt like I got what om was trying to do, straight away. In general I've found it pretty straightforward. I've written a custom parser on the backend with python/transit but I'm looking to see if I can transition to GraphQL.

2017-05-23T14:58:19.258567Z

It's a legacy application, if I could start again I'd pick Clojure on the backend too.

danielneal 2017-05-23T15:07:23.506310Z

nice! I feel like I get om on a conceptual level but still got some questions when I try to implement it

danielneal 2017-05-23T15:09:03.548963Z

at the moment trying to figure out how to have a ui only way of to compose components together that doesn't affect the server

danielneal 2017-05-23T15:09:46.567885Z

basically I was building Search directly in the AppRoot component, but then decided I wanted to name the component Search and reference it from AppRoot

danielneal 2017-05-23T15:09:53.570689Z

and that is proving harder than I thought

danielneal 2017-05-23T15:10:05.575915Z

think I may have missed a trick

peeja 2017-05-23T16:32:25.650582Z

@anmonteiro It looks like Compassus's root component's query doesn't pick up new queries from the route components that have been hot-loaded (using ^:once). Which makes sense, given how it works. Do you know a way to get it to do that?

peeja 2017-05-23T16:32:55.661837Z

Specifically, I'm trying to get changes to queries to take effect when Figwheel loads changes

anmonteiro 2017-05-23T16:47:02.974543Z

@peeja oh hrm makes sense

peeja 2017-05-23T16:47:24.983109Z

I'm not sure what would be best to trigger rebuilding the query…

anmonteiro 2017-05-23T16:47:40.989020Z

I would have to think

anmonteiro 2017-05-23T16:47:51.993108Z

patching the root class seems ugly

peeja 2017-05-23T16:48:12.000793Z

Does it? That's what Om itself does.

anmonteiro 2017-05-23T16:49:21.026386Z

I suppose you could patch the root class on figwheel’s reload hook

anmonteiro 2017-05-23T16:49:26.028578Z

not sure if that would be enough

peeja 2017-05-23T18:19:01.083117Z

@anmonteiro "you could" meaning I can do that today from the reload hook, or meaning Compassus could be changed to allow that?

anmonteiro 2017-05-23T18:19:26.092956Z

meaning Compassus shouldn’t need to be changed, and you could do it today

peeja 2017-05-23T18:19:39.097806Z

Oh, sweet. How can I patch the root class?

anmonteiro 2017-05-23T18:19:40.097914Z

let me know if you think otherwise!

peeja 2017-05-23T18:19:51.102037Z

Isn't that hard to get at?

anmonteiro 2017-05-23T18:20:04.107148Z

you have the root class in the compassus application

anmonteiro 2017-05-23T18:20:15.111271Z

(compassus.core/root-class app)

peeja 2017-05-23T18:20:27.115573Z

I guess I really mean: how would I recalculate what I need to patch it?

peeja 2017-05-23T18:20:37.119345Z

Doesn't that only happen when a new one is built?

anmonteiro 2017-05-23T18:20:46.122985Z

hrm

anmonteiro 2017-05-23T18:21:07.130572Z

I suppose we could create a compassus.dev namespace or something that you require with :preloads

anmonteiro 2017-05-23T18:21:18.134605Z

where we’d do that for you

anmonteiro 2017-05-23T18:21:21.135807Z

feel free to open an issue!

anmonteiro 2017-05-23T18:21:34.141031Z

does that sound good?

peeja 2017-05-23T18:21:58.150143Z

Oh, could I make a new one and swap it out of the Application's :root-class?

peeja 2017-05-23T18:22:22.159286Z

Oh, I guess Om still has the old one

anmonteiro 2017-05-23T18:22:35.164490Z

I think the problem is that React reuses instances

peeja 2017-05-23T18:22:44.167651Z

Ah, yeah, that makes sense

anmonteiro 2017-05-23T18:22:50.170014Z

I would have to think more about it

peeja 2017-05-23T18:22:50.170391Z

Alright, I'll open an issue

peeja 2017-05-23T18:22:52.171278Z

Thanks!

anmonteiro 2017-05-23T18:22:54.171985Z

great

anmonteiro 2017-05-23T18:23:03.175271Z

let me know if you have any ideas too

👍 1