neo4j / graphql

A GraphQL to Cypher query execution layer for Neo4j and JavaScript GraphQL implementations.
https://neo4j.com/docs/graphql-manual/current/
Apache License 2.0
498 stars 147 forks source link

Class Builder Script for OGM #4624

Open inf3rnus opened 6 months ago

inf3rnus commented 6 months ago

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!

inf3rnus commented 6 months ago

Would be a killer feature IMO, way cooler than having to manually specify types.