Invalid Auth Token with Rails, Graphql, Apollo Client

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

    To clarify some of the above answers, since one of the users noted that passing in the uri as a first argument to createNetworkInterface works but logs a deprecation message in the console: you have to pass in options like "credentials" and "headers" in as properties of an options object like so:

    const networkInterface = createNetworkInterface({
      uri: '/graphql',
      opts: {
        credentials: 'same-origin',
        headers: {
          'X-CSRF-TOKEN': $('meta[name=csrf-token]').attr('content'),
        },
      },
    });
    

    See the second example under Fetch in the docs: http://dev.apollodata.com/core/network.html

提交回复
热议问题