Graphql 查询graphiql导致Apollo错误转发不是一个函数

Graphql 查询graphiql导致Apollo错误转发不是一个函数,graphql,apollo,react-apollo,graphiql,Graphql,Apollo,React Apollo,Graphiql,当我转到/graphiql并手动执行一些搜索时,我有一个带有GraphQL的快速后端。我的React前端正在尝试在后端执行搜索。以下代码应异步执行查询: const data = await this.props.client.query({ query: MY_QUERY, variables: { initials: e.target.value } }); console.log(data); 其中,MY_QUERY是在前面定义的,表示我知道可以工作并已在/graphiq

当我转到
/graphiql
并手动执行一些搜索时,我有一个带有GraphQL的快速后端。我的React前端正在尝试在后端执行搜索。以下代码应异步执行查询:

const data = await this.props.client.query({
    query: MY_QUERY,
    variables: { initials: e.target.value }
});
console.log(data);
其中,
MY_QUERY
是在前面定义的,表示我知道可以工作并已在
/graphiql
上测试过的查询。要在我的React组件中实现这一点,我将其导出为
export default with Apollo(MyComponent)
,这样它在
道具中就有了
客户端
变量

在我通过Apollo定义的
index.js
文件中,连接到
/graphiql
,以执行查询:

//link defined to deal with errors, this was found online
const link = onError(({ graphQLErrors, networkError }) => {
    if (graphQLErrors)
        graphQLErrors.map(({ message, locations, path }) =>
        console.log(
            `[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`,
        ),
        );

    if (networkError) console.log(`[Network error]: ${networkError}`);
});

//the httpLink to my GraphQL instance, BASE_URL is defined elsewhere
const httpLink = new HttpLink({
    uri: BASE_URL,
    headers: {
    },
});

//here I define the client linking the GraphQL instance, the cache, and error handling
const client = new ApolloClient({
    link: httpLink,
    cache,
    link
});
在没有处理错误的
链接
变量的情况下执行上述查询时,我从服务器接收到一个
400错误请求
apolleror.js:37未捕获(承诺中)错误:网络错误:响应未成功:收到状态代码400
)。由于这没有告诉我更多,在StackOverflow和Apollo网页上,我找到了上面的错误声明,它输出
[网络错误]:TypeError:forward不是一个函数
。这个错误意味着什么?我该如何解决它


谢谢

您的客户端配置有一个重复的属性--您首先将
链接
属性设置为
HttpLink
,然后再次将其设置为
错误链接
。这意味着将完全忽略
HttpLink
,您只需将
ErrorLink
传递给配置。您看到该错误是因为由
onError
创建的
ErrorLink
不打算自己使用。相反,它应该与
HttpLink
链接,这就是您应该分配给
link
属性的内容

文档中详细介绍了如何正确组合链接。您可以使用
concat
,但我更喜欢
ApolloLink.from
,因为它允许您清楚地显示链接的顺序:

const errorLink = onError(...)
const httpLink = new HttpLink(...)
const link = ApolloLink.from([
  errorLink,
  httpLink,
])
const client = new ApolloClient({
  link,
  cache,
})