在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):GraphQLCollege/graphql-postgres-subscriptions开源软件地址(OpenSource Url):https://github.com/GraphQLCollege/graphql-postgres-subscriptions开源编程语言(OpenSource Language):JavaScript 99.4%开源软件介绍(OpenSource Introduction):graphql-postgres-subscriptionsA graphql subscriptions implementation using postgres and apollo's graphql-subscriptions. This package implements the PubSubEngine Interface from the graphql-subscriptions package and also the new AsyncIterator interface. It allows you to connect your subscriptions manger to a postgres based Pub Sub mechanism to support multiple subscription manager instances. Installation
UsageExample app: https://github.com/GraphQLCollege/apollo-subscriptions-example First of all, follow the instructions in graphql-subscriptions to add subscriptions to your app. Afterwards replace // Before
import { PubSub } from "graphql-subscriptions";
export const pubsub = new PubSub(); // After
import { PostgresPubSub } from "graphql-postgres-subscriptions";
export const pubsub = new PostgresPubSub(); This library uses You have three options: If you don's send any argument to You can also pass node-postgres connection options to You can instantiate your own import { PostgresPubSub } from "graphql-postgres-subscriptions";
import { Client } from "pg";
const client = new Client();
await client.connect();
const pubsub = new PostgresPubSub({ client }); Important: Don't pass clients from commonMessageHandlerThe second argument to const getDataLoader = () => new DataLoader(...)
const commonMessageHandler = ({attributes: {id}, data}) => ({id, dataLoader: getDataLoader()})
const pubsub = new PostgresPubSub({ client, commonMessageHandler }); export const resolvers = {
Subscription: {
somethingChanged: {
resolve: ({ id, dataLoader }) => dataLoader.load(id)
}
}
}; Error handling
const ps = new PostgresPubSub({ client });
ps.subscribe("error", err => {
console.log(err.message); // -> "payload string too long"
}).then(() => ps.publish("a", "a".repeat(9000))); For example you can log all error messages (including stack traces and friends) using something like this: ps.subscribe("error", console.error); DevelopmentThis project has an integration test suite that uses We use Docker to spin up a PostgreSQL instance before running the tests. To run them, type the following commands:
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论