【发布时间】:2019-12-08 08:55:00
【问题描述】:
我正在尝试构建一个模块以将 GraphQL 与 ionic 4 一起使用。我已经能够将不安全的 GraphQL 站点导入此 ionic 应用程序。我在将标头导入导出函数 createApollo 时遇到问题。这是我离开的地方。
GraphQL.module.ts
import {NgModule} from '@angular/core';
import {ApolloModule, APOLLO_OPTIONS} from 'apollo-angular';
import {HttpLinkModule, HttpLink} from 'apollo-angular-link-http';
import {InMemoryCache} from 'apollo-cache-inmemory';
import { HttpHeaders } from "@angular/common/http";
// const uri = 'https://api.graph.cool/simple/v1/cjv14rb014vcb0108wgqy0zmq';
const uri = 'https://somewhere.com/graphql/mobile';
const headers = new HttpHeaders({
'x-authorization-token': 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
'access-control-allow-origin': 'https://app.procuredox.com,https://b2b.procuredox.com',
'access-control-allow-methods': 'GET,POST,OPTIONS',
'access-control-allow-headers': 'Content-Type, X-Authorization-Token, Origin',
'content-type': 'application/json'
});
export function createApollo(httpLink: HttpLink) {
return {
link: httpLink.create({uri}),
cache: new InMemoryCache(),
};
}
@NgModule({
exports: [ApolloModule, HttpLinkModule],
providers: [
{
provide: APOLLO_OPTIONS,
useFactory: createApollo,
deps: [HttpLink],
},
],
})
export class GraphQLModule {}
【问题讨论】:
-
删除你的问题很不爽
-
这是一个糟糕的问题