-
Notifications
You must be signed in to change notification settings - Fork 50
server
This project is a maven plugin, which makes it easy to work in Java with graphQL in a schema first approach.
In server mode, the graphql-maven-plugin reads a graphqls schema, and generated the maximum of boilerplate code. That is, it generates:
- When in a jar maven project, the main class to start a Spring Boot application
- When in a war maven project, the servlet configuration to be embedded in a war package. It can then be deployed in any standard application server
- Almost all the Spring components to wire the whole stuff
- The interfaces (DataFetchersDelegate) for the classes that are specific to the application context (see below)
- The POJOs to manipulate the GraphQL objects defined in the GraphQL schema.
- These POJOs are annotated with JPA annotations. This allows to link them to almost any database
- You can customize these annotations, with the Schema Personalization file (see below for details)
- (in a near future) It will be possible to define your own code template, to generate exactly the code you want
Please note that the generated code uses dataloader to greatly improve the server's performances. See https://github.com/graphql-java/java-dataloader.
Once all this is generated, you'll have to implement the DataFetchersDelegate interfaces. The DataFetchersDelegate implementation is the only work that remains on your side. They are the link between the GraphQL schema and your data storage. See below for more details.
Depending on your use case, you can set the maven packaging to jar or war, in your pom. This changes the generated code. But your specific code is exactly the same. That is: you can change the packaging at any time, and it will still produce a ready-to-go product without any other modification from you.
Below you'll find:
- A sample pom to start with
- The explanation about the DataFetchersDelegate interfaces you'll have to implement.
The parameters for the server are stored in the application.properties file.
You can have a look at this file, in the given server samples. It's a standard spring boot configuration file, so you'll find all the needed information on the net.
If you want to expose your Spring Boot app in https, take a look at the doc on the net. All parameters will go in the application.properties. For instance, Thomas Vitale provides a doc for that.
The important parameter is: server.port (for instance server.port = 8180), which determines the app port, when running as a spring boot app, that is, when it's packaged as a jar.
The path depends on the way the GraphQL is run:
-
If packaged as a jar: the path is /graphql
-
If packaged as a war: the paths is /{WebAppContext}/graphql
Creating a first app (non spring)
Connect to more than one GraphQL servers
Easily execute GraphQL requests with GraphQL Repositories
Access to an OAuth2 GraphQL server
How to personalize the client app
Howto personalize the generated code
Client migration from 1.x to 2.x
Implement an OAuth2 GraphQL server
Howto personalize the generated code
Server migration from 1.x to 2.x