阿波罗角-网络错误:未定义,因为尚未设置正确的点

时间:2018-08-27 22:23:51

标签: angular ionic3 apollo apollo-angular

我刚刚从另一个项目复制了我们的apollo角度设置,在成功登录后从服务器收到响应后,我们初始化了Apollo。

@Effect({ dispatch: true })
setLoginResponseToken$ = this.actions$.pipe(
    ofType(AuthActions.ActionTypes.SET_LOGIN_RESPONSE_ACTION),
    switchMap((loginResponse: UserLoginResponse) => {

    =>  this.init(loginResponse.authorization.token);

        return this.authService.getUserIdWithSelfbitsUserId(loginResponse).pipe(
            map((pgUserId: string) => {
                console.log('login effect', pgUserId);
                return { type: AuthActions.ActionTypes.SET_POSTGRES_USER_ACTION, payload: pgUserId };
            })
        );
    })
);


init(token) {
    const http = this.httpLink.create({
        uri: environment.APOLLO_GRAPHQL_ENDPOINT
    });
    const middleware = new ApolloLink((operation, forward) => {
        operation.setContext({
            headers: new HttpHeaders().set('Authorization', 'Bearer ' + token || null)
        });
        return forward(operation);
    });

    const logoutLink = onError(({ response, networkError }) => {
        let errorToast = this.toastCtrl.create({
            message: 'error'
        });
        errorToast.present();
    });

    if (!this.apollo.getClient()) {
        this.apollo.createDefault({
            link: from([logoutLink, middleware, http]),
            cache: new InMemoryCache(),
            connectToDevTools: true,
            defaultOptions: {
                watchQuery: {
                    errorPolicy: 'ignore'
                }
            }
        });
    }
}

但是当我随后尝试使用apollo进行查询时,传出的呼叫不会转到预先定义的graphql端点,而是转到

  

http://192.168.199.72:8100/POST,我得到404(未找到)

我紧跟着字母Apollo Angular Setup,但我没有使用阿波罗升压器。

我使用的是我们另一个工作项目的确切设置副本,这很奇怪。

我的阿波罗版本是

"apollo-angular": "1.2.0",
"apollo-angular-link-http": "1.2.0",
"apollo-cache-inmemory": "1.2.9",
"apollo-client": "2.4.1",
"apollo-link": "^1.2.2",
"apollo-link-error": "1.1.0",

有人知道发生了什么事吗?

0 个答案:

没有答案