我有一个中继订阅设置,其中我在更新程序中获取数据,如下所示https://gist.github.com/ydvsailendar/6b9569bbcbc269246e299eb5cce18a80#file-gistfile1-txt-L10
我想更新我的查询连接,以便在订阅收到新消息时通过查询获取更新的消息。
这是我的订阅:
import { ConnectionHandler } from 'relay-runtime';
import {
graphql,
requestSubscription
} from 'react-relay'
import environment from '../network';
const subscription = graphql`
subscription chatWithSubscription($id: String){
chatWith(id: $id){
textMessage
id
chatId
date
userType
translatedMessage
}
}
`;
function chatWith(id) {
const variables = { id: id };
requestSubscription(environment, {
subscription,
variables,
onError: (error) => {
console.log(error, "error");
},
updater: (store) => {
console.log(store, "store");
}
});
}
module.exports = chatWith;
这是我想通过更新程序更新的查询:
module.exports = createPaginationContainer(
ChatMessages,
graphql`
fragment ChatMessages_query on Query
@argumentDefinitions(
count: { type: "Int", defaultValue: 10 }
cursor: { type: "String" }
chatId: { type: "ID" }
) {
messages(
first: $count
after: $cursor
chatId: $chatId
) @connection(key: "ChatMessages_messages") {
edges {
node {
id
chatId
userType
date
textMessage
translatedMessage
}
cursor
}
totalCount
pageInfo {
endCursor
hasNextPage
}
}
}
`,
{
direction: "forward" | "backward",
getConnectionFromProps(props) {
return props.query && props.query.messages;
},
// This is also the default implementation of `getFragmentVariables` if it isn't provided.
getFragmentVariables(prevVars, totalCount) {
return {
...prevVars,
count: totalCount
};
},
getVariables(props, { count, cursor }, fragmentVariables) {
return {
count,
cursor,
chatId: fragmentVariables.chatId
};
},
query: graphql`
query ChatMessagesPaginationQuery(
$count: Int!
$cursor: String
$chatId: ID!
) {
...ChatMessages_query
@arguments(
count: $count
cursor: $cursor
chatId: $chatId
)
}
`
}
);
我是通过订阅使用更新程序的新手,文档真的很混乱,我无法理解查看者的道具和文档中提到的其他内容。请帮助我实施。