# Merging Data Loaders in a Federated Graph Using Spring Boot

**URL:** <https://community.apollographql.com/t/merging-data-loaders-in-a-federated-graph-using-spring-boot/6588>\
**Category:** Client SDKs\
**Tags:** federation\
**Created:** [August 12, 2023, 11:35pm UTC](https://community.apollographql.com/t/merging-data-loaders-in-a-federated-graph-using-spring-boot/6588 "2023-08-12T23:35:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![earandap](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/earandap/32/4480_2.png) [@earandap](https://community.apollographql.com/u/earandap)\
**Post date:** [August 12, 2023, 11:35pm UTC](https://community.apollographql.com/t/merging-data-loaders-in-a-federated-graph-using-spring-boot/6588/1 "2023-08-12T23:35:19Z")

</div>

Hi there 👋. I’m working on implementing a batch loader in a federated graph using Spring Boot. I’m exploring consolidating the loading process for scoring and bestseller attributes in the review subgraph.

In `kotlin-graphql`, this could be solved using a `FederatedTypeResolver`, but I’m interested in understanding how to achieve the same outcome in my current setup.

Here’s the schema I’m working with:

**Product subgraph:**

```auto
type Query {
    product(id: ID!): Product
    products: [Product!]!
}

type Product @key(fields: "id") {
    id: ID!
    name: String!
    description: String
}

```

**Review subgraph:**

```auto
type Product @key(fields: "id") @extends {
    id: ID! @external
    reviews: [Review!]!
    scoring: Float!
    bestSeller: Boolean!
}

type Review {
    id: ID!,
    text: String
    starRating: Int!
}

```

I’ve implemented batch loading for both the `scoring` and `bestSeller` fields with the following code:

```auto
  @BatchMapping(typeName = "Product", field = "scoring")
  public Mono<Map<Product, Float>> scoring(List<Product> products) {
    return Mono.just(products.stream().collect(Collectors.toMap(product -> product, product -> new Random().nextFloat())));
  }

  @BatchMapping(typeName = "Product", field = "bestSeller")
  public Mono<Map<Product, Boolean>> bestSeller(List<Product> products) {
    return Mono.just(products.stream().collect(Collectors.toMap(product -> product, product -> new Random().nextBoolean())));
  }

```

My question is: Is it possible to merge these two data loaders and then use the consolidated representation to create a single resolver that can handle both the `scoring` and `bestSeller` fields?

---

<div class="post-metadata">

**Author:** ![Justin\_Gonzalez](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/justin_gonzalez/32/5359_2.png) [@Justin\_Gonzalez](https://community.apollographql.com/u/Justin_Gonzalez)\
**Post date:** [February 6, 2025, 8:48pm UTC](https://community.apollographql.com/t/merging-data-loaders-in-a-federated-graph-using-spring-boot/6588/2 "2025-02-06T20:48:28Z")

</div>


