Fork me on GitHub
#pathom
<
2022-08-22
>
Ernesto Garcia12:08:10

Sorry if this is a basic question, but I can't figure out how to return an error response through an EQL endpoint for queries that refer to an entity id that doesn't exist. If I query for

[{[:person/id "non-existing-id"]
  [:person/id :person/name]}]
I will obtain
{[:person/id "non-existing-id"]
 {:person/id "non-existing-id"}}
as my resolver for person/name is returning nil. My Fulcro client application doesn't obtain the value for the person-name attribute, but it is believing that there is a person with id "non-existing-id".

wilkerlucio19:08:54

hello @U015KAUQRFE, welcome 🙂 not at all, its a difference in mindset around modeling information. in a standard entity based its common have this notion of if an entity exists or not (like: is there a row for it in the database?), but in Pathom, using attribute modeling, the question becomes a bit more complex, because there is no notion of the entity as a single thing, instead its about attribute reachability

wilkerlucio19:08:55

in this world, what you can do, is define some attribute to tell you specifically that (like: :person/exists-in-db?), make an attribute to do that check (directly going to the db, or depending on something else that you always expect present for a user stored in db), makes sense?

Ernesto Garcia08:08:36

That doesn't solve the issue, because that would involve client code making sure that every request contains the additional attribute, and I guess would need to override Fulcro defaults in order to introduce code checks when receiving the response. For now, I have removed the error-handler-plugin that the Fulcro tutorial adds to the Pathom config, and I'm throwing an exception from the resolver.

Otto Nascarella16:08:08

hi yall let’s say I have a resolver that depends on 2 inputs a and b and returns c (let’s say it’s the sum of those) how can I write an EQL query to express those two values given that ident is [:a 1] or [:b 2] Cannot seem to find anything on docs… cheers

sheluchin17:08:43

Are a and b global resolvers that resolve without input? If so, write a resolver that takes both of those as inputs and outputs c, which is their sum, and then just request [:c]:

::pco/input [:a :b]
::pco/output [:c]
Or perhaps you're thinking about it more like parameters? In that case you pass them in using EQL params ['(:c {:a 1 :b 2})]. If :a and :b aren't global, meaning that they require some input to retrieve, you have to provide as much data as is necessary in order get them, and then you can get c. Remember that the planner has a single entry point, but attributes which can be resolved without inputs an be retrieved at any place in the graph. Does that help?

Otto Nascarella18:08:37

[{[:a 1] [:c]}] <- how do I get the :b in there in order to get :c 2

sheluchin18:08:22

(pco/defresolver b
  []
  {:b 2})

(pco/defresolver c
  [{:keys [a b]}]
  {:c (+ a b)})

(p.eql/process (pci/register [ b c])
  [{[:a 1] [:c]}])
; => {[:a 1] {:c 3}}

sheluchin18:08:26

When using EQL idents to provide data you are providing a single attribute to start from.

wilkerlucio19:08:27

in Pathom 3, the best way is to send an entity data, so you can query strait from the root, like: (p.eql/process env {:a 1 :b 2} [:c])

wilkerlucio19:08:02

when using the boundary interface, you can also make a request like: (request {:pathom/entity {:a 1 :b 2} :pathom/tx [:c]})

wilkerlucio19:08:24

but if you need to send via query (maybe to have multiple things) you can do: [{(:>/foo {:a 1 :b 2}) [:c]}], but I might break this interface because I found some usages that make this "always use placeholder params as entity data" is problematic for some use cases