APiGen GraphQL Module
GraphQL API layer alternative to REST for APiGen applications.
Features
- Schema Building: Fluent API for constructing GraphQL schemas
- DataLoader Support: N+1 query prevention with batched loading
- Error Handling: RFC 7807-aligned error responses
- Context Management: Request-scoped context with user ID and locale
- HTTP Endpoint: Ready-to-use GraphQL controller
Quick Start
1. Enable GraphQL
yaml
apigen:
graphql:
enabled: true
path: /graphql2. Define Schema
java
@Configuration
public class GraphQLConfig {
@Bean
public GraphQLSchema graphQLSchema(ProductService productService) {
return SchemaBuilder.newSchema()
.type("Product")
.field("id", GraphQLID, true)
.field("name", GraphQLString, true)
.endType()
.query("products")
.returnsList("Product")
.fetcher(env -> productService.findAll())
.endQuery()
.build();
}
}Configuration Properties
| Property | Default | Description |
|---|---|---|
apigen.graphql.enabled | false | Enable GraphQL support |
apigen.graphql.path | /graphql | GraphQL endpoint path |
apigen.graphql.tracing.enabled | false | Enable Apollo tracing |
apigen.graphql.http.enabled | true | Enable HTTP controller |