I have an express back-end with GraphQL that works when I go to /graphiql
and manually perform some searches. My React front-end is trying to perform a search on the back-end. The following code should perform the query asynchronously:
const data = await this.props.client.query({
query: MY_QUERY,
variables: { initials: e.target.value }
});
console.log(data);
Where MY_QUERY
is defined before and represents a query that I know works and has been tested on /graphiql
. To do this in my React component I export it as export default withApollo(MyComponent)
so that it has the client
variable in the props
.
In the index.js
file I defined through Apollo the connection to /graphiql
in order to perform the queries:
//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
});
When executing the above mentioned query without the link
variable that handles the error, I receive a 400 Bad Request
from the server (ApolloError.js:37 Uncaught (in promise) Error: Network error: Response not successful: Received status code 400
). Since this doesn't tell me more, here on StackOverflow and on the Apollo Web page I've found the above error declaration that outputs [Network error]: TypeError: forward is not a function
. What does this error mean and how do I solve it?
Thanks!