Skip to main content

Basic Concepts

Concepts

In the Spring section, we discussed how to implement REST services with Jimmer and automatically generate client code like TypeScript.

In addition, Jimmer also supports another development mode to build GraphQL services, which is what this article series will discuss.

caution

So far, the GraphQL protocol does not support recursive queries for self-associated properties.

Therefore, it is not possible to expose functionality like recursive queries in object fetchers through GraphQL. This is a functionality sacrifice that must currently be accepted when using GraphQL.

Jimmer's support for GraphQL is based on Spring GraphQL. So the project needs to import both the Jimmer and Spring GraphQL Spring Boot starters, for example:

pom.xml
...other code omitted...

<build>
<dependencies>
<dependency>
<groupId>org.babyfish.jimmer</groupId>
<artifactId>jimmer-spring-boot-starter</artifactId>
<version>${jimmer.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-graphql</artifactId>
<version>${spring.boot.version}</version>
</dependency>
...other dependencies omitted...
</dependencies>
</build>

...other code omitted...
info

If the Jimmer entity types are also defined in the GraphQL project rather than in a separate project, the preprocessor (Annotation Processor for Java, KSP for Kotlin) should also be configured in the build script.

This has already been discussed in detail in the Generate Code article and will not be repeated here.

Spring GraphQL is a Schema-First rather than Code-First approach. Therefore, developers need to create the file src/main/resources/graphql/schema.graphqls in the project and define the GraphQL schema in it.

This file is a requirement of Spring GraphQL. The GraphQL schema content is a standard language that is unrelated to Jimmer, so this article will not explain it. Please refer to the GraphQL Schema in the example.

Notes

caution

In the current version, there is a limitation that when providing GraphQL services, simple calculated properties based on SQL should NOT be used.