pathom

pieterbreed 2025-02-05T12:56:40.252999Z

Hi everyone, I think I misunderstand something about how the attributes are resolved. I'm getting Can't reach attribute <...> for an attribute that seems to exist in the entity:

pieterbreed 2025-02-05T12:58:16.124969Z

I have these resolvers:

(pco/defresolver auth->auth-details
  [{::keys [authenticated]}]
  {:users/sub        (-> authenticated :claims :sub)
   :users.auth/token (:token authenticated)})

(def sub->fleets2
  {"test-sub" [{:model/fleet-name "Foo"}]
   })

(pco/defresolver user-sub->fleets
  [{:users/keys [sub]}]
  {::pco/output [{:user/available-fleets [:model/fleet-name]}]}
  {:user/available-fleets
   (sub->fleets2 sub [])})

(defn vehicles-query
  [auth-token fleet-name]
  {:model/vehicles [{:model.vehicle/id 1
                     :model.vehicle/data {:a 1}}
                    {:model.vehicle/id 2
                     :model.vehicle/data {:a 2}}]})

(pco/defresolver fleet-name->vehicles
  [{:as                 env
    {:keys [telemetry]} ::cfg}
   {fleet-name :model/fleet-name
    auth-token :users.auth/token}]
  {::pco/input  [:model/fleet-name
                 :users.auth/token]
   ::pco/output [{:model/vehicles [:model.vehicle/id
                                   :model.vehicle/data]}]}

  {:model/vehicles
   (vehicles-query auth-token fleet-name)})
and then these 3 queries. The first 2 work, the last one gives me the error:
(p.eql/process (make-env {})
                 {::authenticated {:claims {:sub "test-sub"} :token "this-is-a-token"}}
                 [:users/sub
                  :users.auth/token])
  ;; {:users/sub "test-sub", :users.auth/token "this-is-a-token"}
;;;;;;;;;;;;;;;
  (p.eql/process (make-env {})
                 {::authenticated {:claims {:sub "test-sub"} :token "this-is-a-token"}}
                 [{:user/available-fleets [:model/fleet-name]}])
  ;; #:user{:available-fleets [#:model{:fleet-name "Foo"}]}
;;;;;;;;;;;;;;;
  (p.eql/process (make-env {})
                 {::authenticated {:claims {:sub "test-sub"} :token "this-is-a-token"}}
                 [{:user/available-fleets [{:model/vehicles [:model.vehicle/id]}]}])
  ;; error
  ;;    Pathom can't find a path for the following elements in the query at path [:user/available-fleets 0]: - Attribute
  ;;    :model/vehicles inputs can't be met, details: - Can't reach attribute :users.auth/token

pieterbreed 2025-02-05T12:58:43.832739Z

The ex-info provides the following:

{:com.wsscode.pathom3.connect.planner/graph-fn #function[com.wsscode.pathom3.connect.planner/verify-plan!*/fn--22117],
    :com.wsscode.pathom3.connect.planner/unreachable-paths {:model/vehicles {}},
    :com.wsscode.pathom3.connect.planner/unreachable-details
    {:model/vehicles
     {:com.wsscode.pathom3.connect.planner/unreachable-cause
      :com.wsscode.pathom3.connect.planner/unreachable-cause-missing-inputs,
      :com.wsscode.pathom3.connect.planner/unreachable-missing-inputs
      {{:users.auth/token {}} #{gometro.apigw.resolver/fleet-name->vehicles}}}},
    :com.wsscode.pathom3.path/path [:user/available-fleets 0],
    :com.wsscode.pathom3.error/phase :com.wsscode.pathom3.connect.planner/plan,
    :com.wsscode.pathom3.error/cause :com.wsscode.pathom3.error/attribute-unreachable}

pieterbreed 2025-02-05T13:01:22.504079Z

It looks to me like the :users.auth/token attribute is reachable (on the top level, at least). Does this mean it cannot be used once you start joining?

wilkerlucio 2025-02-05T16:36:25.013149Z

hello @pieterbreed, the reason you can't get the info is because the ::authenticated key is only available in the root entity. inputs always pull from entity data, and entity is never automatically forward to child entities

wilkerlucio 2025-02-05T16:38:18.846099Z

so you have two main options: 1 - you can forward down the ::authenticated when generating new entities, but that's cumbersome for this case I think 2 - make ::authenticated part of env instead of entity, and them from the resolver pull it from the env, this way you have that same ::authenticated info available, no matter what entity you are looking at (the tradeoff is that its harder to change that if you want to have different ::authenticated values for different entities during the processing, but this is usually not an issue when dealing with authentication

pieterbreed 2025-02-05T16:41:34.375109Z

Thank you @wilkerlucio, I will change it like you suggest