aws-mobile-appsync-sdk-js
aws-mobile-appsync-sdk-js copied to clipboard
Stale apollo-cache-inmemory causes error on Lambda when using AWSAppSyncClient
Report a bug
What is the current behavior?
Using aws-appsync in Lambdas (ie.: AWSAppSyncClient) makes lambda execution fail with error:
ERROR Invoke Error {"errorType":"TypeError","errorMessage":"Cannot convert undefined or null to object","stack":["TypeError: Cannot convert undefined or null to object"," at Function.keys (<anonymous>)"," at /opt/nodejs/node_modules/apollo-cache-inmemory/lib/bundle.umd.js:331:12"," at /opt/nodejs/node_modules/apollo-cache-inmemory/lib/bundle.umd.js:2:68"," at Object.<anonymous> (/opt/nodejs/node_modules/apollo-cache-inmemory/lib/bundle.umd.js:5:2)"," at Module._compile (internal/modules/cjs/loader.js:999:30)"," at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)"," at Module.load (internal/modules/cjs/loader.js:863:32)"," at Function.Module._load (internal/modules/cjs/loader.js:708:14)"," at Module.require (internal/modules/cjs/loader.js:887:19)"," at require (internal/modules/cjs/helpers.js:74:18)"]}
Caused by apollo-cache-inmemory:1.3.12 @apollo-cache-inmemory/lib/bundle.umd.js
...
// visitor || visitor.QueryDocumentKeys may be undefined
Object.keys(visitor.QueryDocumentKeys).forEach(function (parentKind) {
var childKeys = queryKeyMap[parentKind] = Object.create(null);
visitor.QueryDocumentKeys[parentKind].forEach(function (childKey) {
childKeys[childKey] = true;
});
if (parentKind === "FragmentSpread") {
childKeys["fragment"] = true;
}
});
...
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.
ie.:
exports.handler = async (event) => {
require("isomorphic-fetch");
const gql = require("graphql-tag");
const AWSAppSyncClient = require("aws-appsync").default;
const appSyncClient = new AWSAppSyncClient({
url: process.env.API_ENDPOINT,
region: process.env.AWS_REGION,
auth: {
type: "API_KEY",
apiKey: process.env.API_KEY,
},
fetchPolicy: "network-only",
disableOffline: true,
});
const response = await appSyncClient
.query({ query: gql`query foo{ foo }` })
.catch((error) => {
throw new Error(error);
});
console.log({ response });
return response;
}
What is the expected behavior?
logs and returns { data: { foo: "bar" } }
Which versions and which environment (nodejs) / OS are affected by this issue? Did this work in previous versions? Running on AWS Lambda
- nodejs14.x
- aws-appsync: "4.1.4"
- apollo-cache-inmemory: "1.3.12"
Got the same problem!
Is there an older version which works properly?
With the following dependency versions, it works!
"dependencies": { "aws-appsync": "^4.1.4", "cross-fetch": "^3.1.4", "graphql": "^15.7.0", "graphql-tag": "^2.12.5" }
Do not use newer "graphql" version.
Works for me, thanks @eugen-maser :bow:
Worked for me, thanks @eugen-maser 🙇
The key thing here appears to be the "graphql": "^15.7.0" line. That's all it took to fix things for me.
Thanks. Still working!
This doesn't fix it for me. Any suggestions?
"graphql": "^15.7.0" worked for me! Thanks!