Apollo mergeSchemas errors return Unexpected error value:

Hello,

I’m using netlify functions Apollog GraphQL and Apollo Gateway Template for schema stitching. I throw AuthenticationError from apollo-server-lambda if login failed. However I always get INTERNAL_SERVER_ERROR. What should I do to fix this?

Gateway Function
image

Login function
const login = async (_, { email, password }, _context) => {
let match = null;
try {
match = await client.query(q.Get(q.Match(q.Index(“user_by_email”), email)));
} catch (err) {
console.error(err);
throw new AuthenticationError(“Wrong email or password”);
}
const user = match.data;

const valid = await bcrypt.compare(password, user.password);
if (!valid) {
throw new AuthenticationError(“Wrong email or password”);
}
return {
accessToken: createAccessToken(user),
refreshToken: createRefreshToken(user)
};
};

Error from Gateway
{
“errors”: [
{
“message”: “Unexpected error value: { message: “Wrong email or password”, locations: [[Object]], path: [“login”], extensions: { code: “UNAUTHENTICATED”, exception: [Object] } }”,
“locations”: [
{
“line”: 2,
“column”: 3
}
],
“path”: [
“login”
],
“extensions”: {
“code”: “INTERNAL_SERVER_ERROR”,
“exception”: {
“errors”: [
{
“message”: “Unexpected error value: { message: “Wrong email or password”, locations: [[Object]], path: [“login”], extensions: { code: “UNAUTHENTICATED”, exception: [Object] } }”,
“locations”: ,
“path”: [
“login”
]
}
],
“stacktrace”: [
“Error: Unexpected error value: { message: “Wrong email or password”, locations: [[Object]], path: [“login”], extensions: { code: “UNAUTHENTICATED”, exception: [Object] } }”,
" at new CombinedError (/home/senpai/Projects/adso/functions/gateway/node_modules/graphql-tools/dist/stitching/errors.js:82:28)",
" at Object.checkResultAndHandleErrors (/home/senpai/Projects/adso/functions/gateway/node_modules/graphql-tools/dist/stitching/errors.js:98:15)",
" at CheckResultAndHandleErrors.transformResult (/home/senpai/Projects/adso/functions/gateway/node_modules/graphql-tools/dist/transforms/CheckResultAndHandleErrors.js:9:25)",
" at /home/senpai/Projects/adso/functions/gateway/node_modules/graphql-tools/dist/transforms/transforms.js:25:54",
" at Array.reduce ()",
" at applyResultTransforms (/home/senpai/Projects/adso/functions/gateway/node_modules/graphql-tools/dist/transforms/transforms.js:24:23)",
" at /home/senpai/Projects/adso/functions/gateway/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:105:50",
" at step (/home/senpai/Projects/adso/functions/gateway/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:32:23)",
" at Object.next (/home/senpai/Projects/adso/functions/gateway/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:13:53)",
" at fulfilled (/home/senpai/Projects/adso/functions/gateway/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:4:58)"
]
}
}
}
],
“data”: {
“login”: null
}
}

Hello @kim_re, I’m not sure what the issue is exactly, but since your error messages are the same in two places, it’s hard to know which async call caused the error. You could try making them different so you can have a better idea. Hope that helps.