Spring Boot GraphQL Subscription: A filter or servlet in the current chain does not support asynchronous operations

121 views Asked by At

I am encountering an issue with a Spring Boot GraphQL application that uses subscriptions. When attempting to hit the endpoint, I am receiving the following error:

java.lang.IllegalStateException: A filter or servlet of the current chain does not support asynchronous operations.
...

Here is a brief overview of the relevant components in my application: Dependencies in pom.xml:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-graphql</artifactId>
</dependency>
<dependency>
    <groupId>com.graphql-java-kickstart</groupId>
    <artifactId>graphql-spring-boot-starter</artifactId>
    <version>15.1.0</version>
</dependency>

GraphQL Resolver:

@Component
public class GraphQLResolver implements GraphQLQueryResolver,GraphQLSubscriptionResolver {
    public Publisher<Comment> allComments() {
       List<Comment> comments = Arrays.asList(restTemplate().getForObject(apiUrl, Comment[].class));
       return Flux.fromIterable(comments);
    }
}

GraphQL Schema:

schema {
    subscription: Subscription
}

type Subscription {
    allComments: Comment
}

type Comment {
    postId: String
    id: String
    name: String
    email: String
    body: String
}

1

There are 1 answers

0
Brian Clozel On

Your application is using two different and incompatible starters for supporting GraphQL in Spring applications. The first one, "com.graphql-java-kickstart:graphql-spring-boot-starter" is managed by the GraphQL Java Kickstart team and the second one "org.springframework.boot:spring-boot-starter-graphql" is managed by the Spring team.

I would suggest choosing only one of those as they provide different opinions and ways to implement GraphQL services with Spring.