0

我有一个订阅查询,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...]
            }
        },
    }
`;

这是它的架构:

架构

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;
                }
            )
        }
}

当我改变相关项目时,MessageFolder_Subscriptionpubsub 会按预期触发查询。追溯,我可以看到它返回true

remoteUserData但是由于某种原因,字段解析器MessageFolder_Subscription永远不会触发。

我错过了什么?

4

1 回答 1

0

解决了。我必须添加该__typename:字段:

const messageFolder_Subscription = {
    __typename: 'messageFolder_Subscription',
    id: userID,
}

...到MessageFolder_Subscription订阅对象,当它在突变解析器中创建时,在传递给pubsub.

于 2019-03-26T12:59:10.240 回答