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

Documentation and dynamic cache control feature of Apollo leverages incompatible GraphQl type interface. #7845

Closed
corbin-mosher opened this issue Mar 5, 2024 · 4 comments · Fixed by #7848

Comments

@corbin-mosher
Copy link
Contributor

corbin-mosher commented Mar 5, 2024

Issue Description

The ApolloServer documentation provides an example of setting cache-control information for a resolver dynamically. This example works in code, but it has a TypeScript error.

Property cacheControl does not exist on type GraphQLResolveInfo.

The info object leverages the type of GraphQLResolveInfo. This type does not have a cacheControl field defined on it.

I am not sure if this is an error with the graphql package and its types, or if its something @apollo/server and other third party libraries like typed-graphql are just expanding the existing GraphQl object with.

I was hoping a maintainer of @apollo/server would be familiar with how this field works and were the hang up is. Is it safe to follow the documentation's example? Should I just be altering the GraphQl libraries GraphQLResolveInfo type?

Link to Reproduction

Reproduction link

Reproduction Steps

Just launch the repro link and view the fact the type information does not exist for cacheControl.

Screen Recording 2024-03-05 at 1 38 49 PM

@corbin-mosher
Copy link
Contributor Author

Follow up on this. We dug some more and uncovered this section of the documentation which mentions:

Instead, @apollo/cache-control-types provides a GraphQLResolveInfoWithCacheControl interface that you can cast info to (if you don't want run-time validation), or if you do want runtime validation, you can use the maybeCacheControlFromInfo and cacheControlFromInfo functions.

import { cacheControlFromInfo } from '@apollo/cache-control-types';

// ...
  someField(parent, args, context, info) {
    cacheControlFromInfo(info).setCacheHint({ maxAge: 100 });
  }

So I guess my request would be that the other locations in the Apollo documentation that mention info.cacheControl could hopefully be updated to instead use examples with cacheControlFromInfo.

If the docs are open source, I could also propose a PR that does that if needed.

@glasser
Copy link
Member

glasser commented Mar 6, 2024

Good catch — the TS-specific improvements from AS4 didn't make it to that page. If you'd like to submit a PR, the file is https://github.com/apollographql/apollo-server/blob/main/docs/source/performance/caching.md

@corbin-mosher
Copy link
Contributor Author

Good catch — the TS-specific improvements from AS4 didn't make it to that page. If you'd like to submit a PR, the file is https://github.com/apollographql/apollo-server/blob/main/docs/source/performance/caching.md

Created the following docs PR,

#7848

glasser pushed a commit that referenced this issue Mar 19, 2024
…#7848)

## Background / Context

Fixes #7845 

## Goals

- Ensure documentation of accessing the extended `cacheControl`
information on GraphQL's info object does not contain any TypeScript
errors

## Changes

- Added import statements to the code examples for `import {
cacheControlFromInfo } from '@apollo/cache-control-types'`
- Leverage `cacheControlFromInfo` in code examples
- Updated description of what provides `info.cacheControl` to reference
the documentation for the cache control plugin
Copy link
Contributor

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
For general questions, we recommend using StackOverflow or our discord server.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants