如何将Apollo Server 2与Firebase功能一起使用

时间:2018-08-06 04:33:17

标签: firebase graphql apollo-server

我正在研究如何使用具有Firebase功能的Apollo GraphQL服务器,并且发现了link,它使用了Apollo Server1。我正在尝试使用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);

使用"apollo-server-express": "^2.0.0",但没有成功,因为每次遵循函数链接时,我总是得到Cannot GET /

那么,有没有办法用Firebase / Google功能实现Apollo Server 2?

1 个答案:

答案 0 :(得分:2)

当我将path: '/'添加到applyMiddleware时有效

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

与端点// https://us-central1-<project-name>.cloudfunctions.net/api一起部署时,我使用此功能。操场在这里工作正常。

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

之前,游乐场无法在这里工作
相关问题