There is no GraphQLFilter class in Spring Boot or Spring for GraphQL. The idea behind the name, a hook that runs before and after each GraphQL request, is implemented by WebGraphQlInterceptor, which you register as a bean. It lets you inspect the request, add headers or context, and change the response, and it is the correct place for logging, authentication checks and metrics.
This article explains the real extension points, because code copied from older posts that references GraphQLFilter, GraphQLRequest or interceptResponse will not compile.
Spring for GraphQL offers several layers where you can intercept traffic. Choose the layer that matches what you need.
| Need | Right tool | Layer |
|---|---|---|
| Read headers, log requests, add context or response extensions | WebGraphQlInterceptor | GraphQL over HTTP or WebSocket |
| Raw HTTP concerns (CORS, rate limiting, request ids) | Servlet Filter or WebFilter | HTTP |
| Authentication and authorization | Spring Security | HTTP and method level |
| Query depth or complexity limits, tracing | graphql-java Instrumentation | Execution engine |
| Per-field cross-cutting logic | DataFetcher wrappers or @PreAuthorize | Field |
The interface has one method that receives the request and a chain. Calling chain.next(request) continues processing and returns a Mono<WebGraphQlResponse> that you can transform.
Spring Boot detects every WebGraphQlInterceptor bean automatically and applies it to the HTTP and WebSocket transports. Use @Order to control the order of several interceptors. This works the same in Spring MVC and WebFlux applications, even though the signature uses Reactor types.
Avoid logging the full query document or variables in production: they can contain personal data and tokens.
A common use is copying a header into the GraphQL context so controllers can read it.
@ContextValue reads the value back from the GraphQL context inside the controller method.
Use response.transform(...) to add extensions to the result. The builder returns a new response, because responses are immutable.
The client then receives {"data": ..., "extensions": {"requestId": "..."}}.
Do not implement authentication by hand in an interceptor. Secure the HTTP endpoint with Spring Security and protect resolvers with method security such as @PreAuthorize. Throwing a plain SecurityException from an interceptor is not a supported pattern and will surface as an internal error.
To block abusive queries, register graphql-java instrumentations as beans. Spring Boot adds every Instrumentation bean to the engine.
For metrics and tracing, Spring Boot with Actuator already records GraphQL timings through Micrometer when the observation support is on the classpath, so you often do not need custom timing code.
GraphQLFilter a real class?No. It does not exist in Spring Boot or Spring for GraphQL. Use WebGraphQlInterceptor for GraphQL-aware hooks or a servlet Filter for plain HTTP logic.
Filter with GraphQL?Yes. The GraphQL endpoint is an ordinary HTTP endpoint, so a Filter or OncePerRequestFilter runs before it. A filter sees raw HTTP only and knows nothing about operations or fields.
Prefer mapping exceptions to GraphQL errors with @GraphQlExceptionHandler. Inside an interceptor, you can return a response with errors by building one from the request rather than throwing.
Interceptors apply to requests received over HTTP and WebSocket. For WebSocket connections there is a separate WebSocketGraphQlInterceptor for connection-level events.
Spring has no GraphQLFilter. Use WebGraphQlInterceptor to log, enrich the context and add response extensions, a servlet filter for pure HTTP concerns, Spring Security for authentication and authorization, and graphql-java instrumentation for depth and complexity limits. Choosing the right layer keeps cross-cutting logic small and secure.