Map Java object to GraphQL object

I find it difficult to implement GraphQL in a java project as part of its update. I am trying to associate an entity (which uses Hibernate ORM to map to various databases) with a GraphQLObjectType object. Any suggestions how can I do this? Is it possible to omit GraphQL database configurations, if so?

+5
source share
3 answers

There are several options here.

  • It's probably best not to display the entity directly. Entities are direct representations of the database and, as such, probably should not be directly disclosed, but should be enclosed in a DTO (possibly allowing you to paginate, align relationships or do what is appropriate).
  • If you just need to map the class (entity or not) to GraphQLObjectType , graphql-java-annotations is the easiest (and most restricted) route
  • If you want to represent the entire entity graph through GraphQL, then graphql-jpa (as Sriram suggests ) is best for you, as he intended to do just that by adding page numbering, aggregation, and sorting.
  • If you want to automatically represent not only the / DTO entity class, but also the operations on it (for example, an arbitrary service class), look at graphql-spqr (I am the author of this project)
+8
source

If you already defined your objects using JPA / Hibernate, try the following:

https://github.com/jcrygier/graphql-jpa

+1
source

You can also check graphql-maven-plugin-project, which generates all the necessary code on the client side and server side. On the server side, it generates JPA annotations and allows you to personalize them.

It is available at https://github.com/graphql-java-generator/graphql-maven-plugin-project . This is the website https://graphql-maven-plugin-project.graphql-java-generator.com

Etienne

0
source

Source: https://habr.com/ru/post/1011472/


All Articles