我有一个订阅查询MessageFolder_Subscription
,看起来像这样:
查询
const MESSAGEFOLDER_SUBSCRIPTION_QUERY = gql`
subscription ($localUserID: String!){
MessageFolder_Subscription(userID: $localUserID){
id
remoteUserData{
id
name_title
name_first
name_last
[...more fields...]
}
},
}
`;
这是它的架构:
SCHEMA
type myUserData {
id: String
gender: String
name_title: String
name_first: String
*[...more fields...]*
}
type messageFolder{
id: String
remoteUserData: myUserData
}
type Subscription {
MessageFolder_Subscription(userID: String!): messageFolder
}
这是我做解析器的方式:
解决方法
const resolvers = {
//FIELD RESOLVER
MessageFolder_Subscription: {
subscribe: withFilter(
() => pubsub.asyncIterator(MSGFOLDER_ADDED_CHANNEL),
(payload, args) => {
debugger; <=== NEVER FIRES
if (typeof (payload) === 'undefined') {
return false;
}
let result = false;
const userId = Meteor.userId();
// let messageFolder = MessageFolder_Subscription.messageFolder;
result = (userId === args.fromID || args === MSGFOLDERargs.toID);
return result;
}
)
},
//ROOT RESOLVER
*[......more resolvers here.....]*
Subscription: {
MessageFolder_Subscription: {
subscribe: withFilter(
() => pubsub.asyncIterator(MSGFOLDER_ADDED_CHANNEL),
(payload, args) => {
debugger;
if (typeof (payload) === 'undefined') {
return false;
}
let result = false;
const userId = Meteor.userId();
// let messageFolder = MessageFolder_Subscription.messageFolder;
result = (userId === args.fromID || args === MSGFOLDERargs.toID);
return result;
}
)
}
}
当我对相关项目进行突变时,pubsub将按预期触发MessageFolder_Subscription
查询。追溯,我看到它返回true
。
但是由于某些原因,remoteUserData
上的字段MessageFolder_Subscription
的字段解析器永远不会触发。
我想念什么?
答案 0 :(得分:0)
已解决。我必须添加__typename:
字段:
const messageFolder_Subscription = {
__typename: 'messageFolder_Subscription',
id: userID,
}
...到MessageFolder_Subscription
订阅对象,该对象在传递给pubsub
之前在变异解析器中创建。