Fork me on GitHub
#pathom
<
2020-01-24
>
λustin f(n)17:01:54

Question about data modeling with resolvers: I already know how to use the vector-collection format (or whatever it is called) for output.

::pc/output  [{::s-coach/sessions
               [::sf/id
                ::user/email
                ::s-coach/first-name
                ::s-coach/last-name
                ::user/visitor-id
                ::story/name
                ::session/id
                ::session/start-time
                ::session/location-url]}]
However, now I am building a resolver to enclose a more maplike existing data structure. e.g.
{:key1 {:a 1
        :b "foo"}
 :key2 {:a 3
        :b "bar"}
 :key3 {:a 14
        :b "baz"}}
Is there a way to simply specify the output of this? Or do I need to restructure things to:
[{:id :key1
  :a 1
  :b "foo"}
 {:id :key2
  :a 3
  :b "bar"}
 {:id :key3 
  :a 14
  :b "baz"}]
And use
::pc/output [{:my-collection
              [:id :a :b]}]
?

wilkerlucio18:01:07

@austin021 hello, there is a feature to help with that coming on the next version, the ::pc/output will remain the same (as you did), but you have to signal to Pathom that this map should be threated like a "map of maps", the distinction is nescessary because otherwise pathom would try to run the sub-query against the map directly (what you see happening now). this is an example of how to do use this:

(pc/defresolver some-resolver [env {:keys []}]
  {::pc/output  [{::s-coach/sessions
                  [::sf/id
                   ::user/email
                   ::s-coach/first-name
                   ::s-coach/last-name
                   ::user/visitor-id
                   ::story/name
                   ::session/id
                   ::session/start-time
                   ::session/location-url]}]}
  {::s-coach/sessions
   ; add this metadata to the map, to signal map of maps to Pathom
   ^::p/map-of-maps
   {:key1 {:a 1
           :b "foo"}
    :key2 {:a 3
           :b "bar"}
    :key3 {:a 14
           :b "baz"}}})

wilkerlucio18:01:25

you can try that using pathom 2.3.0-SNAPSHOT, but this version may be unstable (not production tested, and a lot of changes there), use at your own risk

👍 4