Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request - be able to tell if API was resolved by memory, cache, or source #204

Open
dragonfriend0013 opened this issue Oct 16, 2018 · 3 comments

Comments

@dragonfriend0013
Copy link

I would like to be able to tell what resolved an API call. This can currently be resolved by either the in-memory cache, and external cache, or the actual source. This is needed for a billing log I am needing to write and I accumulate the data as the request is being processed (in my datasource code). This could be a feature that is 'turned on' somehow, so that users that do not need the feature will not enable it.

@sbrichardson
Copy link

I was thinking about this topic recently. This would likely be a combination of things correct? Since each field is resolved independently (potentially). To handle the calculation, which could be based off more than source, but query time, transfer bandwidth etc. did you have any ideas on the output format? To get a precise tracking total, I guess you could have a per field tracking object, similar to how the apollo engine / tracing api works.

Interested in thoughts on this topic in general.

@dragonfriend0013
Copy link
Author

dragonfriend0013 commented Oct 16, 2018 via email

@jbaxleyiii jbaxleyiii transferred this issue from apollographql/apollo-server Jul 8, 2019
@trevor-scheer trevor-scheer transferred this issue from apollographql/apollo-feature-requests May 10, 2023
@LadghemSaid
Copy link

You can do that already with a simple trick overide the trace function and check if it has the age header in the response

  protected override async trace<TResult>(
    url: URL,
    request: RequestOptions,
    fn: () => Promise<any>,
  ): Promise<TResult> {
    if (process.env.NODE_ENV === "development") {
      const startTime = Date.now();
      try {
        const res = await fn();
        if (!res?.response.headers.get("age")) {
          const duration = Date.now() - startTime;
          const label = `${this.currentReq.method || "GET"} ${this.baseURL}${this.currentReq.params.toString()}`;
          logger.info(`${label} (${duration}ms)`);
        }
        return res;
      } catch (err) {
        logger.error(err);
      }
    }
    return fn();
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants