我正在和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/
发布于 2021-06-28 23:48:29
对于两个不同的错误,我有相同的错误信息。
https://server-name.domain,但实际上它是URL。在您的情况下,
尝试删除
/playground2。我的查询中有一个拼写错误
在chrome中检查您的网络选项卡并阅读服务器响应,这比console.log Http failure response更有帮助
https://stackoverflow.com/questions/64800738
复制相似问题