Skip to content
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

Export and import graph #781

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

kmcginnes
Copy link
Collaborator

@kmcginnes kmcginnes commented Feb 6, 2025

Description

Adds the ability to save and load a graph to and from a file. This requires the user to be in the same connection. We define "the same" as:

  • Same database URL (regardless of proxy server use)
  • Same query engine (i.e. Gremlin, openCypher, SPARQL)

The file contains a minimal set of information needed to reconstruct the graph:

  • Metadata
    • Kind of document
    • Source of export (i.e. Graph Explorer)
    • Version of the source (i.e. Graph Explorer version)
    • Timestamp
  • Connection
    • Graph database URL
    • Query engine
  • Graph data
    • List of node IDs
    • List of edge IDs

During import, the file will be validated with Zod, then sent to the vertex and edge details queries to load the data. When all those queries return back it will render the graph.

The export path will attempt to use the new file system APIs that are not widely supported across browsers. As of today, Chrome and Edge will properly show the native OS save file dialog. The fallback behavior for Firefox and Safari is to save the file to the user's download folder, just like any other download.

Future optimizations

Today, the details queries run per node and edge, so this can be quite expensive for large graphs. There are likely some optimizations to make to batch up set of nodes and edges to reduce the amount of queries.

Validation

  • Tested with Chrome and Safari
  • Tested with multiple connections
  • Tested with broken connection
Save.and.load.a.rendered.graph.mp4

Related Issues

Check List

  • I confirm that my contribution is made under the terms of the Apache 2.0
    license.
  • I have run pnpm checks to ensure code compiles and meets standards.
  • I have run pnpm test to check if all tests are passing.
  • I have covered new added functionality with unit tests if necessary.
  • I have added an entry in the Changelog.md.

@kmcginnes kmcginnes force-pushed the export-and-import-graph branch from 0d1a225 to 5989d93 Compare February 6, 2025 22:04
@kmcginnes kmcginnes marked this pull request as ready for review February 6, 2025 22:05
if (matchingByUrlAndQueryEngine.length > 0) {
const matchingConnection = matchingByUrlAndQueryEngine[0];
return {
message: `The graph file requires switching to connection ${matchingConnection.displayLabel}.`,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of scope for this PR but has there been consideration to adding a prompt to allow the user to switch the active connection when this scenario is encountered?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but it depends on all the plumbing for restoring a graph on refresh so I'm doing that first.

@kmcginnes kmcginnes force-pushed the export-and-import-graph branch from 5989d93 to c972212 Compare February 7, 2025 19:27
@kmcginnes kmcginnes force-pushed the export-and-import-graph branch from c972212 to a8f7de2 Compare February 7, 2025 19:32
<PanelHeaderActionButton
icon={<SaveIcon />}
label="Save graph to file"
onActionClick={() => exportGraph("graph-export.json")}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible for the default file name to be less generic so that the user doesn't have to change the default file name to avoid overwriting existing exports? Personally when I am saving a file from a site I like to have the default name be descriptive and unique enough so I don't have to rename it myself.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible, but what would you want it to be?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personal preference would be to add context about the database being extracted (ie. connection detail) but will leave it up to your discretion to make the ultimate decision.

@andreachild
Copy link

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Save & load a graph from a JSON file
2 participants