Fork me on GitHub
#pathom
<
2020-02-21
>
rickmoynihan12:02:49

noob question: Is there a pathom ring handler and corresponding cljs client for making pathom queries anywhere? Or do people hand roll this each time; or am I misunderstanding something?

wilkerlucio12:02:47

@austin021 I'm not sure if I understand, a resolver should only be called if the inputs can be satisfied, can you send an example that demonstrates what you are saying?

wilkerlucio13:02:34

@rickmoynihan hello Rick, not sure what you mean, when I'm doing a server I usually roll an endpoint and put the parser to work on it, many times I juts use it in CLJS directly, so there is not need for server setup in these cases, what kind of setup are you looking into doing?

rickmoynihan13:02:08

@wilkerlucio I’m more at the pondering stage right now, than actively looking at implementing anything — but was essentially thinking about having a single endpoint/route to serve EQL requests from cljs front end components

Brian15:02:13

@rickmoynihan maybe this could be helpful to you to see. This is what I do. I am sending my data over in transit form (although it isn't necessary I could just send the raw query. Here is a link to it though https://github.com/cognitect/transit-format). This is in hooked into an Ion since I am running it in the cloud and my query is placed in the body of the request at the :input

(defn untransitize [query]
  (transit/read
    (transit/reader
      (ByteArrayInputStream. (.getBytes query))
      :json)))

(defn eql-query
  "run eql query into pathom and return the transitized result"
  [{:keys [context input]}]
  (let [query (untransitize input)
        response (<!! (parser {} query))
        out (ByteArrayOutputStream. 4096)]
    (transit/write (transit/writer out :json) response)
    (str out)))

Brian15:02:12

I've then listed the eql-query function in my ion config like so

:lambdas  {:eql-query
            {:fn          my-namespace/eql-query
             :description "run eql query into pathom and return the transitized result"}}
and now I have an endpoint I can just throw eql queries at. In my case they are using transit, but I could very easily just use the raw query. Does this help?

rickmoynihan15:02:22

@brian.rogers: thanks, that’s exactly the kind of thing I was expecting to do

roklenarcic15:02:27

Hm, how do I translate this example query in GraphQL into pathom eql query?

{
  countries(where: {name: {eq: "United Kingdom"}}) {
    cities {
      name
      population
    }
  }
}

roklenarcic15:02:50

Currently I have

::pcg/prefix    "eb"
   ::pcg/ident-map {"countries" {"where" :eb.Country/where}}
and then I tried query:
(parser {} [[:eb.Country/where {:name {:eq "United Kingdom"}}]])

roklenarcic15:02:28

I don’t think I understand this ident map correctly I guess

Brian16:02:58

@roklenarcic I think you are blending edn data and eql queries without meaning to. Or perhaps blending datomic pull syntax and eql queries. That looks to me like you're putting pull syntax into an eql query

Brian16:02:41

I'm imagining a resolver where the input would be a country name and the output would be :population in which case your parser and query call would look something like this:

(parser {} [{[:name "United Kingdom"][:population]}])
here you're saying in the first square brackets that you have an input of :name and you want pathom to give you a :population . This could be used with a resolver like this
(pc/defresolver population-resolver [_ {:keys [name]}]
  {::pc/input #{:name}
   ::pc/output [:population]
   {:population (get-population-function name)}})
and you'd need to write the get-population-function yourself and query your database, likely with pull syntax

Brian16:02:44

Does that help?

myguidingstar16:02:49

from the query I guess @roklenarcic is trying to use pathom to connect to a hasura graphql server?

roklenarcic16:02:42

I am not mixing. But the where parameter is complex and judging by pathom docs i need to put as the ident

roklenarcic16:02:50

Sorry on phone now

Brian16:02:40

Ah in that case I cannot help. Good luck!

codonnell18:02:48

You need to parameterize your query; it should look something like this:

[{'(:my.prefix/countries {:where {:name {:eq "United Kingdom"}}}) [{:my.prefix/cities [:my.prefix/name :my.prefix/population]}]}]

Brian18:02:17

Hey y'all I've got a question regarding using transit-js to turn some js into a pathom query. I think this is more transit-based but perhaps someone can identify my issue. My issue has to do with the ' character and () characters in the query:

[{'([:num1 1] {:pathom/context {:num2 1 :num3 1}})
                                         [:sum]}]
because I am using multiple inputs, I'm using a query like this which I've only gotten to work with that ' character and the following ( character which encompasses most of the rest of the query. On the javascript side I'm having a lot of problem turning that into transit because javascript expects different things from the parentheses characters.
transit.map([
      [(transit.keyword("num1"), 1], {
        // pathom/context part should go here, but the parenthesis screws it all up
      }),
      [transit.keyword("ip-blacklisted?")]
    ])
So 1) does anyone know how I can recreate that query using transit of any language implementation (preferably js of course)? Or 2) does anyone know how I can rewrite the query so that it's less convoluted and therefore easier for me to convert with transit?

myguidingstar19:02:13

@brian.rogers you only need ' in clojure code, not edn strings

myguidingstar19:02:43

And the () characters denote a list. Use transit.list to produce one