@ncg nice! I ended up doing something really similar. Does this implementation include any custom resolvers i.e. keys that are themselves queries (:posts-by-user)?
The referenced code does not, but there is a newer version at https://github.com/ClockworksIO/pullql, which does. It’s conceptually the same as described here, but with a somewhat different implementation. Implementations are provided via a function like the following:
(defmulti derive-attribute (fn [attr db eids values] attr))
which is expected to return Datoms.
Unfortunately there are neither public tests no usage examples at the moment, but if there is interest I can put some up.
This is really cool! I’d really like to see a true GraphQL adapter for Datomic; it seems like the ideas behind both really fit well together, and the GraphQL interface ameliorates a lot risk associated with using Datomic inside a bigger ecosystem.
I could see a parser going one (or both) ways between this and GraphQL to provide a nicer interface for Clojure-native applications.
Interesting ! I’m working on something more general currently - backed by any data store - but I agree that Datomic Pull has significant limitations for implementing graph APIs, with its lack of parameterized and derived attributes.
@lilactown it should be quite easy to implement a GraphQL API on top of Datomic using the existing GraphQL libs in the ecosystem, especially on Peers. However, the gap between GraphQL semantics and Datomic’s semantics should not be underestimated - GraphQL is actually quite complex when you want to stick to the specs, what with its type conditions and conflict resolution rules. That makes bridging it to something simple like Datomic Pull fairly non-trivial. I hope to bring myself around to achieving that for my current lib someday.
@lilactown @vvvvalvalval there’s definitely plenty of cross over between GraphQL and Datomic. One area I wonder about is polymorphism. One of the more interesting parts of Datomic IMO is that you can assign the same properties to multiple distinct “types” e.g. User and Organization can both be tagged with
:security/risk :yellow. GraphQL makes us distinguish beetween User.security and Org.security despite being the same
Regarding polymorphism, isn’t this the role of GraphQL interfaces ? https://graphql.org/learn/schema/#interfaces
There ia also pathom library https://github.com/wilkerlucio/pathom/blob/master/README.md
Really great for building parsrs, also has gràphql <-> datomic pull syntax conversion helpers.
great idea, I somehow missed this when I was using GQL last, but that’s a nice addition
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.