Skip to content

Apollo Server 2 engine reporting error: o.request.headers is not iterable #1301

@BHesseldieck

Description

@BHesseldieck

Hey guys,

we are running into an issue with apollo-server-lambda 2 (RC). Unfortunately it does not report to our engine dashboard and even throws an error when deployed (on local everything works fine). Google didn't provide any hints to a solution. We are deploying the lambda using the Serverless framework.

The returned error on any query is:

{
  "errors": [
    {
      "message": "o.request.headers is not iterable",
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "stacktrace": [
            "TypeError: o.request.headers is not iterable",
            "    at EngineReportingExtension.requestDidStart (/var/task/node_modules/apollo-engine-reporting/dist/extension.js:28:50)",
            "    at handleDidStart.ext (/var/task/node_modules/graphql-extensions/dist/index.js:14:70)",
            "    at extensions.forEach.extension (/var/task/node_modules/graphql-extensions/dist/index.js:60:32)",
            "    at Array.forEach (<anonymous>)",
            "    at GraphQLExtensionStack.handleDidStart (/var/task/node_modules/graphql-extensions/dist/index.js:59:25)",
            "    at GraphQLExtensionStack.requestDidStart (/var/task/node_modules/graphql-extensions/dist/index.js:14:21)",
            "    at doRunQuery (/var/task/node_modules/apollo-server-core/dist/runQuery.js:41:42)",
            "    at Promise.resolve.then (/var/task/node_modules/apollo-server-core/dist/runQuery.js:13:41)",
            "    at <anonymous>"
          ]
        }
      }
    }
  ]
}

Our handler looks like the following:

const server = new ApolloServer({
  typeDefs,
  resolvers,
  trace: true,
  introspection: true,
  debug:true,
  cacheControl: { defaultMaxAge: 240 },
  // engine: {
  //   apiKey: process.env.engineKey,
  //   // FIXME: Do not know why we need these below properties,
  //   // If not provided, application doesn't start!!
  //   privateHeaders: true,
  //   privateVariables: true,
  // },
  context: ({ event, context }) => ({
    headers: event.headers,
    functionName: context.functionName,
    event,
    context,
    loaders, // Data Loaders to avoid extra mongo queries
    language: event.headers && event.headers['Accept-Language'] && event.headers['Accept-Language'].length === 2 ? event.headers['Accept-Language'] : 'en',
  })
});

exports.graphqlHandler = (event, context, callback) => {
  const handler = server.createHandler({
    cors: {
      origin: '*',
      credentials: true,
    },
  });
  context.callbackWaitsForEmptyEventLoop = false;
  return handler(event, context, callback);
};

Does anyone have an idea what causes the problem and/or how to solve it? Queries work if the properties privateHeaders and privateVariables are set as true, but then it does not report to the engine dashboard.

Thanks for your efforts!

Best,
Ben

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✋ blockingPrevents production or dev due to perf, bug, build error, etc..📚 good-first-issueIssues that are more approachable for first-time contributors.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions