Currently, I am using apollo-client on my web server to interact with my graphql server (which is also apollo). While I have successfully implemented a query that retrieves data correctly, I encounter new ApolloError
messages when attempting a mutation. Oddly enough, when I directly paste the same mutation into GraphiQL, it works flawlessly.
I have ensured that CORS is enabled and functioning properly on my graphql server. As mentioned earlier, copying and pasting the mutation from my code editor into the GraphiQL editor yields successful results.
If anyone could provide insight into this issue or direct me on how to access more detailed information on my graphql-server regarding why I'm receiving a 400
error, it would be greatly appreciated.
Below is the Apollo error output:
{
"graphQLErrors": [],
"networkError": {
"response": {
"url": "http://localhost:9000/api/private",
"status": 400,
"statusText": "Bad Request",
...
}
},
"message": "Network error: Network request failed with status 400 - \"Bad Request\""
}
Error
at new ApolloError (/Users/rkstar/dev/projects/crate/microservices/dashboard/node_modules/apollo-client/apollo.umd.js:1490:23)
at /Users/rkstar/dev/projects/crate/microservices/dashboard/node_modules/apollo-client/apollo.umd.js:2149:24
at process._tickCallback (internal/process/next_tick.js:103:7)
**** UPDATE ****
I have added middleware before my apolloMiddleware
to log the req.headers and req.body information:
req.headers -------
{
"accept": "*/*",
"content-type": "application/json",
"authorization": "JWT ",
...
}
req.body -------
{
"query": "mutation updateTwitterAccessToken($data: TokenInput!) {\n updateTwitterToken(data: $data) {...\n}\n}",
"variables": {
"data": {
"accessToken": "...",
...
}
},
"operationName": "updateTwitterAccessToken"
}
When calling client.mutate({ ... })
from my web server, I notice that in the req.body
, the property is set as:
req.body -------
{
"query": "mutation ..."
....
}
The confusion lies in why it shows "query": "mutation ..."
instead of "mutation": "mutation ..."
. Any insights on this discrepancy?