【发布时间】:2020-11-24 12:55:52
【问题描述】:
下面是我的代码。我一直试图以某种方式将错误变量链接到 GraphQL Module 。请提供一种方法来实现这一点。
import { ApolloModule, APOLLO_OPTIONS } from 'apollo-angular';
import { HttpLinkModule, HttpLink } from 'apollo-angular-link-http';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { onError } from 'apollo-link-error';
const uri = 'http://localhost:3000/graphql';
const error = onError(({ graphQLErrors, networkError }) => { // need help on linking this with graphql module
if (graphQLErrors)
graphQLErrors.map(({ message, locations, path }) =>
console.log(
`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`,
),
);
if (networkError) console.log(`[Network error]: ${networkError}`);
});
// <-- add the URL of the GraphQL server here
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 {}
我需要有关与 GraphQL Module 链接错误的帮助。我怎样才能做到这一点?提前致谢。
【问题讨论】:
标签: angular graphql apollo apollo-server express-graphql