graphql
graphql copied to clipboard
Class Builder Script for OGM
Is your feature request related to a problem? Please describe. Nope
Describe the solution you'd like I want a helper script that generates classes for each node type so that Intellisense's autocomplete can be leveraged.
Then on the base class, add a number of convenient methods for connecting two nodes, creating a single node, etc.
Could be inferred from the schema.
Basically the thought is that it'd be a script, or method you run that does this and spits out the code into a file somewhere.
e.g. and this is a rough example, in the middle of writing code that's similar to what I'm describing, and I haven't run it yet, but to get a sense of what I mean:
class Node {
constructor(props) {
this.props = props;
}
asArgs() {
return {
type: this.constructor.name,
props: this.props
};
}
put() {
return graph.node.put({
type: this.constructor.name,
props: this.props
});
}
putAndConnect(toNode, edgeProps) {
return graph.node.putAndConnect({
from: this.asArgs(),
edge: edgeProps,
to: toNode.asArgs()
});
}
}
class Metric extends Node {
constructor({
props: {
name,
source,
description,
}
}) {
super({
name,
source,
description,
});
}
}
Describe alternatives you've considered Writing this myself!