开发者社区> 问答> 正文

Firebase Express服务器-无法连接到WebSocket端点

0

我正在尝试通过firebase函数运行graphql订阅,我进行了以下设置:

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

import { PubSub } from 'apollo-server-express';

const pubsub = new PubSub();

const typeDefs = gql` type Post { author: String comment: String } type Query { hello: String posts: [Post] } type Subscription { postAdded: Post }

type Mutation { addPost(author: String, comment: String): Post }

`;

const POST_ADDED = 'POST_ADDED';

class Poster { public posts() { return [] }

public addPost(args: any) {

}

}

const postController = new Poster();

const resolvers = { Subscription: { postAdded: { // Additional event labels can be passed to asyncIterator creation subscribe: () => pubsub.asyncIterator([POST_ADDED]), }, }, Query: { hello: () => 'Hello world!', posts(root: any, args: any, context: any) { return postController.posts(); }, }, Mutation: { addPost(root: any, args: any, context: any) { pubsub.publish(POST_ADDED, { postAdded: args }); return postController.addPost(args); }, },

};

const server = new ApolloServer({ typeDefs, resolvers, subscriptions: { onConnect: (connectionParams, webSocket) => {

    },
  },
 });

const express = require("express")

/* Express */ const app = express() server.applyMiddleware({ app });

app.get("*", (request:any, response:any) => { response.send("Hello from Express on Firebase!") }) app.listen({ port: 4000 }, () => console.log( Server ready at http://localhost:4000${server.graphqlPath}) )

const api = functions.https.onRequest(app)

module.exports = { api } 当我尝试使用游乐场通过此查询进行连接时:

subscription { posts { author comment } } 我收到一个错误:

"error": "Could not connect to websocket endpoint ws://localhost:5001/graphql. Please check if the endpoint url is correct." 我是否在exprses服务器中缺少某些配置,或者firebase不能正确支持套接字?

展开
收起
被纵养的懒猫 2019-09-27 19:39:42 802 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
如何运维千台以上游戏云服务器 立即下载
网站/服务器取证 实践与挑战 立即下载
ECS快储存加密技术 立即下载