om

Please ask the channel first, not @dnolen directly!
souenzzo 2018-02-14T17:45:19.000748Z

Anyone using om-next + graphql backend?

2018-02-14T17:47:21.000195Z

I've played with it: https://github.com/danielstockton/omql

pithyless 2018-02-14T17:51:13.000616Z

Maybe also check out https://github.com/wilkerlucio/pathom

2018-02-14T17:54:34.000763Z

Pathom looks really interesting, thanks.

souenzzo 2018-02-14T18:24:59.000483Z

And how about normalization? There is no problems around it? I'm prototyping with reagent + lacinia, and normalization is my main problem

2018-02-14T18:30:22.000428Z

Pathom looks interesting to me, because perhaps it could allow querying with om-next but also exposing the same backend API/parser to graphql queries

2018-02-14T18:30:38.000067Z

I have no desire to use graphql really, but i am interested in offering it to other API users who might prefer it

2018-02-14T18:31:14.000478Z

I'm looking for a write-once backend solution, that can expose both om and graphql APIs

souenzzo 2018-02-14T18:32:07.000785Z

Any good reason to support om and graphql api? There is something possible on om that isn't possible on graphql?

2018-02-14T18:32:10.000317Z

I played with omql because i also have a case where the backend isn't written in Clojure. I tend to have to fix normalization issues myself in merge anyway.

2018-02-14T18:32:49.000322Z

I'm no expert in graphql tbh. Doesn't it force you to separate reads and mutations, whereas om can express them in a single query?

2018-02-14T18:33:27.000395Z

I also just prefer om syntax, but thats subjective

2018-02-14T18:33:54.000587Z

Actually no, one benefit is that it's data (instead of strings like graphql). Dealing with strings is much more painful.

2018-02-14T18:34:04.000124Z

Also, transit?

2018-02-14T18:34:49.000727Z

From clojurescript, it's clearly preferable to use cljs data structures

wilkerlucio 2018-02-14T19:39:50.000773Z

@danielstockton pathom integrations with graphql are mostly in the direction of consumption (consuming graphql from clojure, and integrate on the om style), there are docs in progress about using graphql endpoints strait from the client (the examples will be using custom fulcro networks, but shouldn't be hard to port into a send function in om.next). that said, consuming gql is much easier than exposing it. the tricky is that the om model is flexible and schema free, so we have no restrictions about combinations of attributes, that's not true for graphql, trying to expose a graphql from a pathom implementation means having to figure out how to define the entities and interfaces, I see no easy way to do it automatically, a feasible way could be manually defining some external gql schema that uses the underling implementation, I would be interested in help with advice if you wanna take the adventure

wilkerlucio 2018-02-14T19:48:36.000121Z

@souenzzo I think the parser model we do in om is more flexible than the gql, exactly because we are not forced to have rigid schemas, it's a different way of thinking, it's like Prismatic Schema vs Spec. in Schema you are encouraged to think on entities first, every attribute lives on an entity, the entities are the primary building block. on spec the primary building blocks are the attributes, you start with then and later combine as you find suitable. IMO the later evolves easier, allowing you to do as many combinations as you wish, it's a different way o thinking really

souenzzo 2018-02-14T19:56:01.000261Z

@wilkerlucio there is something like Voyager to om?

wilkerlucio 2018-02-14T19:56:21.000416Z

I don't know Voyager, what is it?

wilkerlucio 2018-02-14T19:59:29.000049Z

@souenzzo just found it, not yet (that I know), but it's part of OgE (https://github.com/wilkerlucio/oge) roadmap to have something like that 🙂

❤️ 4
souenzzo 2018-02-14T22:14:54.000337Z

I'm trying, one more time, to use om-next But I always stuck at this point ("recursive" parser): https://gist.github.com/souenzzo/6db3917911884d44e7da768958c7f242

wilkerlucio 2018-02-14T22:15:26.000128Z

@souenzzo had you tried fulcro?

souenzzo 2018-02-14T22:17:12.000312Z

@wilkerlucio yep, I see (almost) all the videos, but I really want to understand om-next before start to use fulco stuff

wilkerlucio 2018-02-14T22:18:15.000037Z

well, learning how to write parsers is not really necessary to use a lot of fulcro/om.next, but it can surely hold you up if you trying to learn the deal 🙂

wilkerlucio 2018-02-14T22:18:25.000497Z

let me take a look on your example

wilkerlucio 2018-02-14T22:25:15.000520Z

@souenzzo interesting, the third argument for the parser, the target, I didn't knew it existed, it's the first time I see it

wilkerlucio 2018-02-14T22:25:34.000506Z

and there is a chance that nobody was using it, really, might had never worked, but I'm just guessing

wilkerlucio 2018-02-14T22:26:01.000364Z

I did a few changes to your example, sending the target manually (I used a namespaced version, seems like the plain :target is special somehow), and it works:

wilkerlucio 2018-02-14T22:26:04.000265Z

(ns com.wsscode.pathom.tmp
  (:require [om.next :as om]
            [clojure.test :refer :all]))

(defmulti om-read om/dispatch)
(defmethod om-read :default
  [_ k _]
  (throw (ex-info (str "read: " k) {:k k})))

(defmethod om-read :db/id
  [{::keys [target]} k _]
  {:value (get target k)})

(defmethod om-read :user/name
  [{::keys [target]} k _]
  {:value (get target k)})

(defmethod om-read :user/id
  [{::keys [target]} k _]
  {:value (get target k)})

(defmethod om-read :me
  [{:keys [state query parser] :as env} k v]
  ;; Why parser returns '[]'
  {:value (parser (assoc env ::target (get @state k)) query)})

(def parser
  (om/parser
    {:read om-read}))

(deftest recursive-read
  (let [state (atom {:me {:db/id 1 :user/name "abc" :user/id "1"}})
        env {:state state}]
    (is
      (= (parser env [{:me [:db/id :user/name]}])
         {:me {:db/id 1 :user/name "abc"}}))))

wilkerlucio 2018-02-14T22:26:20.000223Z

instead of sending as the third argument, I assoc on the env during the recursive call

wilkerlucio 2018-02-14T22:26:53.000609Z

that's how pathom does it, but it's called ::p/entity there (by default, it's configurable)

👍 1
souenzzo 2018-02-14T22:29:04.000120Z

So, this is the "standard" method to do a recursive parser?

wilkerlucio 2018-02-14T22:29:54.000241Z

I can't say it's standard, but that's how I've been doing it since I started, not sure if other people were aware of the :target thing

👍 1
wilkerlucio 2018-02-14T22:30:55.000382Z

in the past I used to give specific names for the entity (like :user, :item, etc...), but after a while I realised giving a standard name (`::p/entity`) makes generalisations easier

wilkerlucio 2018-02-14T22:32:05.000104Z

if you like to read more about it, I wrote an article about those parsing details: https://medium.com/@wilkerlucio/implementing-custom-om-next-parsers-f20ca6db1664

wilkerlucio 2018-02-14T22:34:13.000321Z

but I can't express in text how much I recommend you try fulcro, it's not just about the local parser, it takes so much overhead out of your face when compared to stock om, and you still need all those parsing skills to write the backend, the front-end works pretty well with just db->tree

👍 1