如何解决Apollo 服务器 (subscriptions-transport-ws) onDisconnect await context.initPromise 在 Heroku 上未定义,但在本地工作
当 onDisconnect 在我的 Heroku 产品构建上触发时,我的上下文未定义,但它在我的本地机器上完美运行。
这是服务器上的错误信息:
TypeError: Cannot read property 'initPromise' of undefined
at _callee3$ (/app/dist/index.js:518:42)
at tryCatch (/app/node_modules/regenerator-runtime/runtime.js:65:40)
at Generator.invoke [as _invoke] (/app/node_modules/regenerator-runtime/runtime.js:299:22)
at Generator.prototype.<computed> [as next] (/app/node_modules/regenerator-runtime/runtime.js:117:21)
at step (/app/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
at /app/node_modules/babel-runtime/helpers/asyncToGenerator.js:28:13
at processTicksAndRejections (internal/process/task_queues.js:97:5)
这是我的代码
index.js
onDisconnect: async (webSocket,context) => {
console.log('what is the context?: ',context); // undefined
try {
const initialContext = await context.initPromise;
if (
initialContext &&
typeof initialContext === 'object' &&
Reflect.has(initialContext,'user')
) {
console.log('initialContext: ',initialContext);
}
} catch (err) {
console.log('error',err); // TypeError: Cannot read property 'initPromise' of undefined
}
}
},
一切都符合我当地的机器规格。
package.json
"dependencies": {
"@axelspringer/graphql-google-pubsub": "^2.1.0","apollo-server-express": "^1.1.3","babel-runtime": "^6.26.0","bcrypt": "^4.0.0","body-parser": "^1.18.2","cors": "^2.8.4","devcert": "^1.1.2","expo-server-sdk": "^3.5.1","express": "^4.16.1","firebase-admin": "^8.9.1","graphql": "^0.11.7","graphql-redis-subscriptions": "^1.3.1","graphql-subscriptions": "^0.5.4","graphql-tools": "^2.2.1","jsonwebtoken": "^8.1.0","lodash": "^4.17.4","merge-graphql-schemas": "^1.1.4","node-fetch": "^2.6.0","node-gyp": "^3.8.0","node-pre-gyp": "^0.12.0","pg": "^7.7.1","sequelize": "^4.13.5","subscriptions-transport-ws": "^0.9.18"
},"engines": {
"node": "12.16.1","npm": "6.13.4"
}
有人对我有什么想法吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。