Introduction to PostGraphile
Tags: postgraphile, graphql, postgres, beginners
Published: 2021-07-21 10:24:18

![postgraphile logo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dfy4b3ey39rougm1vj80.png)

#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

![without service](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q2t6i3m4nejmp3z5chu5.png)

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.

![with service](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/35xozv0h4wzz3c8rb0iz.png)


#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.

![DB structure](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f2onsg1u0p2r9tqvclya.png)

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.  

![terminal](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/583sw8a24rmnlc8ldw0h.png)

If you can go to the http://localhost:5000/graphiql endpoint, you will be able to the PostGraphile CLI interface.


![playground](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/msyvd1u9s5hxqnkeknd5.png)


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.

{% youtube KCsQNAV1_to %}


Learn more about **GraphQL, PostGraphile, NestJS and Angular**, please visit [Java Foundation](http://www.javafoundation.xyz/)