我有一个带有 GraphQL 的快速后端,当我去/graphiql
手动执行一些搜索时它可以工作。我的 React 前端正在尝试在后端执行搜索。以下代码应异步执行查询:
const data = await this.props.client.query({
query: MY_QUERY,
variables: { initials: e.target.value }
});
console.log(data);
WhereMY_QUERY
是之前定义的,代表一个我知道有效并且已经过测试的查询/graphiql
。为了在我的 React 组件中执行此操作,我将其导出为export default withApollo(MyComponent)
它client
在props
.
在index.js
我通过 Apollo 定义的文件中,连接到/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
});
link
在没有处理错误的变量的情况下执行上述查询时,我400 Bad Request
从服务器(ApolloError.js:37 Uncaught (in promise) Error: Network error: Response not successful: Received status code 400
)收到一个。由于这并没有告诉我更多信息,因此在 StackOverflow 和 Apollo 网页上,我发现上面的错误声明输出[Network error]: TypeError: forward is not a function
. 这个错误是什么意思,我该如何解决?
谢谢!