feat: add dependency graph API endpoint #1038
Open
+530
−16
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a new API endpoint
GET /dependency-graphthat queries PostgreSQL system catalogs to return database object dependencies as nodes and edges, suitable for graph visualization.Motivation
Understanding database schema dependencies is challenging in complex projects. This endpoint enables building visual tools that show:
This is the backend foundation for an interactive Schema Graph feature in Supabase Studio.
Changes
New Files
src/lib/PostgresMetaDependencyGraph.ts- Main class that queries and transforms dependency datasrc/lib/sql/dependency_graph.sql.ts- SQL queries for nodes and edgessrc/server/routes/dependency-graph.ts- Fastify route handlerModified Files
src/lib/PostgresMeta.ts- Register dependency graph classsrc/lib/index.ts- Export new typessrc/lib/types.ts- Add TypeScript types and schemassrc/server/routes/index.ts- Register routeAPI
Endpoint
Query Parameters
include_system_schemasincluded_schemasexcluded_schemasincluded_typesResponse
Node Types Supported
Edge Types Supported
fk- Foreign key constraintstrigger_table- Trigger attached to tabletrigger_function- Trigger calls functionpolicy- RLS policy on tableindex- Index on tableview_dependency- View depends on table/viewfunction_table- Function references tablesequence_owned- Sequence owned by table columnTesting
Build passes:
The SQL queries have been tested against databases with complex schemas including multiple schemas, cross-schema references, triggers, policies, and materialized views.
Future Improvements