neo4j-graphql / neo4j-graphql-java

Neo4j Labs Project: Pure JVM translation for GraphQL queries and mutations to Neo4j's Cypher
Apache License 2.0
105 stars 49 forks source link

Neo4 OGM model as schema #88

Open karayv opened 4 years ago

karayv commented 4 years ago

I wonder if there is a way to use my Neo4j OGM annotated Java classes as a schema for neo4j-graphql-java. I have my model classes and I don't want to have them duplicated in the IDL (or SDL) format.

Model example:

@lombok.Data
@JsonIdentityInfo(
        generator = ObjectIdGenerators.PropertyGenerator.class, 
        property = "id")
public abstract class EntityMetadata {
    @Id
    String id;    
    long lastChangeTime;    
    String comment;
}

@Setter
@Getter
public class EntityA extends EntityMetadata {
    String propA;

    @Relationship(direction = Relationship.OUTGOING, type = "TEST")
    ArrayList<EntityMetadata> entityBs = new ArrayList<>();
}

@Setter
@Getter
public class EntityB extends EntityMetadata {    
    String propB;

    @Relationship(direction = Relationship.INCOMING, type = "TEST")
    EntityA entityA;    
}

If currently there is no such feature how would you add it? Overall, do you think it is possible?

I believe at the moment SchemaBuilder supports SDL strings and TypeDefinitionRegistry. I guess the easier approach would be to create TypeDefinitionRegistry in runtime from model classes using reflection and then use it in SchemaBuilder.

I saw a post by @jexp, he has SDL separate from the model class.

karayv commented 4 years ago

This project allows "Code first generation of GraphQL schema from JPA entities" as a top feature.

If we consider Neo4j-ORG as an alternative to JPA...