Fork me on GitHub

@wilkerlucio I just watched your Conj 2018 talk, ; very interesting 🙂 I have one question on your last demo involving the spacex and youtube APIs. You use “aliases” to make a connection between the launch video URL and a youtube URL, so that you can traverse the graph from the spacex data to the youtube data. What if, however, you had multiple youtube links? i.e. a launch video and a behind-the-scenes video. Is there a way to get to the youtube data for each of these?


hello, thanks for taking the time to watch it. For the to-many would be very similar, you still do the alias in the same way, when we think about list processing, its no different from one item processing, its just the same thing many times, so if spacex had some list of videos, we could make so in pathom its a sequence of maps, example:

 [{:spacex.launch/video-url "..."}
  {:spacex.launch/video-url "..."}
  {:spacex.launch/video-url "..."}]}
so in the previous example it has a list of items, which each has a video-url, so you alias this and that's it, makes sense?


@wilkerlucio and thanks to you for taking the time to reply. Ha! I didn’t mean a list of videos. What I meant was two properties each pointing to a youtube url. For example, :spacex.launch/video-url and :spacex.launch/interview-url


From what you said about aliases in the talk, it seems that at this point Pathom would not be able to pick which video to follow


Unless there is some sort of join/other way around this issue


ah, gotcha, well, you have some options in this case, in the example you sent now there not a single definitive way to link, so the api designer should choose, you could still point the video-url to translate to youtube as the default, and make a secondary join for the interview one, something like: {:spacex.launch/interview-youtube []}, this way in the same level of the launch you get the main video, or join to this new name to get data about the interview part. You could make both depend on a join, this reduces the library reach but also reduces ability, the choice will depend on each case. A third option, in case there are two different variables that point to the same thing (maybe because some field got renamed for example), in this case you can implement resolvers for both cases, and pathom will choose which to use (and backtrack in case it fails, trying the other option)


@wilkerlucio ah, thank you! That’s useful information. So I take it there is no feature in EQL to “alias an attribute to another” within a new context? I am not sure I am using the right terminology, but what I meant is that if, as per the example I gave, you have two youtube URLs in a context (assigned to different attributes), it seems like you should be able to write a query along the lines of “I was to traverse down that road by assigning this attribute to within a new context, and get, and similarly for the other youtube URL”


Without a change in the API itself


Would such a query feature make sense? Or is there something I am missing? (i.e. would it not work because of X and Y, or…)


Your suggestion of changing the API design makes sense though, and if I have control over the API it seems sensible. I am just wondering if the approach I am suggesting above could be done


the API doesn't really have to change, you can just write more resolvers on top of it and make more nesting, the connection between apis is supposed to be mostly in user control


pathom actually does have an alias feature to change the output name of things, but that doesn't affect the connect process, its just about renaming some output (the use case is when you need the same attribute twice using different parameters, so you can alias one of then to something else, you can do it as: (:my-key {:pathom/as :output-name})


Ah, I see. Still have to get used to some of that way of thinking. Thanks!


Another question on Pathom: would this be the right approach for a parametarised query?

{:pc/input #{:pagination/limit}
 :pc/output [{:user/all ....}]}
And how would one write a resolver where some of those inputs are optional? (i.e. a query that can have a bunch of filters, but where most filters are optional and have some defaults)


no, inputs and params are two different dimensions, the input is more like information to traverse, a dependency (a requirement of the operation to run, that might be available via some computation), its a blur line but from experience I can tell you pagination is usually a param, not an input, so the param you can declare using ::pc/param (be careful, your code is using a single : on the namespace, you need o use :: to expand the alias to get the real keyword, if you not familiar with fully qualified keywords check:


then, you can read the params with: (-> env :ast :params)


the ::pc/param use the same syntax as ::pc/output, currently it does nothing to be honest, but in the future it will be used for auto-complete on the codemirror query editor


ah yes, that was just a typo for ::. and thanks for the information on params. Can they be optional as well?


ah nevermind, the doc seems to indicate there is no validation at the moment


(as you just said as well)


@wilkerlucio what is the syntax for passing params to a resolver? the doc only seems to mention params in conjunction with mutations


@hmaurer you can find some docs for it in the EQL spec:

💯 5

and you motivated me to write the long missing docs about params in the pathom book, doing it now 😉


@wilkerlucio unrelated but coming from GraphQL (which I use on some hobby projects) I particularly liked the part of your talk on interfacing multiple domains (i.e. spacex + youtube). That was a big questionmark for me in GraphQL; how to do schema stitching. Pathom’s attribute-level approach feels a lot more natural for this

😄 5

@wilkerlucio is there a section of the documentation that discusses how to best represent “soft” errors? (such as a validation error on a mutation). I was just reading which seems more suitable for hard, non-user-caused failures


(I am using Fulcro)


there is nothing fully done for it, but you can expose extra data in your errors, pathom supports a ::p/process-error fn that you can use to customise the output, what I usually do is expose a map so I can attach extra info, so if you have validations that can only be done on the server, you can add something to error to tell the UI to represent accordingly


@wilkerlucio ah thanks! Do you know if this works in conjunction with Fulcro’s fallbacks? ( Either way I’ll try it right away


it does, the fallback will cover you from network errors (500, network timeout, etc...), so not a lot of info available, but at least you can tell the user


@wilkerlucio ah, but I meant as a way to pick up the validation error and transact some state (i.e. an error flag + message on the approriate field)


well anyway I’ll try this out 🙂


the fulcro fallback will only trigger if the remote responds with errors, pathom will never respond with an error (unless something had fail big time)


so, I'm just getting you aware that to handle the "soft" errors from pathom, the best thing you can do now is using the pessimistic mutations from incubator:


this way you will have a nice way to handle those


the fallback is still useful, but for other reasons (major failures, like having no internet to hit the parser endpoint, or something crashing bad)


ah ok, makes sense.


Add new docs for how to use parameters in resolvers @hmaurer


that was fast! thanks 🙂