apollographql / router

A configurable, high-performance routing runtime for Apollo Federation 🚀
https://www.apollographql.com/docs/router/
Other
813 stars 271 forks source link

Long request times for large queries #6121

Closed NobleUpFront closed 1 month ago

NobleUpFront commented 1 month ago

Describe the bug

I have a problem, when queying data that is used to build a CSV file. The query takes for 1000+ elements, around 600ms for the subgraph to complete, but the time for the Apollo Router, to receive this information back, is for 500 elements around 15 seconds, and 1000+ elements its around 30 seconds.

Output

Node.js GraphQL model: More than 25 fields, and 4 objects, that also contains quite a few fields: (small sample)

@ObjectType()
export class Foo{
  @Field({ nullable: true })
  @prop({ required: true })
  x!: string;

  @prop({ required: true })
  y!: string;

  ... 25-35 more fields

Resolver:

@Query(() => [Foo])
  @UseMiddleware(validation)
  async allFooToFrom(
    @Args() { h, i, k }: AllFooArgs,     
    @Ctx() context: any
  ): Promise<Foo[]> {
    try {
      let foo: Foo[] = [];

      ... 340 ms ...

      return foo;
    } catch (error) {
      throw new Error(`Error fetching foo: ${error}`);
    }
  }

Test for 1220 elements (340 ms for service to complete)

Fetch call receive by Router: {"timestamp":"2024-10-04T12:33:37.229346071Z","level":"DEBUG","trace_id":"x","span_id":"x","message":"our JSON body"}

Call when subgraph is finished and returns to router: {"timestamp":"2024-10-04T12:34:06.229539721Z","level":"TRACE","trace_id":"x","span_id":"x"}

As you can see, the time difference is around 30 seconds, which is way to long.

What am I doing wrong here?

Apollo Router version 1.56