# Generating only the necessary part of the federated schema in codegen

**URL:** <https://community.apollographql.com/t/generating-only-the-necessary-part-of-the-federated-schema-in-codegen/5878>\
**Category:** General\
**Tags:** federation\
**Created:** [March 6, 2023, 7:55am UTC](https://community.apollographql.com/t/generating-only-the-necessary-part-of-the-federated-schema-in-codegen/5878 "2023-03-06T07:55:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![killjoy2013](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/killjoy2013/32/2861_2.png) [@killjoy2013](https://community.apollographql.com/u/killjoy2013)\
**Post date:** [March 6, 2023, 7:55am UTC](https://community.apollographql.com/t/generating-only-the-necessary-part-of-the-federated-schema-in-codegen/5878/1 "2023-03-06T07:55:39Z")

</div>

Hi,  
Using Apollo Federation 2. Using graphql-request for syncronous communication between subgraphs.  
In one of my subgraph (food) I’m using codegen to generate graphql types using supergraph;

codegen.ts

```ts
import { CodegenConfig } from '@graphql-codegen/cli';

const config: CodegenConfig = {
  schema: '../router/supergraph-schema.graphql',
  documents: ['./src/gql_definitions/queries.ts'],
  ignoreNoDocuments: true,
  generates: {
    './src/gql/': {
      preset: 'client',
      plugins: [],
    },
  },
};

export default config;

```

My query is;

```ts
import { graphql } from '../gql/gql';

export const CITY = graphql(`
  query City($cityId: Int!) {
    city(id: $cityId) {
      id
      name
      population
    }
  }
`);

```

finally, below files created successfully;

```auto
./gql/fragment-masking.ts
./gql/gql.ts
./gql/graphql.ts
./gql/index.ts

```

However, all the super schema entities are generated in `graphql.ts`. This causes unnecessary builds of my food microservice just because of some changes which are not related to my food service, it’s using only city query. In a monorepo environment, I’m trying to save the microservices from unnecessary builds.

Is it possible to generate only the needed part of the schema? Or any other suggestion?

I love graphql codegenerator, thank you all for it 😄

---

<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:49pm UTC](https://community.apollographql.com/t/generating-only-the-necessary-part-of-the-federated-schema-in-codegen/5878/2 "2025-02-06T20:49:19Z")

</div>


