Invalid Auth Token with Rails, Graphql, Apollo Client

后端 未结 7 1655
北海茫月
北海茫月 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 14:04

    this one works fine for me.

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

提交回复
热议问题