Add a Postgres Database Table to a Hasura GraphQL Backend

Share this video with your friends

Send Tweet
Published 2 years ago
Updated 10 months ago

Use a GUI to create a Postgres table for your GraphQL engine and add some test data to it.

Instructor: [0:00] To add some data to this GraphQL end point, we need to first of all add a table to the database. Click on data, click on add table and give this table a name. We can call this Caesar. The next thing we need to do is to define some columns or some fields for this table.

[0:19] The first field I would like to add is the username field which is going to be of type text. The next field would be password field which would also be of type text. This next field which we want to save as the primary key is going to be of a different type, an integer, which is going to be auto incremented. Of course, it should be unique.

[0:42] You can add one frequently used column which is the created_at column, which is basically going to run the null function to generate the current timestamp at the point where this field was created.

[0:55] We can set the primary key to the ID, then once we scroll down and click on the Add table button, what this will do is to go to the PostgreSQL database and create a table there. You can see the table and its field here, if you want to modify it. You can start inserting rows or browsing through the data you have, but instead of doing this here, let's use the GraphQL window to do this.

[1:23] If you scroll down on the sidebar and choose the mutation command and add a new one, if you're able to insert a username and a password...You can just give the password anything, and the username can be codebeast, and you can just return the affected row. This generates a GraphQL mutation for us.

[1:51] If you run this, you should get a response, which shows us how many rows were created. Now, if you go back to the Data tab or the Data menu, click on the user table which you created. You should see that this field has been added to the table.