Invalid Auth Token with Rails, Graphql, Apollo Client

后端 未结 7 1804
北海茫月
北海茫月 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:54

    Using apollo-boost, it's a little different.

    import ApolloClient from 'apollo-boost'
    
    const client = new ApolloClient({
      fetchOptions: {
        credentials: 'same-origin',
      },
      request: (operation) => {
        const csrfToken = document.querySelector('meta[name=csrf-token]').getAttribute('content')
        operation.setContext({
          headers: { "X-CSRF-Token": csrfToken }
        })
      },
    })
    

提交回复
热议问题