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

Errors using shared documentStore with Redis KeyvAdapter #7471

Closed
yamaha252 opened this issue Mar 27, 2023 · 3 comments · Fixed by #7433
Closed

Errors using shared documentStore with Redis KeyvAdapter #7471

yamaha252 opened this issue Mar 27, 2023 · 3 comments · Fixed by #7433

Comments

@yamaha252
Copy link

yamaha252 commented Mar 27, 2023

Issue Description

After enabling Redis KeyvAdapter for documentStore there are errors on receiving requests.

TypeError: Cannot read properties of undefined (reading 'body')
  File "/opt/app/node_modules/graphql/language/location.js", line 23, col 30, in getLocation
    for (const match of source.body.matchAll(LineRegExp)) {
  File "/opt/app/node_modules/graphql/error/GraphQLError.js", line 128, col 39, in <anonymous>
    (0, _location.getLocation)(loc.source, loc.start),
  File "<anonymous>", in Array.map
  File "/opt/app/node_modules/graphql/error/GraphQLError.js", line 127, col 25, in new GraphQLError
    : nodeLocations.map((loc) =>
  File "/opt/app/node_modules/graphql/error/locatedError.js", line 26, col 10, in locatedError
    return new _GraphQLError.GraphQLError(originalError.message, {
  File "/opt/app/node_modules/graphql/execution/execute.js", line 503, col 54, in <anonymous>
    const error = (0, _locatedError.locatedError)(
  File "node:internal/process/task_queues", line 95, col 5, in process.processTicksAndRejections
  File "/opt/app/node_modules/@apollo/server/dist/cjs/requestPipeline.js", line 223, col 37, in execute
    const resultOrResults = await (0, incrementalDeliveryPolyfill_js_1.executeIncrementally)({
  File "/opt/app/node_modules/@apollo/server/dist/cjs/requestPipeline.js", line 158, col 32, in processGraphQLRequest
    const fullResult = await execute(requestContext);
  File "/opt/app/node_modules/@apollo/server/dist/cjs/ApolloServer.js", line 615, col 16, in internalExecuteOperation
    return await (0, requestPipeline_js_1.processGraphQLRequest)(schemaDerivedData, server, internals, requestContext);

The service works in multiple instances with a shared redis database.

NodeJS v18.15.0
Apollo server is running as an express middleware.

Dependencies:

    "@apollo/server": "^4.5.0",
    "@apollo/utils.keyvadapter": "^2.0.1",
    "@graphql-tools/schema": "^9.0.17",
    "@keyv/redis": "^2.5.6",
    "compression": "^1.7.4",
    "cors": "^2.8.5",
    "express": "^4.18.2",
    "graphql": "^16.6.0",
    "graphql-import-node": "^0.0.4",
    "graphql-redis-subscriptions": "^2.4.0",
    "graphql-subscriptions": "^2.0.0",
    "graphql-ws": "^5.12.0",
    "helmet": "^6.0.1",
    "keyv": "^4.5.2",
    "ws": "^8.13.0"

Link to Reproduction

n/a

Reproduction Steps

  const app = express();
  const schema = makeExecutableSchema({
    typeDefs,
    resolvers
  });

  const httpServer = http.createServer(app);
  const wsServer = new WebSocketServer({
    server: httpServer,
    path,
  });

  const serverCleanup = useServer({
    schema,
    context: (ctx) => {
      const accessToken = ctx.connectionParams?.accessToken?.toString();
      return new Context({
        accessToken,
        cache: apolloServer.cache,
        mongoClient,
      });
    },
  }, wsServer);


  const keyvCache = new KeyvAdapter(new Keyv(REDIS_ADDRESS));
  const apolloServer = new ApolloServer<Context>({
    cache: keyvCache,
    documentStore: keyvCache,
    schema,
    plugins: [
      ApolloServerPluginDrainHttpServer({httpServer}),
      {
        async serverWillStart() {
          return {
            async drainServer() {
              await serverCleanup.dispose();
            },
          };
        },
      },
    ],
  });

  await apolloServer.start();

  app.use(
    path,
    cors({
      maxAge: 84600
    }),
    helmet({
      contentSecurityPolicy: production
    }),
    compression(),
    json(),
    expressMiddleware(apolloServer, {
      context: async ({req}) => {
        const accessToken = (req.headers.authorization || '')?.split(' ').pop();
        return new Context({
          accessToken,
          cache: apolloServer.cache,
          mongoClient,
        });
      },
    }),
  );

  httpServer.listen({port}, () => {
    console.log(`Apollo Server on http://localhost:${port}${path}`);
  });
@trevor-scheer
Copy link
Member

Thanks for the detailed report. To save you time in the future, I recommend searching open issues and pull requests before opening one yourself.

This will be resolved soon via #7433

I recommend reading my comments there to understand the caveats of doing this as well.

@yamaha252
Copy link
Author

It seems I checked not so carefully :)
Sorry for disturbing!

@github-actions
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 27, 2023
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