GraphQL and Tree Data Structures with Postgres on Hasura GraphQL engine
This blog post discusses modeling a tree data structure on Postgres using Hasura's GraphQL engine. Tree data structures are commonly used to store hierarchical data such as directory structures, comment threads, and finding common connections in networking applications. The author demonstrates how to create a table for comments with columns for id, parent_id, comment text, created_at timestamp, post_id, and user_id. They also explain how to add a self-reference to the parent_id column and create a relationship to fetch child comments. The mutation to insert a comment is provided along with an example of adding a reply to a comment. The GraphQL query to fetch comments for a post is demonstrated, including ordering by created_at timestamp. The author also discusses handling unknown levels of nesting in comments and suggests using a separate table to keep track of ancestry or arranging the list of comments in memory on the client side. Finally, the author concludes by encouraging readers to explore other use-cases for tree data structures and provides resources for getting started with Hasura's GraphQL engine.
Company
Hasura
Date published
May 8, 2018
Author(s)
Hasura
Word count
1153
Language
English
Hacker News points
None found.