How would you add a GraphQL API to an existing Spring Boot REST service?

Adding a GraphQL API to an existing Spring Boot REST service means layering a schema-driven query interface alongside the existing REST endpoints, typically using the spring-boot-starter-graphql module built on GraphQL Java.

Key Points

Example

An existing ProductService used by REST controllers is reused unchanged; a new @QueryMapping method named "product" calls the same service to resolve GraphQL queries, so no business logic is duplicated between the REST and GraphQL layers.

type Query {
    product(id: ID!): Product
}

type Product {
    id: ID!
    name: String!
    price: Float!
}
@Controller
public class ProductGraphQLController {

    private final ProductService productService;

    @QueryMapping
    public Product product(@Argument String id) {
        return productService.findById(id);
    }
}

Interview Tip

A concise interview answer is

I'd add spring-boot-starter-graphql, define the schema in a .graphqls file, and write data fetcher controllers with @QueryMapping and @MutationMapping that call into the same service layer the REST controllers already use. That way GraphQL and REST coexist without duplicating business logic.

Last updated: 11 November 2026

Previous question: How would a Spring Boot application switch between multiple data sources at runtime based on the request?

Next question: Describe how you would secure sensitive data in a Spring Boot application that is accessed by multiple users with different roles.

More Spring Boot - Level III (Scenario Based) interview questions

All Spring Boot - Level III (Scenario Based) questions