Skip to content

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: /graphql

2. 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

PropertyDefaultDescription
apigen.graphql.enabledfalseEnable GraphQL support
apigen.graphql.path/graphqlGraphQL endpoint path
apigen.graphql.tracing.enabledfalseEnable Apollo tracing
apigen.graphql.http.enabledtrueEnable HTTP controller

Released under the MIT License.