プロファイルを取得する反応ネイティブアプリケーションで上位コンポーネントがあります。私が「フォロワーを追加する」突然変異を呼び出すとき、そのフォロワーコレクションの新しいフォロワーを反映するようにプロファイルを更新したい。ストアへの更新を手動でどのようにトリガーしますか。プロファイルオブジェクト全体を再取得することはできますが、ネットワークの再フェッチをせずにクライアント側で挿入するだけです。現在、突然変異を引き起こすと、プロファイルは画面の変化を反映しません。Apolloデータストア/キャッシュを突然変異クエリから更新するには、更新オプションが起動しないようです。
私はupdate
オプションを使用している必要がありますが、私の名前付き突然変異ではうまくいかないようです。 http://dev.apollodata.com/react/api-mutations.html#graphql-mutation-options-update
const getUserQuery = gql`
query getUserQuery($userId:ID!) {
User(id:$userId) {
id
username
headline
photo
followers {
id
username
thumbnail
}
}
}
`;
...
const followUserMutation = gql`
mutation followUser($followingUserId: ID!, $followersUserId: ID!) {
addToUserFollowing(followingUserId: $followingUserId, followersUserId: $followersUserId) {
followersUser {
id
username
thumbnail
}
}
}`;
...
@graphql(getUserQuery)
@graphql(followUserMutation, { name: 'follow' })
@graphql(unfollowUserMutation, { name: 'unfollow' })
export default class MyProfileScreen extends Component Profile
...
this.props.follow({
variables,
update: (store, { data: { followersUser } }) => {
//this update never seems to get called
console.log('this never triggers here');
const newData = store.readQuery({ getUserQuery });
newData.followers.push(followersUser);
store.writeQuery({ getUserQuery, newData });
},
});
ドキュメントによると、updateQueriesは廃止予定で、代わりにhttp://dev.apollodata.com/react/cache-updates.html#updateQueriesを使用すると、更新オプションを使用しようとしましたが、アップデートを引き起こすようです - 私はそのコードスニペットで質問を更新します – MonkeyBonkey
console.log(newData)でしたか?一つのことは、 'readQuery'がそれを見つけるためのクエリに名前をつける必要があるかもしれないということです。 'const getUserQuery = gql'query getUserQuery {....}' –
私はreadqueryの名前をつけましたが、まだ更新機能を起動していません - console.logは最初の行ですが、呼び出されません。 console.logに質問をして、質問に名前をつけてください。 – MonkeyBonkey