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

Graph serialization and deserialization #49

Open
huypham50 opened this issue Feb 25, 2024 · 1 comment
Open

Graph serialization and deserialization #49

huypham50 opened this issue Feb 25, 2024 · 1 comment

Comments

@huypham50
Copy link

Are there any suggestions on how to implement these two helpers?

const graph = new DepGraph() // adding nodes a, b, c, d, etc

const serializedGraph: Record<string, unknown> = serialize(graph) // unknown could be a specific type

const insertedRow = database.insert({ serializedGraph }) // putting serialized graph into a database using something like prisma or sequelize

const const deserializedGraph: DepGraph<T> = deserialize(insertedRow.serializedGraph) // T could be a specific type as well

Great library!

@jriecken
Copy link
Owner

jriecken commented Apr 1, 2024

I've been hesitant to add any sort of official serialization/deserialization support to this library as it's possible to add data to the graph that is not serializable.

See this comment chain for more information c9238dc#commitcomment-137327165

Ah, this wasn't an intentional change (although there's never really been a promise that the graph is JSON-serializable)

The only thing I worry about adding an official toJSON() / fromJSON(string) is that it's possible for someone who is using this library to add a node that has data attached that is not JSON.stringifyable (e.g. as you've shown a Map, or a Function, etc) and it's not clear what the output should be (fromJSON(graph.toJSON()) would not return the same thing)

Someone else had luck using this lib to serialize the graph - https://github.com/yahoo/serialize-javascript

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

No branches or pull requests

2 participants