-
Notifications
You must be signed in to change notification settings - Fork 30
Graph renderer #116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
maldoinc
wants to merge
4
commits into
master
Choose a base branch
from
graph-renderer
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Graph renderer #116
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| --- | ||
| description: Wireup interactive dependency graph for Django: expose the graph page, understand what it shows, and gate it by environment. | ||
| --- | ||
|
|
||
| ## Enable The Interactive Graph | ||
|
|
||
| Create a small view that renders the graph page from the application container: | ||
|
|
||
| ```python title="mysite/wireup_graph.py" | ||
| from django.http import HttpRequest, HttpResponse | ||
| from wireup.integration.django import get_app_container | ||
| from wireup.renderer.full_page import GraphEndpointOptions, render_graph_page | ||
|
|
||
|
|
||
| def wireup_graph(_request: HttpRequest) -> HttpResponse: | ||
| return HttpResponse( | ||
| render_graph_page( | ||
| get_app_container(), | ||
| title="My Django App - Wireup Graph", | ||
| options=GraphEndpointOptions(base_module="mysite"), | ||
| ), | ||
| content_type="text/html", | ||
| ) | ||
| ``` | ||
|
|
||
| Then mount it in your URLconf: | ||
|
|
||
| ```python title="mysite/urls.py" | ||
| from django.conf import settings | ||
| from django.urls import path | ||
|
|
||
| from mysite.wireup_graph import wireup_graph | ||
|
|
||
| urlpatterns = [ | ||
| # ...your existing routes... | ||
| ] | ||
|
|
||
| if settings.DEBUG: | ||
| urlpatterns.append(path("_wireup", wireup_graph)) | ||
| ``` | ||
|
|
||
| Then open `http://127.0.0.1:8000/_wireup`. | ||
|
|
||
| ## What It Shows | ||
|
|
||
| The graph can include: | ||
|
|
||
| - services and factories | ||
| - configuration nodes | ||
| - singleton, scoped, and transient lifetimes | ||
| - discovered Django consumers that the graph can infer from the loaded app state | ||
|
|
||
| ## Environment Gating | ||
|
|
||
| Because the graph exposes internal implementation details, it is best treated as a development tool. | ||
|
|
||
| A typical pattern is to mount the route only in local or non-production environments: | ||
|
|
||
| ```python title="mysite/urls.py" | ||
| if settings.DEBUG: | ||
| urlpatterns.append(path("_wireup", wireup_graph)) | ||
| ``` | ||
|
|
||
| If you need stricter control, omit the route entirely in production or protect it like any other internal debug page. | ||
|
|
||
| ## Related | ||
|
|
||
| - [Django Integration](index.md) | ||
| - [General Interactive Graph Docs](../../interactive_graph.md) | ||
| - [Django Request-Time Injection](request_time_injection.md) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| # Interactive Graph | ||
|
|
||
| !!! interactive-graph "Interactive Graph" | ||
|
|
||
| Turn your container into an interactive dependency graph. Explore routes, functions, services, factories, | ||
| configuration, and scopes in a live page with search, grouping, and dependency tracing. | ||
|
|
||
| Learn how it works and explore it on an demo pet store app: | ||
|
|
||
| [:octicons-arrow-right-24: Live Demo](wireup_graph/pet_store.html){ .md-button .md-button--primary target="_blank" } | ||
|
|
||
| Wireup can render your dependency graph as an interactive page, including: | ||
|
|
||
| - routes and injected functions for selected frameworks | ||
| - services and factories | ||
| - configuration nodes | ||
| - singleton, scoped, and transient lifetimes | ||
|
|
||
| This is one of the fastest ways to understand how a real application is wired together without relying on a static dump | ||
| or a handwritten diagram. | ||
|
|
||
| ## Preview | ||
|
|
||
|  | ||
|
|
||
|
|
||
| ## Automatic with FastAPI and Flask | ||
|
|
||
| FastAPI and Flask can expose the graph page automatically at `/_wireup`. | ||
|
|
||
| ### FastAPI | ||
|
|
||
| ```python | ||
| from wireup.integration.fastapi import GraphEndpointOptions | ||
| import wireup.integration.fastapi | ||
|
|
||
| wireup.integration.fastapi.setup( | ||
| container, | ||
| app, | ||
| add_graph_endpoint=True, | ||
| ) | ||
| ``` | ||
|
|
||
| ### Flask | ||
|
|
||
| ```python | ||
| from wireup.integration.flask import GraphEndpointOptions | ||
| import wireup.integration.flask | ||
|
|
||
| wireup.integration.flask.setup( | ||
| container, | ||
| app, | ||
| add_graph_endpoint=True, | ||
| ) | ||
| ``` | ||
|
|
||
| ## Use in other frameworks | ||
|
|
||
| If your framework does not have automatic graph-page setup, you can still generate the graph yourself from Python. | ||
|
|
||
| ### 1. Build graph data | ||
|
|
||
| ```python | ||
| from wireup.renderer.core import GraphOptions, to_graph_data | ||
|
|
||
| graph_data = to_graph_data( | ||
| container, # or get_app_container() if the integration provides it | ||
| options=GraphOptions(base_module="myapp"), | ||
| ) | ||
| ``` | ||
|
|
||
| ### 2. Render it as HTML | ||
|
|
||
| ```python | ||
| from wireup.renderer.full_page import full_page_renderer | ||
|
|
||
| html = full_page_renderer(graph_data, title="My App - Wireup Graph") | ||
| ``` | ||
|
|
||
| ### 3. Return it from a route | ||
|
|
||
| ```python | ||
| @app.get("/_wireup") | ||
| def wireup_graph(): | ||
| graph_data = to_graph_data(container, options=GraphOptions(base_module="myapp")) | ||
| html = full_page_renderer(graph_data, title="My App - Wireup Graph") | ||
|
|
||
| return HTMLResponse(html) | ||
| ``` | ||
|
|
||
|
|
||
| !!! tip | ||
| Make sure to permission this endpoint appropriately in production since it exposes internal implementation details. You can disable it by omitting `add_graph_endpoint=True` or by not registering the route at all. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Edge-direction convention should be documented. The renderer emits source = provider, target = consumer, which is the opposite of UML's dependency-arrow convention (where the arrow points from the dependent to the depended-upon). Tools and readers built on the graph JSON will silently make the wrong inference without this.
Fix: Consider reversing the direction to match UML, or adding a note to this page clarifying the current convention.