apollo lighthouse subscription link
1.0.0
使用 Laravel Echo 状态通道订阅 Lighthouse graphql 订阅的 apollo 链接。
npm install @thekonz/apollo-lighthouse-subscription-link
# or
yarn add @thekonz/apollo-lighthouse-subscription-link
灯塔版 | 链接版本 | 评论 |
---|---|---|
5.2及以下 | 1.1及以下 | |
5.3及以上 | 1.2及以上 | 活动名称从“lighthouse.subscription”更改为“lighthouse-subscription” |
5.3及以上 | 1.3及以上 | 支持“lighthouse.subscription.version”= 2 |
import ApolloClient from "@apollo/client" ;
import gql from "graphql-tag" ;
import Echo from "laravel-echo" ;
import { createLighthouseSubscriptionLink } from "@thekonz/apollo-lighthouse-subscription-link" ;
const echoClient = new Echo ( { ... } ) ;
const client = new ApolloClient ( {
link : ApolloLink . from ( [
createLighthouseSubscriptionLink ( echoClient ) ,
httpLink , // your existing http link to your graphql api
] ) ,
cache : new InMemoryCache ( ) ,
} ) ;
const subscriber = client
. subscribe ( {
query : gql `
subscription {
postUpdated {
id
title
}
}
` ,
} )
. subscribe ( ( postUpdated ) => {
console . log ( postUpdated ) ; // { id: 2, title: "New title" }
} ) ;
// stop listening to events
subscriber . unsubscribe ( )
请随意使用问题系统为这个包做出贡献,并在develop
分支上拉取请求。
必须添加或更改自动化单元测试以覆盖您的更改或重现错误。