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
分支上拉取請求。
必須新增或變更自動化單元測試以覆寫您的變更或重現錯誤。