Fork me on GitHub
#pathom
<
2022-03-22
>
sheluchin00:03:42

I'm trying to run this GitHuh GraphQL query with Pathom but it's not working as I expect.

{
  search(query: "sheluchin", type: USER, first: 1) {
    edges {
      node {
        ... on User {
          login
        }
      }
    }
  }
}
In Pathom:
[{(:github.Query/search {:query "sheluchin" :type USER :first 1})
  [:github.SearchResultItemConnection/userCount
   {:github.SearchResultItemConnection/edges
    [{:github.SearchResultItemEdge/node
      [:github.User/login]}]}]}]
Result:
cause "Pathom can't find a path for the following elements in the query: [:github.User/login] at path [:github.Query/search :github.SearchResultItemConnection/edges :github.SearchResultItemEdge/node]"
Might this be a bug?

👀 1
wilkerlucio14:03:59

it looks similar to https://github.com/wilkerlucio/pathom3-graphql/issues/15#issuecomment-1069050373 to me, I plan to do the debugging on this by Thursday this week, hopefully its same thing and we can get both fixes together 🤞

sheluchin14:03:26

Ok, @U066U8JQJ. Thanks for checking it out. Hopefully it is related.

Mark Wardle11:03:31

Hi all. I now have 153 resolvers and counting, some in my main server product, and many others as separate resolvers in specific libraries. I use integrant to configure much of the environment, so that resolvers have access to different connections to databases, key value stores etc.. But I don't have an easy way of registering resolvers as part of that process. I currently add the resolvers in my integrant init method, storing them in an atom, and finally making use of the collection when the pathom environment is created. e.g. see https://github.com/wardle/pc4/blob/49c3b50667c92d0c35e244de8ba8566888786fd4/pc4-server/src/com/eldrix/pc4/server/system.clj#L103. This works well at small scale, but I'd like to move to being able to keep resolvers and the service init/halt multimethods in their own namespaces. Here is my example integrant configuration file: https://github.com/wardle/pc4/blob/main/pc4-server/resources/config.edn Has anyone got any suggestions on how to use pathom with integrant to register the appropriate resolvers if and when a specific service is configured? Thank you, Mark

wilkerlucio14:03:12

hello Mark, I was playing with integrant setup, I have a half-baked Pathom 3 integrant library, but its development its currently on pause

wilkerlucio14:03:17

in my setup, the config looks like this:

wilkerlucio14:03:19

{:com.wsscode.pathom3.integrant/pathom3
 {:com.wsscode.pathom3.integrant/registry
  [#pathom3/ops some.org.sample-resolvers/registry
   #pathom3/ops "some\\.org\\..+"]

  :com.wsscode.pathom3.integrant/env
  {}

  :com.wsscode.pathom3.integrant/pathom-viz-enabled?
  false

  :com.wsscode.pathom3.integrant/pathom-viz-name
  "demo"}}

wilkerlucio14:03:39

so you can reference resolvers (by var or regex namespace match) to be included

wilkerlucio14:03:49

this is the current source, not much but may help you as a starting point:

wilkerlucio14:03:53

(ns com.wsscode.pathom3.integrant
  (:require [integrant.core :as ig]
            [clojure.tools.namespace.dir]
            [com.wsscode.pathom3.connect.operation :as pco]
            [clojure.spec.alpha :as s]
            [some.org.sample-resolvers]
            [ :as io]
            [com.wsscode.pathom3.connect.indexes :as pci])
  (:import (java.util.regex Pattern)))

(s/def ::registry ::pci/operations)

(defn re-find-operations [re]
  (into []
        (comp
          (filter #(re-find re (str %)))
          (map ns-publics)
          (mapcat vals)
          (map var-get)
          (filter pco/operation?))
        (all-ns)))

(defn find-operations [x]
  (cond
    (qualified-symbol? x)
    (var-get (requiring-resolve x))

    (string? x)
    (re-find-operations (re-pattern x))))

(def readers
  {'pathom3/ops find-operations})

(defmethod ig/init-key ::pathom3 [_ {::keys [registry] :as p}]
  (let [env {}]
    (pci/register env registry)))

(comment
  (var-get (requiring-resolve 'some.org.sample-resolvers/registry))

  (ig/read-string
    {:readers readers}
    (slurp (io/resource "sample_app/config.edn")))

  (let [publics (ns-publics ns)])
  (->> (find-ns 'some.org.sample-resolvers)
       (ns-publics)
       vals
       (mapv #(var-get %)))
  (find-operations #"^some\.org\..+-resolvers$")
  (clojure.tools.namespace.dir/dirs-on-classpath))

wilkerlucio14:03:02

for the symbol version this code can load the namespace dinamically, but note that for the namespace regex version you still responsible for loading the possible namespaces yourself, then the code can match from those loaded namespaces

Mark Wardle14:03:47

Oooo that's clever. What a nice idea. I haven't used clojure's ability to find public symbols in namespaces before, but that would work really well. I shall have a good play with it! Thank you. Hope you are keeping well. Mark

wilkerlucio15:03:00

glad you liked it 🙂 IMO the option using explicit vars (pointing to registry entries) is preferred over the regex, being explicity makes easier to track and understand whats going on