# Can I use "mergeResolvers" from graphql-tools in BuildSubgraphSchema

**URL:** <https://community.apollographql.com/t/can-i-use-mergeresolvers-from-graphql-tools-in-buildsubgraphschema/5688>\
**Category:** Schema Design\
**Tags:** federation\
**Created:** [February 10, 2023, 9:11am UTC](https://community.apollographql.com/t/can-i-use-mergeresolvers-from-graphql-tools-in-buildsubgraphschema/5688 "2023-02-10T09:11:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pierre\_Biver](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/pierre_biver/32/3860_2.png) [@Pierre\_Biver](https://community.apollographql.com/u/Pierre_Biver)\
**Post date:** [February 10, 2023, 9:11am UTC](https://community.apollographql.com/t/can-i-use-mergeresolvers-from-graphql-tools-in-buildsubgraphschema/5688/1 "2023-02-10T09:11:03Z")

</div>

Hello,

I’m in the process of migrating our service to Apollo Federation and when calling the function “buildSubgraphSchema”, I want to pass my resolvers and merge them together as in a real world you would have them split across your code. Something like this:

```auto
buildSubgraphSchema({
      resolvers: mergeResolvers(myListOfResolvers),
})

```

I’m using “@graphql-tools/merge” with the mergeResolvers function but when running my test the resolvers don’t seems to be called. Can I use this function ? or is there something similar to merge multiple resolvers together ? I found the documentation provided very light regarding this topic.

---

<div class="post-metadata">

**Author:** ![watson](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/watson/32/2053_2.png) [@watson](https://community.apollographql.com/u/watson)\
**Post date:** [February 13, 2023, 7:43pm UTC](https://community.apollographql.com/t/can-i-use-mergeresolvers-from-graphql-tools-in-buildsubgraphschema/5688/2 "2023-02-13T19:43:17Z")

</div>

Hey @Pierre_Biver, I would love to talk more about this live! We recently started up an [Apollo Discord](https://discord.com/graphos) for more live interactions and if you head over there, feel free to ping me directly (@watson) and we can dig in deeper. I don’t know if `mergeResolvers` would work or not, but I don’t see any reason why it wouldn’t.

Can you help me understand if there is anything special you are doing with `mergeResolvers`? You might have a pattern with your resolvers where the `Query` resolver is split over multiple files, in which case I’ve just see `lodash/merge` get used to do this. The legacy SpaceXLand API has a good [example](https://github.com/SpaceXLand/api/blob/master/src/schema/resolvers.ts) and that could be provided to `buildSubgraphSchema`.

If it’s to just bring together a set of resolvers, you could consider exposing them in a single `index` that is exported and used in `buildSubgraphSchema`. I typically favor this pattern because of it’s simplicity, but it does mean having to add the resolver into the `index` for it to be added. (I’m assuming you’re doing something similar to create `myListOfResolvers`).

For example, you can co-locate all of your resolvers into a `resolvers` folder that has an `index` ([example](https://github.com/apollographql/subgraph-template-typescript-apollo-server-boilerplate/tree/main/src/resolvers)):

```typescript
import { Query } from "./Query";
import { Mutation } from "./Mutation";
import { Thing } from "./Thing";

const resolvers = {
  ...Query,
  ...Mutation,
  ...Thing,
};

export default resolvers;

```

Then in your server code, you would just import those resolvers ([example](https://github.com/apollographql/subgraph-template-typescript-apollo-server-boilerplate/blob/main/src/index.ts#L11)):

```typescript
import resolvers from "./resolvers";
...
const schema = new ApolloServer({
  schema: buildSubgraphSchema({ resolvers }),
});

```
