angular - 我收到一个错误:http://localhost:10600/playground/ 的 Http 失败响应:404 Not Found at new ApolloError
问题描述
我正在使用graphQL。我正在尝试提出请求。服务器有权限。我从官网举个例子,把uri改成http://localhost:10600/playground/。但是错误404不断发生。虽然服务本身在此地址可用。
我的 graphql.module.ts
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/
解决方案
对于 2 个不同的错误,我有相同的错误消息。
- 我的网址是错误的,我提供
https://server-name.domain
但实际上是https://server-name.domain/graphql
在您的情况下,请尝试删除
/playground
2。我的查询中有错字
在 chrome 中检查您的网络选项卡并阅读服务器响应,这比 console.log 更有帮助Http failure response
推荐阅读
- android - 在firebase中使用电话身份验证登录后,如果我退出,有什么方法可以使用相同的号码登录?
- visual-studio-code - 差异编辑器页面可以邮寄吗?
- python - 排序和选择 Python Pandas 问题
- reactjs - 我怎样才能让背景覆盖屏幕。在 React Native 中
- android - 未处理的异常:LateInitializationError:字段“_id@21016470”尚未初始化
- azureservicebus - Azure 服务总线接收器消息处理程序被多次调用相同的消息
- javascript - 如何获得我在猫鼬中增加的原始数字
- flutter - 无法无条件访问属性“文档”,因为接收者可以为“空”-Flutter
- jsxgraph - 如何将 n 更改为 nslider.Value()?
- security - 内核与用户空间通信是否需要保护