我想我的後端訂閱設置正確。我使用的角度在客戶端上,當我嘗試打電話subscribe
我得到一個錯誤GraphQL訂閱:調用apolloClient.subscribe的錯誤
passwordUpdatedSubscription = gql`
subscription passwordUpdated{passwordUpdated{name password}}
`;
// Apollo Subscription
var subscription = this.apollo.subscribe({
query: this.passwordUpdatedSubscription
});
subscription.subscribe(
{
next(data) {
console.log(data);
},
error(err) { console.error('err', err); },
}
);
然後這是錯誤控制檯出現 {"type":"subscription_fail","id":0,"payload":{"errors":[{"message":"Cannot read property 'subscribe' of undefined"}]}}
在後端也許我失去了一些東西?我是否需要在SubscriptionManager
中定義setupFunctions
?
這是我SubscriptionManager
const sub = require('graphql-subscriptions');
const pubSub = new sub.PubSub();
const manager = new sub.SubscriptionManager({
schema,
pubSub
});
這是我在graphQL
const graphql = require('graphql');
var schema = graphql.buildSchema(`
type Subscription {
passwordUpdated: User
}
type Mutation {
setMessage(message: String): String,
updateUserPassword(userName: String, password: String): User!
}
type Query {
getMessage: String,
getUsers: [User],
findUsers(userName: String): [User]
}
type User {
name: String,
password: String
}
`);
錯誤是告訴你,在這種情況下apollo客戶端是未定義的。你已經檢查過嗎? –
@ Locco0_0,我已檢查過。它不是沒有定義的。其他操作如'watchQuery'和'mutation'正在工作,雖然 –
好,所以請在服務器上顯示Subscription Manager。你使用哪個節點包?我想你錯過了設置功能。你使用什麼樣的發佈訂閱? –