title: NestJs Apollo GraphQL federation and responseCachePlugin
body: <p>I'd like to cache my expensive GQL queries on the server-side with nestjs</p>
  <p>I've followed <a href="https://docs.nestjs.com/graphql/plugins#using-external-plugins" rel="nofollow noreferrer">https://docs.nestjs.com/graphql/plugins#using-external-plugins</a> and then <a href="https://www.apollographql.com/docs/apollo-server/performance/caching/#caching-with-responsecacheplugin-advanced" rel="nofollow noreferrer">https://www.apollographql.com/docs/apollo-server/performance/caching/#caching-with-responsecacheplugin-advanced</a></p>
  <p>I've also seen <a href="https://github.com/nestjs/graphql/issues/443#issuecomment-599445224" rel="nofollow noreferrer">https://github.com/nestjs/graphql/issues/443#issuecomment-599445224</a> which suggests that it should work as expected</p>
  <p>I am using apollo federation</p>
  <p>the problem I have is that it works (more or less) correctly if I add the responseCachePlugin inside the subgraph</p>
  <p>However, when I try to use the responseCachePlugin at the gateway (i.e at the federation service), it simply is ignored: all the requests always hit the downstream subgraphs</p>
  <p>package.json</p>
  <pre><code>&quot;dependencies&quot;: {
      ...
      &quot;@nestjs/common&quot;: &quot;^7.6.18&quot;,
      &quot;@nestjs/core&quot;: &quot;^7.6.18&quot;,
      &quot;@nestjs/graphql&quot;: &quot;^7.11.0&quot;,
      &quot;@nestjs/platform-express&quot;: &quot;^7.6.18&quot;,
      &quot;apollo-server-express&quot;: &quot;^2.25.0&quot;,
      &quot;apollo-server-plugin-response-cache&quot;: &quot;^0.9.0&quot;,
      ...
      &quot;graphql&quot;: &quot;^15.5.0&quot;,
      &quot;graphql-subscriptions&quot;: &quot;^1.2.1&quot;,
      &quot;graphql-type-json&quot;: &quot;^0.3.2&quot;,
      ...
  }
  </code></pre>
  <p>Note : using 0.9.0 to be compatible with 2.25.0 (not yet the possibility to move to latest 3.2.0)</p>
  <p>Then, in my &quot;main&quot; module of the gateway I have :</p>
  <pre><code>GraphQLGatewayModule.forRootAsync({
        imports: [
          LoggerModule,
          BuildServiceModule,
          ConfigModule.register(GwEnvVar, GW_DEFAULT_CONFIG),
        ],
        inject: [ConfigService, GATEWAY_BUILD_SERVICE],
        useFactory: (configService: ConfigService&lt;GwEnvVar&gt;) =&gt; ({
          cors: true,
          server: {
            introspection:
              configService.env.NODE_ENV === NodeEnv.PRODUCTION ? false : true,
            playground: true,
            cacheControl: {
              defaultMaxAge: 5,
            },
            plugins: [responseCachePlugin()],
          },
          gateway: getSupergraphSchema('schema.gql', configService.env),
        }),
      }),
    ],
  })
  export class GraalModule {}
  </code></pre>
  <p>The app starts correctly but, as I already said, every request hit the downstream subgraphs</p>
  <p>Also note that if I put the exact same config directly in subgraphs, then the resolvers are not hit anymore (however, it means the cache is done inside the subgraph which is NOT what I'd like)</p>
  <p>If not providing directly a solution, does anyone have a pointer to explain how caching is supposed to work with apollo federation (beyond the minimalist doc <a href="https://www.apollographql.com/docs/apollo-server/performance/caching/#caching-with-responsecacheplugin-advanced" rel="nofollow noreferrer">https://www.apollographql.com/docs/apollo-server/performance/caching/#caching-with-responsecacheplugin-advanced</a> and <a href="https://www.apollographql.com/docs/federation/performance/caching/" rel="nofollow noreferrer">https://www.apollographql.com/docs/federation/performance/caching/</a>) ?</p>