Invalid Auth Token with Rails, Graphql, Apollo Client

后端 未结 7 1643
北海茫月
北海茫月 2021-02-09 13:06

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

7条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-09 13:51

    Since Apollo 2.0 and according to

    https://github.com/apollographql/apollo-client/blob/master/Upgrade.md

    Just do this way

    const csrfToken = document.querySelector('meta[name=csrf-token]').getAttribute('content');
    const client = new ApolloClient({
        link: new HttpLink({
            credentials: 'same-origin',
            headers: {
                'X-CSRF-Token': csrfToken
            }
        }),
        cache: new InMemoryCache()
    });
    

提交回复
热议问题