You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+16-19Lines changed: 16 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -1,31 +1,29 @@
1
1
# GraphQL Java Generator
2
2
3
-
TODO: remove need to graphql-java-client from the server (needed because of the annotations)
4
-
5
3
6
4
The GraphQL Java Generator makes it easy to work in Java with graphQL in a schema first approach.
7
5
8
-
This project is an accelerator to develop <B>GraphQL clients</B> and <B>GraphQL servers</B> in java. That is: it generates the boilerplate code, and let you concentrate on what's specific to your use case: the queries/mutations/subscriptions you will call, when in client mode. And the response to the queries/mutations/subscriptions call, as well as the relations between objects, when in server mode.
6
+
This project is an accelerator to develop __GraphQL clients__ and __GraphQL servers__ in java. That is: it generates the boilerplate code, and let you concentrate on what's specific to your use case: the queries/mutations/subscriptions you will call, when in client mode. And the response to the queries/mutations/subscriptions call, as well as the relations between objects, when in server mode.
9
7
10
-
* The <B>GraphQL client</B> generated by graphql-java-generator contains a class for each query and mutation type. Subscription are not managed yet. These classes contains a metod for each field of the query and mutation types. To call the GraphQL server, you just call one of this method. The <B>GraphQL response is contained in POJOs</B>, for easy use in Java.
11
-
* The <B>GraphQL server</B> contains the heart of the GraphQL server: The main method (if you use it as a Spring Boot application), the declaration of each Data Fetcher, and the listening of incoming calls, as well as the forging of the Response. The developper has 'only' to develop the Data Fetchers, that is: the link with the underlying data. The generated POJOs are annotated with JPA annotations, so it's pretty easy to map with Spring Data.
8
+
* The __GraphQL client__ generated by graphql-java-generator contains a class for each query and mutation type. Subscription are not managed yet. These classes contains a method for each field of the query and mutation types. To call the GraphQL server, you just call one of this method. The __GraphQL response is contained in POJOs__, for easy use in Java.
9
+
* The __GraphQL server__ contains the heart of the GraphQL server: The main method (if you use it as a Spring Boot application), the declaration of each Data Fetcher, and the listening of incoming calls, as well as the forging of the Response. The developer has 'only' to develop the Data Fetchers, that is: the link with the underlying data. The generated POJOs are annotated with JPA annotations, so it's pretty easy to map with Spring Data.
12
10
13
-
Please, take a look at the projets that are within the graphql-maven-plugin-samples: they show various ways to implement a GraphQL server, based on the graphql-java library.
11
+
Please, take a look at the projects that are within the graphql-maven-plugin-samples: they show various ways to implement a GraphQL server, based on the graphql-java library.
14
12
15
-
<B>The interesting part is that graphql-java-generator is just an accelerator: you don't depend on additional library</B>. So, it just helps you.
13
+
__The interesting part is that graphql-java-generator is just an accelerator: you don't depend on additional library__. So, it just helps you to build application based on [graphql-java](https://www.graphql-java.com).
16
14
If the generated code doesn't fully suit your needs, you can: take what's generated as a full sample for graphql-java usage, based on your use case. You can then update the generated code, where it's not compliant for you. And that's it. The only thing, there, is that we would like to know what was not correct for your use case, so that we can embed it into next versions. Or perhaps it's just a matter of documentation, to better explain how to use it...
17
15
18
-
The generator is currently a maven plugin. A Gradle plugin will come.
16
+
The generator is currently available as a maven plugin. A Gradle plugin will come soon.
19
17
20
18
21
19
## Aim of this projet
22
20
23
21
The aim of this project is to:
24
22
25
23
* Hide all the GraphQL technical stuff and boilerplate code
26
-
* Let the developper concentrate on his applicaiton
24
+
* Let the developer concentrate on his application
27
25
* Make it __very easy__ to create a GaphQL client, based on the generated POJOs. The calls to the GraphQL server are just the call of a generated Java method, with Java parameters
28
-
* Make it __easy__ to create a GraphQL server. The plugin generated the server boilerplate code and the POJOs. But it's still up to the developper to map the GraphQL schema to the database schema. See the provided samples for different ways to do this. The generated code integrate the JPA schema, making the database access easy, thanks to the Spring Data Repositories.
26
+
* Make it __easy__ to create a GraphQL server. The plugin generated the server boilerplate code and the POJOs. But it's still up to the developer to map the GraphQL schema to the database schema. See the provided samples for different ways to do this. The generated code integrate the JPA schema, making the database access easy, thanks to the Spring Data Repositories.
29
27
30
28
In the near future :
31
29
* Implement also Mutations and Subscriptions. Currently only queries are managed.
@@ -109,7 +107,7 @@ When the package type of the maven module (or project) is _jar_, then this mode
109
107
The server mode is more complex, as its subject is to link the GraphQL schema to the underlying data structure. This data structure can vary a lot (relational database with lots of possible physical schema, document database like MongoDB, underlying JSON services...). Of course, the generated code can not guess what's your data structure, and how to access it.
110
108
111
109
So the GraphQL Java Generator generates:
112
-
* The GraphQLServer class, wich is the executable Java class. It's actually a Spring Boot application.
110
+
* The GraphQLServer class, which is the executable Java class. It's actually a Spring Boot application.
113
111
* TODO: in the future, it will also be possible to generate war packages.
114
112
* The code expected by the graphql-java library. It depends on no other graphql dependency
115
113
* The POJOs, so that you can manipulate your data.
@@ -127,20 +125,20 @@ The build will complain about the Data Fetchers Delegate you need to define.
127
125
128
126
A Data Fetcher Delegate is a class that implements a XxxDataFetcherDelegate. It is responsible to return the data, as specified in the GraphQL schema. Of course, for mutation, it needs to do some complementary work.
129
127
130
-
<B>Important:</B> a DataFetcherDelegate is a Spring component. That is, in order to Spring to find it, it must implement the @Component Spring stereotype annotation.
128
+
__Important:__ a DataFetcherDelegate is a Spring component. That is, in order to Spring to find it, it must implement the @Component Spring stereotype annotation.
131
129
132
130
The Data Fetcher Delegates are the heart of the Server part.
133
131
134
132
The short story is this one:
135
133
* The code generated by the GraphQL maven plugin directly maps to the entity, thanks to [Spring Data JPA](https://spring.io/projects/spring-data-jpa)'s magic.
136
-
* The developper still needs to develop the DataFetchers, to manage the relation between objects (see the samples and below, to see how to do this).
134
+
* The developer still needs to develop the DataFetchers, to manage the relation between objects (see the samples and below, to see how to do this).
137
135
138
136
A longer story is this one:
139
137
* The GraphQL maven plugin expects a database model that is the same as what's in the GraphQL schema. That is: for each GraphQL object, there is a
140
138
table with the same name, and for each field of each of these GraphQL objects, there is a column with the same name and type. This insure the JPA
141
139
access to the database.
142
140
* In GraphQL request, a critical factor for performance is the way to query relations between objects. The [graphql-java site](https://www.graphql-java.com/documentation/v12/batching/)
143
-
is very clear on this subject. So the maven plugin mark every relational field as transient, and let the developper manage these relations.
141
+
is very clear on this subject. So the maven plugin mark every relational field as transient, and let the developer manage these relations.
144
142
145
143
So you have to create the Data Fetchers. Please, take a look at the projets that are within the graphql-maven-plugin-samples: they show various ways to implement a GraphQL server, based on the graphql-java library. The interesting part is that graphql-java-generator is just an accelerator: you don't depend on additional library.
146
144
@@ -180,19 +178,18 @@ You can access to the H2 Console with this URL: [http://localhost:8180/h2-consol
180
178
181
179
You'll find below the main changes, that are foreseen in the near future
- Generate the package as a jar or war form. Currently, GraphQL Java Generator generates a Spring Boot application.
184
181
- Add a gradle plugin
185
-
- Manage properties which name is a java keyword, like: public, private, class...
186
-
- Manage field parameters. Currently, GraphQL Java Generator accepts parameters out of the query level (that is on object fields), only wih Direct Queries (which is nice enough to begin)
187
-
- Comments should be reported in the generated code, especially the POJOs and the queries, mutations and subsciptions
182
+
- Manage properties which name are java keyword, like: public, private, class... Currently, it would generate a compilation error.
183
+
- Manage field parameters. Currently, GraphQL Java Generator accepts parameters out of the query level (that is on object fields), only with Direct Queries (which is nice enough to begin)
184
+
- Comments should be reported in the generated code, especially the POJOs and the queries, mutations and subscriptions
188
185
- Define specific Scalars (for instance Date, DateTime, Time)
189
186
- The plugin currently manages only one schema. It would be nice to allow several graphqls files, with a pattern like /*.graphqls
190
187
- Fragment in graphql queries
191
188
192
189
193
190
### Note for contributors
194
191
195
-
This projet is a maven plugin project.
192
+
This project is a maven plugin project.
196
193
197
194
If you want to compile it, you'll have to add the lombok.jar file in your IDE. Please see the relevant section, in the Install menu of the [https://projectlombok.org/](https://projectlombok.org/) home page. This very nice tools generates all java boiler plate code, like setters, getters, constructors from fields...
0 commit comments