I am trying to get a basic Rails, Graphql, Apollo-Client setup working but having trouble with 422 errors \'invalid auth token\' on the rails side.
Does my use of apoll
I was experimenting with Apollo on Rails the other day, here's the configuration that worked for me:
var RailsNetworkInterface = apollo.createNetworkInterface('/graphql', {
credentials: 'same-origin',
headers: {
'X-CSRF-Token': $("meta[name=csrf-token]").attr("content"),
}
});
var client = new apollo.ApolloClient({networkInterface: RailsNetworkInterface})
client.query({ query: gql`{ event(id: 7) { name } }`})
But, it seems like yours would work just as well!
Can you confirm that the proper token is being sent to the server? For example, if you open the network tab of Chrome devtools, then make a query, can you see the X-CSRF-Token in the "Request Headers" section?
Also, it's possible that Rails is updating the CSRF token in the DOM, but the NetworkInterface keeps the old, stale CSRF token. Can you confirm that the token in the "Request Headers" section matches the current value in the tag? (I was surprised that I didn't encounter this problem myself, using Turbolinks Classic.)