Replies: 5 comments
-
@claymccoy First off thank you for checking out the library, it is interesting to see the many different ways people are using GraphQL My first recommendation would be to not actually expose your database objects as part of your API. I know it may seem that GraphQL is a perfect match for graph databases, but GraphQL is just poorly named. It is neither graph based, nor does it provide a fully feature query language like SQL. It is just another way for you to expose your API contract to your clients. If you wanted to build this API in REST would you expose the same exact objects as your DB? For most people APIs exists to add abstractions on your raw domain objects so you are free to change them later and not have clients tied directly to your data implementations. That being said, I know there are some useful ways of just exposing your DB schema in an API that has a schema itself (GraphQL, gRPC). This should be possible using the custom hooks when you are adding a type or field. Here you can inspect the |
Beta Was this translation helpful? Give feedback.
-
Actually taking a second look what would really help here is a new hook for specifically generating a new |
Beta Was this translation helpful? Give feedback.
-
I think this still could be resolved with the existing hook |
Beta Was this translation helpful? Give feedback.
-
I appreciate the advice on separating the db and api abstractions, and normally I would agree. But this is a bit different. Since Neo 4j is a graph database it matches up much better than something like a SQL database would. Graphql is a tree which is a type of graph. So they actually match up perfectly. It is true that you might still want an abstraction in the middle so that you could change the db without affecting the API, but I actually want them to be the same. I basically want to use graphql to query neo rather than cypher. I do all the abstracting I need to do with how I ingest the data into neo4j, not when I read it out. Check it out, there is a Neo4j extension that lets you query it with GraphQL instead of Cypher. My app basically does the same thing as that extension. Querying Neo using GraphQL. Unfortunately, that extension is EOL, but they broke out the part that converts a GraphQL query to Cypher into a library. Your library makes a perfect companion to neo4j-graphql-java because your it allows me to generate the schema and have the neo4j model be the source of truth. graphql-kotlin: Neo4j model -> GraphQL Schema I'm surprised these two projects aren't used together in apps. But they aren't. Unfortunately, neo4j-graphql-java has an outdated version of graphql-java and it doesn't play well with your library. I spent today trying to fix that rather than making use of SchemaGeneratorHooks. But I'm hoping to dive into that next. |
Beta Was this translation helpful? Give feedback.
-
I got this working using onRewireGraphQLType(). I use reflection on the data class myself and construct directives from the annotations on the class. Let me know if you see improvements with the way I am using your library. I'm pretty sure I am not using enum types as intended, but it works! :)
This is a unit tests the demonstrates what I am trying to do. I am turning my neo4j data classes into a GraphQL schema with the neo4j directives.
|
Beta Was this translation helpful? Give feedback.
-
I'd like to use the Kotlin Schema Generator to generate my GraphQL schema from Kotlin classes. I have existing classes that persist to Neo4j using the Neo4j OGM annotations:
My GraphQL schema will look almost the same:
So I want to modify the generation to use the Neo4j annotations. For example:
@Relationship(type = "DEPENDS_ON", direction = Relationship.OUTGOING)
becomes
@relation(name:"DEPENDS_ON", direction:OUT)
@Id val id: String
becomesid: ID!
I read through the docs, but didn't see what I was looking for. What is the best way to do this type of customization with your library? Thanks!
Beta Was this translation helpful? Give feedback.
All reactions