Building Stellar Apps

An adventure in PostgreSQL and GraphQL

Over the past year, I’ve built three successful Stellar applications of varying complexity.

The Stellar SDKs are amazing well written and the documentation is getting better everyday. The communities on Slack, Reddit and StackExchange is vibrant, helpful and excited. As with anything however, especially a relatively complicated technology the ramp up can be slow and it doesn’t take long to hit both knowledge and feature walls.

Across all the apps I’ve worked on this has been becoming more and more true. As you gain a deeper understanding of how something works you begin to collect a pretty solid wishlist for features you wish existed or problems you haven’t figured out how to solve yet.

The biggest most common and glaring issue I’ve run across for both myself and within the community is getting answers to more and more complex and specific questions about the Stellar dataset itself.

Things like:

List out all accounts who trust USD from issuer X

Show me all the trustlines for issuer X

Which accounts haven’t yet set an inflation destination?

List all accounts ordered by their XLM volume

Rank accounts based on their level of “trust” throughout the network

The list goes on and on and as you begin to build, these unanswerable questions will plague you. I say unanswerable but of course they actually are in fact answerable, just not by the current SDKs. Currently to dig deeper into the Stellar ecosystem you have to somehow gain access to the distributed Stellar PostgreSQL database itself. This requires spinning up at least a core server if not a horizon instance as well if you’ve got historical questions needing answers.

With Stellar’s Docker repositories this is actually not as painful as it sounds but the real trouble comes when it’s time to get the psql queries ported to the frontend. This requires you to build an API layer.

This is where I was a couple weeks ago. Slowly building out individual endpoints. Each designed to answer a specific set of questions. It very quickly became a massively painful process. Especially for something which wasn’t ultimately the application I actually wanted to build.

Somewhere between the lines and some conversations with some folks on Slack I had an idea. I wonder if there was an open source tool for porting a PostgreSQL database over to GraphQL. I mean they shared a lot of schema similarities and what GraphQL was to the frontend PostgreSQL was to the backend. Surely there might maybe be such a tool.

💥 Enter PostGraphile 💥

Just a few hours of learning and poking around later and I had direct access to the entire core and horizon databases via GraphQL. Needless to say I was floored. I still am.