首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我收到一个错误:在新的ApolloError中找不到http://localhost:10600/playground/: 404的Http失败响应

我收到一个错误:在新的ApolloError中找不到http://localhost:10600/playground/: 404的Http失败响应
EN

Stack Overflow用户
提问于 2020-11-12 16:57:58
回答 1查看 180关注 0票数 2

我正在和graphQL一起工作。我正在试着提出一个请求。服务器有权限。我从官方网站上取了一个例子,把uri改成了http://localhost:10600/playground/。但是错误404经常发生。尽管服务本身在这个地址上是可用的。

我的graphql.module.ts

代码语言:javascript
复制
import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import { Apollo, APOLLO_OPTIONS } from 'apollo-angular';
import { HttpLink } from 'apollo-angular/http';
import { InMemoryCache, ApolloLink } from '@apollo/client/core';
import { setContext } from '@apollo/client/link/context';

const uri = 'http://localhost:10600/playground/';

export function createApollo(httpLink: HttpLink) {
  const basic = setContext((operation, context) => ({
    headers: {
      Accept: 'charset=utf-8'
    }
  }));

  const auth = setContext((operation, context) => {
    const token = localStorage.getItem('access_token');
    console.log(token)
    if (token === null) {
      return {};
    } else {
      return {
        headers: {
          Authorization: `Bearer ${token}`
        }
      };
    }
  });

  const link = ApolloLink.from([basic, auth, httpLink.create({ uri })]);
  const cache = new InMemoryCache();
  console.log(link);
  return {
    link,
    cache
  };
}

@NgModule({
  exports: [
    HttpClientModule,
  ],
  providers: [{
    provide: APOLLO_OPTIONS,
    useFactory: createApollo,
    deps: [HttpLink]
  }]
})
export class GraphQLModule { }

令牌有效。客户端为http://localhost:4200/

EN

回答 1

Stack Overflow用户

发布于 2021-06-28 23:48:29

对于两个不同的错误,我有相同的错误信息。

  1. 我的URL错误,我提供了https://server-name.domain,但实际上它是URL。

在您的情况下,

尝试删除/playground 2。我的查询中有一个拼写错误

在chrome中检查您的网络选项卡并阅读服务器响应,这比console.log Http failure response更有帮助

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64800738

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档