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

[keyvaluecache] Cannot use 'in' operator to search for 'Symbol(prefixesAreUnnecessaryForIsolation)' in bounded #239

Closed
junajan opened this issue Dec 13, 2022 · 3 comments

Comments

@junajan
Copy link

junajan commented Dec 13, 2022

Hi,
in the last version of @apollo/utils.keyvaluecache package there is this line return prefixesAreUnnecessaryForIsolationSymbol in c; which breaks our apollo server instance (tested on node v16 and v18).

It throws this error:

TypeError: Cannot use 'in' operator to search for 'Symbol(prefixesAreUnnecessaryForIsolation)' in bounded
    at Function.prefixesAreUnnecessaryForIsolation (/app/node_modules/@apollo/server/node_modules/@apollo/utils.keyvaluecache/dist/PrefixingKeyValueCache.js:27:57)
    at new PrefixingKeyValueCache (/app/node_modules/@apollo/server/node_modules/@apollo/utils.keyvaluecache/dist/PrefixingKeyValueCache.js:9:36)
    at new ApolloServer (/app/node_modules/@apollo/server/dist/cjs/ApolloServer.js:110:28)

I was testing it on @apollo/server version 4.2.1 which creates object PrefixingKeyValueCache like this:

new utils_keyvaluecache_1.PrefixingKeyValueCache(config.persistedQueries?.cache ?? this.cache, requestPipeline_js_1.APQ_CACHE_PREFIX),

With these params:

console.log(
  config.persistedQueries?.cache, // undefined
  this.cache, //  bounded
  requestPipeline_js_1.APQ_CACHE_PREFIX //  apq:
); 

Where constructor on line 22:

if (PrefixingKeyValueCache.prefixesAreUnnecessaryForIsolation(wrapped)) {

Uses mentioned function prefixesAreUnnecessaryForIsolation called with "bounded" string in params which turns into faulty code Symbol(prefixesAreUnnecessaryForIsolation) in "bounded".

Is it a problem of @apollo/server or of @apollo/utils.keyvaluecache? With previous version of utils.keyvaluecache (v2.0.1) everything worked fine.

@trevor-scheer
Copy link
Member

trevor-scheer commented Dec 13, 2022

Hey @junajan, thanks for opening an issue and providing the details of the error.

cache: "bounded" is the default behavior for AS4 and you can just remove that configuration altogether.

However, we did run into this issue internally so @glasser merged a fix (apollographql/apollo-server#7241) which re-adds support for cache: "bounded" in AS4.2.2 AS4.3.0 (edited - thanks @glasser) (note that it's still a no-op, just no longer broken if you choose to do that).

So your 2 options are: drop the configuration (which I'd recommend) or update to latest AS version (or both!)

I like to mention that TypeScript prevents these kinds of errors. If you prefer to use JavaScript, you can still leverage the benefits of TypeScript in your editor VERY easily. A tsconfig like this at the root of your project or simply writing // @ts-check at the top of your files are a couple ways you can benefit from our typings without actually using TS in your project.

// tsconfig.json
{
  "compilerOptions": {
    "target": "ESNext",
    "lib": ["ESNext"],
    "module": "ESNext",
    "moduleResolution": "node",
    "allowJs": true,
    "checkJs": true,
    "noEmit": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true,
    "resolveJsonModule": true
  }
}

@glasser
Copy link
Member

glasser commented Dec 13, 2022

(the fix is actually v4.3.0)

@junajan
Copy link
Author

junajan commented Dec 14, 2022

Nice! Thank you both for such a quick response 👍
And thank you for that idea with tsconfig, will give it a try.

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