如何将 Apollo Server 2 与 Firebase 函数一起使用

How to use Apollo Server 2 with Firebase Functions

我正在研究如何使用具有 Firebase 功能的 Apollo GraphQL 服务器,我发现了这个 link,它使用 Apollo Server 1。我正在尝试使用 Apollo Server 2,但它没有

import { graphqlExpress, graphiqlExpress } from 'apollo-server-express';

作者在文章中使用的。

我试过这样实现的:

import { https } from "firebase-functions"
import { ApolloServer, gql } from 'apollo-server-express';
import * as express from 'express';

const app = express();

const graphQLServer = new ApolloServer({ typeDefs, resolvers });

graphQLServer.applyMiddleware({ app });

export const api = https.onRequest(app);

with "apollo-server-express": "^2.0.0" 但没有成功,因为每次我按照函数 link.

总是得到 Cannot GET /

那么,有没有办法用 Firebase/Google 函数来实现 Apollo Server 2?

当我将 path: '/' 添加到 applyMiddleware

时有效
graphQLServer.applyMiddleware({ app, path: '/' });

我在使用端点 // https://us-central1-<project-name>.cloudfunctions.net/api 部署时使用此函数。游乐场在这里工作正常。

localhost,由 http://localhost:5000/<project-name>/us-central1/api。在我将历史按钮旁边的 URL 更改为 http://localhost:5000/<project-name>/us-central1/api/

之前,Playground 在这里不起作用