INTERNAL_SERVER_ERROR for not passing a variable

Hey folks,

I am using "apollo-server-lambda": "2.25.2". For queries that have some issues related to variables passed by the client causes the server to report INTERNAL_SERVER_ERROR. For example, if a variable wasn’t passed or if the variable is of a type Float instead of a String etc. I believe it should be treated as validation error or request error? What do you guys think?

  code: "INTERNAL_SERVER_ERROR",
  exception: {
    stacktrace: [
      "GraphQLError: Variable "$slug" of required type "String!" was not provided.",
      "    at _loop (/opt/nodejs/node_modules/graphql/execution/values.js:94:17)",
      "    at coerceVariableValues (/opt/nodejs/node_modules/graphql/execution/values.js:121:16)",
      "    at getVariableValues (/opt/nodejs/node_modules/graphql/execution/values.js:50:19)",

Changing the type of error returned would be a breaking change in my opinion, because others who are in production may use that error code in order to perform additional logic, such as a follow-up query when a variable passed in by a generated response is null and returns this code on the first try.

I don’t recall what apollo-server does for this, but my gut tells me that both of these packages use the apollo-server-core package, so the error code is probably coming from that.

Feel free to submit a ticket to the apollo-server-lambda github, but the change you’re talking about is a breaking one, and would probably effect 100% of users.

1 Like

Thanks for the response @kevin-lindsay-1
Guess the only option is to reformat this error before sending to client by parsing the error message using formatError function. Any other way you reckon?

If you really want to rename an error code built into the framework, yes that’s probably the simplest way to do it.