未能使用clouldfirebase部署apollo graphql无服务器功能



我正在尝试使用Apollo graphql无服务器云firebase,但我遇到了一个问题&无法找到解决方案。

当我运行firebase serve时,我的应用程序运行良好,我可以在graphql操场上运行我的查询,但当我执行firebase deploy命令时,它会抛出一个错误:

部署的函数与以下函数有错误:graphql

我检查了许多资源,其中的实现与我正在做的相同,但仍然会累积错误。在执行firebase deploy命令时,有什么特别的事情需要注意吗?

const functions = require('firebase-functions');
const admin = require('firebase-admin');
const express = require('express')
const {ApolloServer, gql} = require('apollo-server-express')
const serviceAccount = require('./serviceAccountKey.json')
admin.initializeApp({
credential: admin.credential.cert(serviceAccount)
});

const typeDefs = gql`
type Post {
text: String
} 
type Query {
post: [Post] 
}
`
const resolvers = {
Query : {
post: () => {
const arr = [{'text' : 'hello'},{'text' : 'hie'}]
return arr
}
}
}
const app = express()
const server = new ApolloServer({typeDefs, resolvers})
server.applyMiddleware({app, path: "/", cors: true})
exports.graphql = functions.https.onRequest(app)

记录

[2020-07-22T08:18:52.179Z] <<< HTTP RESPONSE 200 {"content-type":"application/json; charset=UTF-8","vary":"X-Origin, Referer, Origin,Accept-Encoding","date":"Wed, 22 Jul 2020 08:18:50 GMT","server":"ESF","cache-control":"private","x-xss-protection":"0","x-frame-options":"SAMEORIGIN","x-content-type-options":"nosniff","alt-svc":"h3-29=":443"; ma=2592000,h3-27=":443"; ma=2592000,h3-25=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"","accept-ranges":"none","transfer-encoding":"chunked"}
[2020-07-22T08:18:54.181Z] >>> HTTP REQUEST GET https://cloudfunctions.googleapis.com/v1/operations/ZmlyLWJhc2ljcy05OS91cy1jZW50cmFsMS9hcGkvMHN4TEhkamJFblE  
[2020-07-22T08:18:54.505Z] <<< HTTP RESPONSE 200 {"content-type":"application/json; charset=UTF-8","vary":"X-Origin, Referer, Origin,Accept-Encoding","date":"Wed, 22 Jul 2020 08:18:53 GMT","server":"ESF","cache-control":"private","x-xss-protection":"0","x-frame-options":"SAMEORIGIN","x-content-type-options":"nosniff","alt-svc":"h3-29=":443"; ma=2592000,h3-27=":443"; ma=2592000,h3-25=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"","accept-ranges":"none","transfer-encoding":"chunked"}
[2020-07-22T08:18:56.529Z] >>> HTTP REQUEST GET https://cloudfunctions.googleapis.com/v1/operations/ZmlyLWJhc2ljcy05OS91cy1jZW50cmFsMS9hcGkvMHN4TEhkamJFblE  
[2020-07-22T08:18:56.835Z] <<< HTTP RESPONSE 200 {"content-type":"application/json; charset=UTF-8","vary":"X-Origin, Referer, Origin,Accept-Encoding","date":"Wed, 22 Jul 2020 08:18:55 GMT","server":"ESF","cache-control":"private","x-xss-protection":"0","x-frame-options":"SAMEORIGIN","x-content-type-options":"nosniff","alt-svc":"h3-29=":443"; ma=2592000,h3-27=":443"; ma=2592000,h3-25=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"","accept-ranges":"none","transfer-encoding":"chunked"}
[2020-07-22T08:18:58.860Z] >>> HTTP REQUEST GET https://cloudfunctions.googleapis.com/v1/operations/ZmlyLWJhc2ljcy05OS91cy1jZW50cmFsMS9hcGkvMHN4TEhkamJFblE  
[2020-07-22T08:18:59.189Z] <<< HTTP RESPONSE 200 {"content-type":"application/json; charset=UTF-8","vary":"X-Origin, Referer, Origin,Accept-Encoding","date":"Wed, 22 Jul 2020 08:18:57 GMT","server":"ESF","cache-control":"private","x-xss-protection":"0","x-frame-options":"SAMEORIGIN","x-content-type-options":"nosniff","alt-svc":"h3-29=":443"; ma=2592000,h3-27=":443"; ma=2592000,h3-25=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"","accept-ranges":"none","transfer-encoding":"chunked"}
!  functions[api(us-central1)]: Deployment error. 
Function failed on loading user code. Error message: Error: please examine your function logs to see the error cause: https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs

Functions deploy had errors with the following functions:
graphql

To try redeploying those functions, run:
firebase deploy --only functions:api

To continue deploying other features (such as database), run:
firebase deploy --except functions
Error: Functions did not deploy properly.

感谢@tzovurn的支持,在参考本文后,我已经解决了这个问题https://medium.com/@sandun.isuru/how-to-deploy-nodejs-express-app-to-firebase-as-function-31515c304e70
实际上问题出在firebase方面,节点10有问题,所以我在我的package.json中做了一个更改,即从";发动机":{"节点":"10"}到"10";发动机":{"节点":"8"},并且还将所有的devdependencies移动到dependencie。

相关内容

  • 没有找到相关文章

最新更新