HACKER Q&A
📣 ethan_smith

How do I go about using PostGraphile?


I'm new to the whole GraphQL environment but have a lot of experience in writing REST based micro-services where most of the business logic goes into a controller and the database layer is separate.

For a new project we've chosen PostGraphile and I've spent a few days reading the PostGraphile documentation, but to me it seems like it just exposes the CRUD APIs for your underlying Postgres database and tries to move most of the logic in the database layer. I'm have a basic idea of the modularity/plugins and extendable plugins to add more functionality to the PostGraphile app.

But where/how exactly do I write the core/business logic of the micro service?

For example, I currently have a NodeJs REST based service that:

- Has an API that fetches data from database, sends it to another micro-service for processing waits for the result and stores the returned result back in the DB.

- Has an API that fetches and aggregates data from multiple micro-services and returns to the client, without doing any database reads.

- Has an API which fetches something from ElasticSearch and DynamoDB, processes it and returns a response.

So my question is, How do I do something similar with PostGraphile?

It just feels like I'm missing a piece of the puzzle.


  👤 BenjieGillam Accepted Answer ✓
PostGraphile is designed for a situation where Postgres is your main data store, and other things are ancilliary. You can add in the other things with traditional GraphQL resolvers via the plugins/etc that you've mentioned; but if your stack is already quite complex with a lot of data stores that interact in interesting ways (i.e. not just driven by postgres and then fetching additional things from other stores as needed; but instead getting some from one, feeding it to another, feeding it back to the first, etc) you might be better off rolling your own GraphQL API that can handle your complex requirements.

If you like the plugin system, lookahead, etc then you could dive straight into Graphile Engine (which is agnostic to data store(s)) and use that to build your GraphQL API. If autogeneration and applying wide-ranging transforms appeals to you, that might be an interesting approach, but otherwise that system is not sufficiently optimised (yet) for one-off APIs currently (and is under-documented), so you might have a better time just writing your own types and resolvers with Apollo Server or similar.