Fork me on GitHub
#pathom
<
2019-02-05
>
eoliphant07:02:34

Hey guys. quick question. I’m using pathom to ‘smooth out’ the interface to data coming back from datomic. In general pretty straight forward, even have some generic query funcs, that my pathom resolvers call that mostly obviate the need for per resolver db queries, etc. I’m currently trying to figure out the best way to flatten datomic ‘enums’ generically. so say my pathom query is [... [:my-enum-attr]] and I expect to get {:my-enum-attr :enum-val/one}. Of course datomic returns something like {:my-enum-attr {:db/id xxx :db/ident :enum-val/one}}. I was thinking about the stuff in the manual, around managing derived attributes with resolvers, but I don’t think that works here since I already have the attribute I want, I just want to apply a transform to its value, without having to do something more brute force with the results prior to returning it to pathom

wilkerlucio10:02:19

@eoliphant bom dia 🙂 I think a good idea would be to create a new name for the "normalized" version of the enum, for example, if you have :animal/specie thats something like :animal.specie/dog, then you could have a resolver for the attr :animal/specie-ident that converts and extracts, having a separated name helps to avoid shadowing the original name and making it unaccessible. With this basic idea in mind, you could try to inspect the datomic schema and generate those automatically, I don't remember what the datomic schema looks like after commited, but I think worth checking, it might have enough information to automate those enum resolvers

eoliphant13:02:23

bom dia 🙂 just got back, dying from the cold lol. Ok, that’s interesting. I’d actually already added a bit of a hack,. I’ve been working on a tool that lets me define a sort of generic domain/attr model, so I can create docs, gen datomic schema, warn if specs are missing etc. So I already ‘know’ that :animal/specie is a ‘enum type’. SO used that to look at the query and see if I’d need to do any munging of the result. I’ll use the same info to try what you suggested.

eoliphant13:02:31

obrigadao 🙂

Daniel Hines17:02:59

I've thought that it should be totally feasible to create a datascript/datomic -> pathom plugin like the existing graphql one, no?

wilkerlucio17:02:18

@d4hines totally, just never got prioritised on my side, but I think would be a nice addition

Daniel Hines17:02:11

I wouldn't mind taking a stab at this, starting with Datascript. I'd like to play with your graphql examples to get a feel for it. Are your examples from the Conj on GitHub?

wilkerlucio17:02:31

didn't tested, please let me know if there is anything broken