apollo-server - Apollo graphql 订阅,对 graphql 服务器和 websocket 端点使用相同的端点
问题描述
我只是想知道为 graphql 端点和 WebSocket 使用相同的端点是否有任何性能下降或任何劣势。您可以在下面查看示例代码。
import express = require("express");
import { ApolloServer } from "apollo-server-express";
import bodyParser from "body-parser";
import Knex from "knex";
import { execute, subscribe } from "graphql";
import { SubscriptionServer } from "subscriptions-transport-ws";
// graphql api
import api from "./api";
const { createServer } = require("http");
const app: express.Application = express();
const path = "/graphql";
app.use(bodyParser.json());
const graphqlServer = new ApolloServer(api);
graphqlServer.applyMiddleware({ app, path });
const server = createServer(app);
server.listen(process.env.PORT, err => {
if (err) {
throw new Error(err);
}
new SubscriptionServer(
{
execute,
subscribe,
schema: api.schema
},
{
server,
// same as the graphql endpoint
path
}
);
console.log(
`the server is running at http://localhost:${process.env.PORT}/graphql`
);
});
解决方案
推荐阅读
- fpga - 在组合电路上,我想知道传播延迟(路径延迟)
- android - 如何在 AlertDialog 中将复选框列表项设置为由 DEFAULT 选中?
- c - C中输入的字符计数
- java - 偏移量 5 处的格式错误的函数或过程转义语法
- c++ - 如何使用指针创建 Mat 并调用 OpenCV 方法
- mysql - 多对多关系 - 在 MySQL 中获取双行
- android - 通过 Glide 或 Volley 库从服务器检索所有图像并在列表视图中显示它们
- python - pandas 有效地将 DataFrames 与不匹配的分类列和 MultiIndex 级别连接起来
- java - Java中的整洁循环
- qt - 如何在 QML 布局中的以下项目上绘制元素