Holochain Forum

GraphQL and Holochain

This thread is a continuation of a highly detailed discussion started by @pospi regarding GraphQL and where it makes sense to integrate into a Holochain-based stack. Client-side, zome-side, and conductor-side were all considered.

The original thread: https://chat.holochain.org/appsup/channels/dev-graphql

So to recap:

  • The Holochain core team do not (yet) consider GraphQL as being part of the core framework or officially supported stack.
  • There is no real performance impact for Holochain users between an in-browser GraphQL query adapter, and a GraphQL query adapter that runs within the conductor.
  • There is a negligible performance impact for HOLO users when using an in-browser GraphQL query adapter, as it results in more packets going via the wider internet through the hc-web-client connection.
  • Juniper can be compiled and run within DNA code as WASM, but this makes Holochain apps infeasibly large and is not recommended.

Thus, the recommended way of using Holochain with GraphQL is currently via an in-browser schema adapter. This has been successfully implemented in pure JavaScript in hp-admin; and in TypeScript with compiler-generated types in HoloREA.

So, the Holochain <> GraphQL problem seems to be largely a solved one for now, though ongoing experiments are toying with how to make these integrations more generic and less verbose to implement. There is also work to do in both implementations to make requesting data more efficient by adding something like dataloader.

The next big feature to implement is subscriptions, which looks to be dependent on the PubSubEngine interface (see issue in HoloREA repo). I’m curious as to whether anyone has started work on a Holochain-backed PubSubEngine or has plans to, as this appears to be the ‘core’ layer module necessary to get this running end-to-end.

2 Likes

Who do we have to bribe in the core team to make this happen?

1 Like

thanks @pospi for that excellent recap, esp the theoretical performance comparisons. I don’t know of anyone who’s started work on a PubSubEngine… what would your needs be? Would this be for DHT-wide messages between agents, or messages between DNA and UI, or something else? (If this thing exists as a separate DNA, I totally we think we should call the individual networks PubSubClubs :wink: )

@Flip heh, you really want it in core, eh? There were some experiments embedding Juniper into a DNA (as mentioned by Pospi above) which were a way of prototyping whether it’d be worth creating a GraphQL-based SDK/HDK, but yeah — huge binary sizes.

^this one. And on “core / not core”… I don’t think those are semantics we really need to be concerned with. The boundaries between organisations, codebases and parts of this ecosystem are all pretty fuzzy… there is no reason we can’t have an officially supported JavaScript module in the Holochain Github org which provides everything needed to connect Holochain DNAs with JS-based clients built on GraphQL :slight_smile:

2 Likes

Ahhhhh I think I’m getting a clearer picture of the vision. An app can have multiple backends (Holochain/SSB/ActivityPub) and multiple frontends, connected by an interface of GraphQL + an app-specific ontology. Then each backend has adapters that map between it and the GraphQL ontology. Is that right? (one wonders if it even makes sense to call it an app at this point :slight_smile: )

Because you’re closer to your needs than I am, could you share what a generic, app-agnostic HC-to-GraphQL JS module would look like? The only thing I can imagine being versatile enough is something that accepts functions that map queries and mutations to zome calls, but in my naïve implementation it wouldn’t add much value vs just rolling your own ad-hoc for every app’s ontology.

2 Likes

The place I’ve been linking to is pretty much it, and is implemented as you describe.

what a generic, app-agnostic HC-to-GraphQL JS module would look like?

@wollum was playing with something like this, which I think was primarily about mapping Holochain’s core entry & link structures onto a generic GraphQL schema that would allow inspecting and following data in a lowest-common-denominator sort of way.

The other cool thing GraphQL offers (which I haven’t played with yet) is “schema delegation”, which essentially allows defining 1 schema in terms of another. For exampe- defining ValueFlows in terms of a low-level Holochain entry/link storage schema.

1 Like

And the picture gets yet clearer. Thanks! Sounds like the intent, in both your case and @wollum’s, is to have as little mismatch between the GraphQL and the zome functions as possible, and that’s what enables this sort of generic-ness. Your strategy is to have the zome understand the app’s ontology, but @wollum’s strategy is to have an endpoint that doesn’t care about the data and just enables graph traversal.

(BTW your JavaScript reads like Haskell. Very pleasantly declarative and functional.)

1 Like

WOW, YES! This is my vision too with the OASIS API to connect everything to everything… :slight_smile: To eliminate silios and walled gardens…

What you call adapters I am calling Providers in my design… :slight_smile:

Thanks to the amazing work @pospi and his team are doing over at HoloREA I was made aware of GraphQL & Apollo and have been researching them ever since and have concluded it solves a number of technical design decisions I was going through of how to provide an elegant unified interface to all the back-end providers that the OASIS API supports (Holochain, IPFS, SOLID, Ethereum, ActivityPub & lots more!)

The whole point of the OASIS API is to help expose Holochain to the rest of the world and to act as a bridge or stepping stone for everything to slowly migrate over to Holochain… :slight_smile:

I look forward to working with @pospi and his amazing team on how we can work together to bridge the gaps and connect everything to everything… Our World (which is powered by the OASIS API and is like the XR Gamified Interface to it), will also be using HoloREA to power the e-commerce part and in-game purchases, etc… :slight_smile:

Keep up the good work guys! :smiley: Love what you are doing! :slight_smile: :sparkling_heart: :sparkling_heart: :sparkling_heart:

Forgot to add, the other difference is that I am building a .NET/Unity GraphQL/Apollo interface to Holochain so would be interesting to see where we have overlaps and where parts converge and can be shared/re-used, etc… :slight_smile: