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
Added sample project to show plugin configuration to use customized templates:
* graphql-maven-plugin-samples-CustomTemplates-resttemplate defines a customized template for a Query implementation based on a Srping-based QueryExecutor using RestTemplate
* graphql-maven-plugin-samples-CustomTemplates-client is a client project showing plugin configuration to use customized template
Update Maven site with new page ustomtemplates.apt.vm showing usage of new param "templates"
Updated README with info related on how to customize code generation on Maven Plugin
Copy file name to clipboardExpand all lines: README.md
+90-10Lines changed: 90 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,9 @@
2
2
3
3
The GraphQL Java Generator makes it easy to work in Java with graphQL in a schema first approach.
4
4
5
-
This project is an accelerator to develop __GraphQL clients__ and __GraphQL servers__ in java.
5
+
This project is an accelerator to develop __GraphQL clients__ and __GraphQL servers__ in java.
6
6
7
-
That is: graphql-java-generator generates the boilerplate code, and lets you concentrate on what's specific to your use case. Then, the running code __doesn't depend on any dependencies from graphql-java-generator__. So you can get rid of graphql-java-generator at any time: just put the generated code in your SCM, and that's it.
7
+
That is: graphql-java-generator generates the boilerplate code, and lets you concentrate on what's specific to your use case. Then, the running code __doesn't depend on any dependencies from graphql-java-generator__. So you can get rid of graphql-java-generator at any time: just put the generated code in your SCM, and that's it.
8
8
9
9
* In __client mode__ : graphql-java-generator generates a class for each query and mutation type (subscriptions are not managed yet). These classes contain the methods to call the queries and mutations. That is, to call the GraphQL server, you just call one of this method.
10
10
* graphql-java-generator also generates the POJOs from the GraphQL schema. The __GraphQL response is stored in these POJOs__, for easy and standard use in Java.
@@ -14,10 +14,10 @@ That is: graphql-java-generator generates the boilerplate code, and lets you con
14
14
* graphql-java-generator also generates interfaces, named DataFetchersDelegate. It expects a Spring Bean to be defined.
15
15
* The developer just has to implement each DataFetchersDelegate, and the GraphQL server is ready to go!
16
16
17
-
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.
17
+
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.
18
18
19
-
__The interesting part is that graphql-java-generator is just an accelerator: you don't depend on any library from graphql-java-generator__. So, it just helps you to build application based on [graphql-java](https://www.graphql-java.com) .
20
-
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, if it's just a matter of documentation, to better explain how to use it...
19
+
__The interesting part is that graphql-java-generator is just an accelerator: you don't depend on any library from graphql-java-generator__. So, it just helps you to build application based on [graphql-java](https://www.graphql-java.com) .
20
+
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, if it's just a matter of documentation, to better explain how to use it...
21
21
22
22
The generator is currently available as a maven plugin. A Gradle plugin will come soon.
23
23
@@ -52,14 +52,18 @@ You'll find the following samples in the project. For all of these samples, ther
52
52
* The GraphQL server exposes http
53
53
* The server uses the schema personalization, to override the default code generation
54
54
* The GraphQL model maps to the database model
55
-
* The Forum client project shows implementation of the same queries in the XxxQueries classes.
55
+
* The Forum client project shows implementation of the same queries in the XxxQueries classes.
56
56
* StarWars
57
57
* The server is packaged as a war
58
58
* The GraphQL server exposes https
59
59
* The GraphQL interfaces in this model (character, and friends relation) makes it difficult to map to native RDBMS data model. This project uses JPA native queries to overcome this.
60
60
* The StarWars client project shows implementation of the same queries in the XxxQueries classes.
61
+
* CustomTemplates
62
+
* An example related on how to customize code templates
63
+
* graphql-maven-plugin-samples-CustomTemplates-resttemplate project offers a customize template for Query/Mutation/Subscriptino client class and offer a Spring-base RestTemplate implementation for QueryExecutor template
64
+
* graphql-maven-plugin-samples-CustomTemplates-resttemplate proyect defines a client project that generates code with customized template defined in previous project
61
65
62
-
Note: The client projects for these samples contain integration tests. They are part of the global build. These integration tests check the graphql-maven-plugin behaviour for both the client and the server for these samples.
66
+
Note: The client projects for these samples contain integration tests. They are part of the global build. These integration tests check the graphql-maven-plugin behaviour for both the client and the server for these samples.
63
67
64
68
### Client mode
65
69
@@ -91,10 +95,10 @@ When in server mode, the plugin generates:
91
95
* The DataFetchersDelegate interface declarations for all the [Data Fetchers](https://www.graphql-java.com/documentation/master/data-fetching/), which is the graphql-java word for GraphQL resolvers.
92
96
* The DataFetchersDelegate groups the Data Fetchers into one class per GraphQL object (including the Query and the Mutation)
93
97
* It contains the proper declarations to use the [DataLoader](https://github.com/graphql-java/java-dataloader) out of the box
94
-
* The POJOs to manipulate the GraphQL objects defined in the GraphQL schema.
98
+
* The POJOs to manipulate the GraphQL objects defined in the GraphQL schema.
95
99
* These POJOs are annotated with JPA annotations. This allows you to link them to almost any database
96
100
* You can customize these annotations, with the Schema Personalization file (see below for details)
97
-
* (in a near future) It will be possible to define your own code template, to generate exactly the code you want
101
+
* (in a near future) It will be possible to define your own code template, to generate exactly the code you want
98
102
* All the necessary runtime is actually attached as source code into your project: the generated code is stand-alone. So, your project, when it runs, doesn't depend on any external dependency from graphql-java-generator.
99
103
100
104
Once all this is generated, your only work is to implement the DataFetchersDelegate interfaces. They are the link between the GraphQL schema and your data storage. As such, they are specific to your use case. A DataFetchersDelegate implementation looks like this:
@@ -140,6 +144,82 @@ public class DataFetchersDelegateTopicImpl implements DataFetchersDelegateTopic
140
144
141
145
You'll find all the info on the [server](server.html) page.
142
146
147
+
148
+
### Custom code templates
149
+
150
+
If for any reason you may need to customize the template to modify the generated code this can be donde using the parameter **tempaltes**
151
+
152
+
Here there's an exmaple of plugin configuration to use customized templates
**templates** param is a map where the key is the ID of the template to customize
196
+
and the value is a classpath entry to the resources containing the customized tempalte
197
+
198
+
Customize templates shall be provided in a depdency configured in the plugin
199
+
200
+
Both client and server templates can be customized.
201
+
202
+
The avialable template IDs that can be configured for customization are:
203
+
204
+
| ID | Scope | Default template |
205
+
| --- | --- |
206
+
| OBJECT | COMMON |[templates/object_type.vm.java](http://github.com/graphql-java-generator/graphql-maven-plugin-project/tree/master/graphql-maven-plugin-logic/src/main/resources/templates/object_type.vm.java)|
207
+
| INTERFACE | COMMON |[templates/interface_type.vm.java](http://github.com/graphql-java-generator/graphql-maven-plugin-project/tree/master/graphql-maven-plugin-logic/src/main/resources/templates/interface_type.vm.java)|
208
+
| ENUM | COMMON |[templates/enum_type.vm.java](http://github.com/graphql-java-generator/graphql-maven-plugin-project/tree/master/graphql-maven-plugin-logic/src/main/resources/templates/enum_type.vm.java)|
209
+
| UNION | COMMON |[templates/union_type.vm.java](http://github.com/graphql-java-generator/graphql-maven-plugin-project/tree/master/graphql-maven-plugin-logic/src/main/resources/templates/union_type.vm.java)|
| BATCHLOADERDELEGATE | SERVER |[templates/server_BatchLoaderDelegate.vm.java](http://github.com/graphql-java-generator/graphql-maven-plugin-project/tree/master/graphql-maven-plugin-logic/src/main/resources/templates/server_BatchLoaderDelegate.vm.java)|
215
+
| BATCHLOADERDELEGATEIMPL | SERVER |[templates/server_BatchLoaderDelegateImpl.vm.java](http://github.com/graphql-java-generator/graphql-maven-plugin-project/tree/master/graphql-maven-plugin-logic/src/main/resources/templates/server_BatchLoaderDelegateImpl.vm.java)|
216
+
| DATAFETCHER | SERVER |[templates/server_GraphQLDataFetchers.vm.java](http://github.com/graphql-java-generator/graphql-maven-plugin-project/tree/master/graphql-maven-plugin-logic/src/main/resources/templates/server_GraphQLDataFetchers.vm.java)|
217
+
| DATAFETCHERDELEGATE | SERVER |[templates/server_GraphQLDataFetchersDelegate.vm.java](http://github.com/graphql-java-generator/graphql-maven-plugin-project/tree/master/graphql-maven-plugin-logic/src/main/resources/templates/server_GraphQLDataFetchersDelegate.vm.java)|
218
+
| GRAPHQLUTIL | SERVER |[templates/server_GraphQLUtil.vm.java](http://github.com/graphql-java-generator/graphql-maven-plugin-project/tree/master/graphql-maven-plugin-logic/src/main/resources/templates/server_GraphQLUtil.vm.java)|
219
+
| PROVIDER | SERVER |[templates/server_GraphQLProvider.vm.java](http://github.com/graphql-java-generator/graphql-maven-plugin-project/tree/master/graphql-maven-plugin-logic/src/main/resources/templates/server_GraphQLProvider.vm.java)|
220
+
| SERVER | SERVER |[templates/server_GraphQLServerMain.vm.java](http://github.com/graphql-java-generator/graphql-maven-plugin-project/tree/master/graphql-maven-plugin-logic/src/main/resources/templates/server_GraphQLServerMain.vm.java)|
221
+
222
+
143
223
# Main evolutions for the near future
144
224
145
225
You'll find below the main changes, that are planned in the near future:
@@ -157,7 +237,7 @@ The Change Log is available [here](CHANGELOG.md)
157
237
158
238
# Note for contributors
159
239
160
-
This project is a maven plugin project.
240
+
This project is a maven plugin project.
161
241
162
242
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