⚠️ This lesson is retired and might contain outdated information.

Add a Postgres Database Table to a Hasura GraphQL Backend

Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 2 years 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.

egghead
egghead
~ 49 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today