What is PostGraphile?
If you are familiar with Spring Data JPA, it will be very easy to understand PostGraphile. But never mind. Let's look into it. PostgreSQL DB is one of the very popular DB for high-performance applications. The ProstGraphile works with PostgreSQL database and GraphQL. It provides instant and high-performance GraphQL APIs from the PostgreSQL schema within seconds. It gives a lot more features.
Features of PostGraphile
- Stunning performance
- Database relations are discovered automatically and automatic CRUD mutations Ex: vehicleById, createVehicle, updateVehicle, deleteVehicle... etc.
- Enable query functions like sorting, filtering, pagination... etc.
- Very easy to enable and use.
- Schema documentation is generated through the CLI
- You can directly call PostGraphile endpoints via your client application.
PostGraphile without a middleware service
You may think that we can use PostGraphile without a service. Because PostGraphile provides GraphQL APIs, then a client can directly call those APIs. Yes, this is possible, but if we need some customizations or if we need to request data from any other web services (Ex: REST), we need to have a middleware service like NestJS, Spring Boot...etc. It will look like this.
Install PostGraphile
Hit this command to install PostGraphile globally.
npm install -g postgraphile
PostGraphile CLI interface
My TestDB2 database has only one table called Vehicle. This is my DB structure.
Then I run the following command to get the PostGraphile CLI interface. You can find this from the Postgraohile documentation.
npx postgraphile -c 'postgres://postgres:1234@localhost/TestDB2' --watch --enhance-graphiql --dynamic-json
As you can see my database is TestDB2, my username is postgres and the password is 1234. Once I hit this command in the terminal it will give a few details as mentioned below. There some other CLI options. You can find more details from the official documentation.
If you can go to the http://localhost:5000/graphiql endpoint, you will be able to the PostGraphile CLI interface.
In Explore you can see Query and also you can create Mutations too. This is very similar to the GraphQL playground. All queries and mutations are automatically generated. So you have no worries, just click on the query or mutation and hit the play button to execute the query.
Please check the following video to understand the complete flow of working with PostGraphile.
Learn more about GraphQL, PostGraphile, NestJS and Angular, please visit Java Foundation
Top comments (0)