【问题标题】:Apollo GraphQL (React) refetchQueries/update after mutation don't update the storeApollo GraphQL (React) refetchQueries/update after mutation 不更新存储
【发布时间】:2018-07-15 11:07:11
【问题描述】:

当您想要移动文件/文件夹时,我有一个类似于 Google 驱动器中的组件。它获取有关目录的所有必要数据,显示它,并在选择一个之后 - 它将文件移动到另一个文件夹中。我试图瞄准的目标是更新有关当前显示的文件夹和文件已移动的文件夹的数据。我尝试了两种方式(refetchQueries,更新),但没有工作......

主要问题是 updateQueries 中定义的查询被执行,但 store 没有更新。

如果有人能帮忙,那就太好了!

const EntityMoveContainer = compose(
    graphql(GET_DIRECTORIES, {
        options() {/*...*/},
        props(props) {/*...*/}
    }),
    graphql(MOVE_FILE, {
       props(props) {
           const { mutate, ownProps } = props;
           const { entity, directoryId } = ownProps;

           return {
            async moveFile(destDirId) {
                return mutate({
                    variables: {
                        fileId: entity.id,
                        directoryId: destDirId,
                    },
                    refetchQueries: () => [
                        {
                            query: GET_DIRECTORIES,
                            variables: {
                                id: directoryId,
                                sortKey: store.sortKey,
                                cursor: store.cursor,
                                filetype: store.filetype,
                            },
                        },
                        {
                            query: GET_DIRECTORIES,
                            variables: {
                                id: destDirId,
                                sortKey: store.sortKey,
                                cursor: store.cursor,
                                filetype: store.filetype,
                            },
                        },
                    ],
                    /* update(proxy) {
                        console.log('update method');
                        try {
                            const storeData = proxy.readQuery({
                                query: GET_DIRECTORIES,
                                variables: {
                                    id: destDirId,
                                    sortKey: store.sortKey,
                                    filetype: store.filetype,
                                    cursor: store.cursor,
                                },
                            });

                            storeData.directory = {
                                ...storeData.directory,
                                files: {
                                    ...storeData.directory.files,
                                    edges: [
                                        ...storeData.directory.files.edges,
                                        { node: entity, __typename: 'File' },
                                    ],
                                },
                            };

                            proxy.writeQuery({
                                query: GET_DIRECTORIES,
                                variables: {
                                    id: destDirId,
                                    sortKey: store.sortKey,
                                    filetype: store.filetype,
                                    cursor: store.cursor,
                                },
                                data: storeData,
                            });
                        } catch (e) {
                            console.log(e);
                        }
                    }, */
                });
            },
        };
    },
}),
)(EntityMoveView)

【问题讨论】:

    标签: reactjs graphql react-apollo apollo-client


    【解决方案1】:

    问题在于

    光标:''

    我传递给 refetchQueries 的属性。

    【讨论】:

      猜你喜欢
      • 2018-05-26
      • 2019-01-12
      • 2021-10-04
      • 2020-01-15
      • 2019-06-12
      • 2020-02-14
      • 2018-08-26
      • 2019-03-10
      • 1970-01-01
      相关资源
      最近更新 更多