繁体   English   中英

无法使用云 firebase 部署 apollo graphql 无服务器 function

[英]Failing to deploy apollo graphql serverless function with clould firebase

我正在尝试将 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.

感谢@tzovourn 的支持我已经解决了这个问题,参考这篇文章https://medium.com/@sandun.isuru/how-to-deploy-nodejs-express-app-to-firebase-as-function-31515c304e70
实际上问题出在 firebase 方面,节点 10 存在问题,所以我在 package.json 即从“引擎”到“引擎”{“node”:“{”:“{”:“{”}:”:” "8"} 并且还将所有 devdependies 移动到依赖项。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM