从订阅获得新数据后更新分页结果

时间:2019-12-25 00:28:52

标签: graphql react-apollo apollo-client

收到来自订阅的新数据后,我无法更新分页消息。

我有一个主要组件PrivateChannel用来获取消息:

#import '../../ApolloClient/fragments/User/basicUserInfo.gql'
#import '../../ApolloClient/fragments/Message/basicMessageInfo.gql'
#import '../../ApolloClient/fragments/common/channelMember.gql'

query messages($input: MessagesInput!) {
    messages(input: $input) {
        cursor {
            prev
            next
            limit
        }
        results {
            ...BasicMessageInfo
            author {
                user {
                    ...BasicUserInfo
                }
                channelMember {
                    ...ChannelMember
                }
            }
        }
    }
}

Sidebar中,我有频道成员列表,当用户加入或离开频道或其属性之一(如muted)更改时,该列表会通过订阅进行更新。由action字段确定,该字段接受3个值addeddeletededited

#import '../../ApolloClient/fragments/common/channelMember.gql'
#import '../../ApolloClient/fragments/User/basicUserInfo.gql'

subscription channelMemberListUpdated($input: ChannelMemberListUpdatedInput!) {
    channelMemberListUpdated(input: $input) {
        action
        channelMember {
            ...ChannelMember
        }
    }
}

ChannelMember

fragment ChannelMember on ChannelMember {
    blocked
    muted
    role
    channelId
    memberId
}

typePolicies: {
    ChannelMember: {
        keyFields: ['channelId', 'memberId'],
    },
}

我想实现什么?通过订阅在ChannelMember中更新Sidebar时,我希望新数据能够反映在PrivateChannel组件中。 当PrivateChannel字段为action时,一切工作正常,对于edited组件而言,但对于其他组件则无效。 我有什么可能解决这个问题?

我使用Apollo Client 3。

0 个答案:

没有答案