Skip to content

Deduplication rest call to downstream services like Apollo RESTDataSource does #4315

Closed
@matdurand

Description

@matdurand

This feature request is coming from a comparaison I'm doing between GraphQL Mesh and a custom Apollo server to front a REST api. What Apollo RESTDataSource is doing, is deduplicating requests to downstream rest services when the same request is needed more than once to build a single graphql response.

The process is described in this article: https://khalilstemmler.com/blogs/graphql/how-apollo-rest-data-source-caches-api-calls/
This is how RESTDataSource is implemented: https://github.com/apollographql/apollo-server/blob/main/packages/apollo-datasource-rest/src/RESTDataSource.ts#L270

Right now, GraphQL mesh is doing the same request more than once. For example, if I query for blog articles and authors, and the same author has multiple article, it's going to query the author endpoint for each article.

I created a repo to replicate the issue: https://github.com/matdurand/graphql-mesh-docs-first-gateway
You can "asdf install", or use node 17.4.0, and check the readme to run the project.
Then just execute this request:

{
  assets {
    id
    publisher {
      id
      name
    }
  }
}

and you should see in the logs that it's calling the same publisher rest endpoint 2 times, because the first asset is by the same publisher.

[3] 🕸️ - PublishersService - http: Call GET http://localhost:3003/publishers/11?
[3] 🕸️ - PublishersService - http: Call GET http://localhost:3003/publishers/11?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions