Apollo Graphql fetch/mutate/watch 不执行

56 阅读1分钟

问题:

Apollo Graphql fetch/mutate/watch 不执行。

直接上代码

 const args: GroupAddMutationVariables = {
                        entity: {
                            group: {
                                id: data.id,
                                title: data.title,
                                desc: data.title,
                                groupNext: [{
                                    id: groupNext[0].id,
                                    groupId: groupNext[0].groupId,
                                    roleId: groupNext[0].roleId
                                }]
                            }
                        }
                    };
                    console.log(args);
                    this.groupAdd.mutate(args).subscribe(d => {
                        console.log(d);
                        this.loadGroupList();
                    });
                    console.log(result);
                }
            },
            error => {
                console.log(error.name + " " + error.message);
            });

这个函数里的代码只执行到console.log(args)就不再执行了,直接跳出。

打开控制台 network,没有graphql网络请求。

原因:

参数错误,当参数为undefine或null,或者参数与graphql所需参数不符合,graphql请求不会执行,所以代码不再执行,网络里没有请求。

解决方法:

在打印出的args中看是否有参数传了undefine或null,或与graphql参数名字不符合。

问题解决。