Fork me on GitHub
#pathom
<
2022-05-05
>
Ryan Domigan12:05:47

Hi, I'm trying to model a graph using pathom3, and have a transaction which creates multiple nodes and then adds a reference from one to another, something like [(add-node {:id "a"}) (add-node {:id "b"}) (setup-ref {:from "a" :to "b"})]. Is this expected to work? I'm trying to debug and it seems like add-node is running for :id "b" but not "a"

wilkerlucio13:05:07

hello Ryan, when you have to coordinate things, its better to pack them in a single operation so you have more control, so instead of 3 mutations, you can design it to be one thing, something like:

[(include-nodes {:nodes [{:id "a"}
                         {:id "b"}]
                 :rels [["a" "b"]]})]

wilkerlucio14:05:47

although, in any case it should be running all the mutations, let me see if there is an issue there

wilkerlucio14:05:24

yeah, this demo shows a bug, multiple mutations are converging to the same params

wilkerlucio14:05:35

I see the problem, will have a fix for it soon

Ryan Domigan14:05:35

Thanks for letting me know, I'll keep an eye on the issue. I'm populating my DB for testing, and for now I think running separate queries models the expected interaction just as well

wilkerlucio14:05:57

thanks from bringing it up, nasty issue that got all this time without being noticed

wilkerlucio14:05:09

but, there is a more fundamental problem to fix in this case, there is what the response will look like? since the key of the mutation is what shows up, they will conflict, we need a way to rename some of them, otherwise we can only get the response for one of them

Ryan Domigan15:05:06

You can call the same mutation multiple times with the same arguments and get different results, so I think the result needs to encode position of the mutation in the input. Not sure if you were looking for feedback or just thinking out loud.

wilkerlucio15:05:34

sure, feedback is always welcome 🙂

wilkerlucio15:05:09

I'm thinking for the first fix, just fix the calling part, and let output a single result (prob the first, or the last one)

wilkerlucio15:05:15

this will fix the calls at least

wilkerlucio15:05:33

for the response, I'm thinkihng of using some special parameter to define the output name, this way the user can be explicit about it

donovanmcgillen20:05:23

Hi. Newbie question here, but what is the intended / recommended method for dealing with the situation when the thing a resolver is looking up doesn’t exist at all? E.g. imagine I have a resolver that takes :user/id as an input and outputs :user/id and :user/name. As far as I can tell, there is no difference in the output for a user that exists but doesn’t have a name to a user that doesn’t exist at all - in both cases you get back the :user/id supplied with an attribute missing error on :user/name, but really these are two different things and I want to know the difference. I notice throwing exceptions also adds the exception into each attribute (other than the :user/id) so I think I’m missing something in the philosophy of how to handle this by thinking in terms of attributes. I have been toying with using union queries so I can return either an error or an intended ‘thing’ from mutations / resolvers in general when there are errors - perhaps something like that the way to go?

wilkerlucio20:05:19

hello Donovan, funny that I was yesterday talking to co-workers just about that 🙂 the philosophical thing here is that each attribute is its own world, the concept of "user exists" or not is not really applicable, not in the same way we are used to when dealing primarily with entities. in Pathom the question is not about "does the user exists?", but "is this attribute available given the context?" this is general way of thinking, but with that in mind, if you have some way to tell if a user exists or not (by hitting a db, service, or whatever) and this information is relevant to your business, then the way in Pathom is to make an attribute that can tell you specifically that, for example an attribute :user/exists? (or even :user/stored-on-db?), and for the implementation of this you can make sure it deals with the difference between non-existent vs don't have a specific attribute, because then :user/exists? becomes something you have full control, and can make any heuristics you want makes sense?

wilkerlucio20:05:42

I dont recommend jumping to unions on this case, unions is more branching for different sub-queries (that may be very different) depending on something in the data

donovanmcgillen09:05:37

Hi Wilker, thanks for replying. That makes a lot of sense (and is quite obvious now you mention it!). It's not something I've found I typically need to worry about, I've just hit a case where I have a page of my app that takes the id of a specific thing in it's path (so user's can bookmark) and I want to handle people typing in non-existent ids / ids that don't belong to them as a specific case. One thing I have tried using a union query for (that I'm now wondering is not the way to go based on what you have said) is for getting errors out of mutations. For example, in fulcro I am sending a query along with a mutation (in the remote of the fulcro client side mutation I'm using something like (m/returning env SomeThing) ) and my mutation on success will return something like {:some-thing/id id} that will go on and be resolved, but in some cases I need to return an error from the mutation. What I have been looking at doing is wrapping SomeThing to make a union query to get either the mutation error map or query for SomeThing, but I'm now wondering if perhaps I should let the SomeThing query happen and use the attribute errors - that does mean I lose the reason the mutation failed, though. Another option is just to throw an exception from the mutation (and then I guess use a plugin to turn it into something that can be sent over the wire?). Sorry, not sure if this is a pathom or a fulcro question really!

wilkerlucio13:05:08

no worries, these modelling questions are common, since the modeling based on attributes is a new thing for most of the people that start using Pathom, so we are learning together on how to work this way 🙂

wilkerlucio13:05:09

I dont have an immediate answer for the mutation question now, its been a while since I dealt with that in Fulcro, what I remember for sure now is that I used the pessimist mutation in fulcro to handle cases like this, so the error flow is controlled more on the Fulcro end, but of course, Pathom needs to give you something to make that decision there

wilkerlucio13:05:17

I'll have a look into it and get back to you

donovanmcgillen18:05:21

Very much appreciated 👍