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

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

Closed
BHesseldieck opened this issue Jul 5, 2018 · 5 comments
Closed
Labels
📚 good-first-issue Issues that are more approachable for first-time contributors. ✋ blocking Prevents production or dev due to perf, bug, build error, etc..

Comments

@BHesseldieck
Copy link

BHesseldieck commented Jul 5, 2018

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

@ghost ghost added ✋ blocking Prevents production or dev due to perf, bug, build error, etc.. 📚 good-first-issue Issues that are more approachable for first-time contributors. labels Jul 5, 2018
@evans
Copy link
Contributor

evans commented Jul 9, 2018

@BHesseldieck Thank you for bringing it up! I've run tests locally/with the sam deployment and it seems like we aren't seeing the error as a deployment with the serverless framework. We've added wrapper around the headers contained in event with #1313. If you want to take a look, please do. We should have another release for you soon.

@evans
Copy link
Contributor

evans commented Jul 10, 2018

@BHesseldieck This should be fixed with npm install apollo-server-lambda@rc. We've published #1313. Let us know if the issue persists

@BHesseldieck
Copy link
Author

BHesseldieck commented Jul 10, 2018

Thank you so much for the response!! Sorry for replying late, I was busy with other cache setups and experiments.

I think below setup worked, still not sure if its right, will figure it out in coming days.

One more catch is that we missed configuring the AWS NAT gateway to allow to communicate with the internet!

// FIXME: Only for testing
engine: {
 apiKey: 'XXXXXXXX',
 // FIXME: Do not know why we need these below properties,
 // If not provided, application doesn't start!!
 privateHeaders: true,
 // privateVariables: true,
 maxUncompressedReportSize: 4000, //4000000,
 debugPrintReports: true,
},

@evans
Copy link
Contributor

evans commented Jul 10, 2018

@BHesseldieck Great to hear! Super odd that the lambda doesn't start without those options. Can you try removing privateHeaders and maxUncompressedReportSize? The new release should allow sending headers and send a report on every request

@evans evans closed this as completed in e29f804 Jul 14, 2018
@tspecht
Copy link

tspecht commented Jul 20, 2018

@evans I'm having the same issue using the express setup, just upgraded so should be on the latest versions respectively. Any idea why this is happening? The fix that @BHesseldieck posted above seems to be working for me as well ...

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
📚 good-first-issue Issues that are more approachable for first-time contributors. ✋ blocking Prevents production or dev due to perf, bug, build error, etc..
Projects
None yet
Development

No branches or pull requests

3 participants