4

How to set custom header on @nuxtjs/apollo?

on my nuxt.config.js

I have something like this

apollo: {
  "x-token": "hash",
  "x-auth-token": "hash",
  "x-refresh-token":  "hash",
  headers: {
  },
  clientConfigs: {
    default: {
      // required
      httpEndpoint: "localhost:4000"
    }
  }
}

Thanks

Riku
  • 652
  • 1
  • 9
  • 24

1 Answers1

1

Like this:

nuxt.conifg.js

apollo: {
  clientConfigs: {
    default: {
      httpEndpoint: 'localhost:4000',
      httpLinkOptions: {
        headers: {
           'x-token': 'hash',
           'x-auth-token': 'hash',
           'x-refresh-token':  'hash'
        }
      }
    }
  }
},
Imre_G
  • 2,468
  • 1
  • 17
  • 33
  • I also tried that one earlier, but there an error, "Converting circular structure to JSON" The endpoint is working on fine on React. – Riku Nov 13 '18 at 14:21
  • The apollo module just got rewritten and I think this is still a release candidate and not an actual release, so this is probably a bug. What you could do is fall back to the old way by defining a path like this `default: '~/apollo/client-configs/default.js'` and then add the httplink options manually. – Imre_G Nov 13 '18 at 14:37
  • i see, ill try to create a separate config then import it on nuxt.config.js Thanks. – Riku Nov 13 '18 at 15:09