我目前使用'subscriptions-transport-ws'
作爲我的graphql和reactJS應用程序上的訂閱客戶端。然而這行代碼返回Object(...) is not a function
無法在React中使用addGraphQLSubscriptions,狀態「對象(...)未定義)」
的代碼:
import App from './components/App';
import registerServiceWorker from './registerServiceWorker';
import { ApolloProvider, createNetworkInterface, ApolloClient } from 'react-apollo'
import { SubscriptionClient, addGraphQLSubscriptions } from 'subscriptions-transport-ws'
const networkInterface = createNetworkInterface({
uri: '_GRAPHQL_END_POINT_'
})
const wsClient = new SubscriptionClient('_SUBSCRIPTION_END_POINT', {
reconnect: true,
})
const networkInterfaceWithSubscriptions = addGraphQLSubscriptions(
networkInterface,
wsClient
)
const client = new ApolloClient({
networkInterface: networkInterfaceWithSubscriptions
})
ReactDOM.render(
<BrowserRouter>
<ApolloProvider client={client}>
<App />
</ApolloProvider>
</BrowserRouter>
, document.getElementById('root')
)
registerServiceWorker();
凡在代碼中斷:
const networkInterfaceWithSubscriptions = addGraphQLSubscriptions(
networkInterface,
wsClient
)
我該如何解決這個問題? 相關文章:https://github.com/apollographql/subscriptions-transport-ws/issues/169 https://github.com/apollographql/subscriptions-transport-ws/pull/272