Apollo-client: how to override the uri of the apollo client's network interface?

Created on 7 Feb 2017  路  4Comments  路  Source: apollographql/apollo-client

long story short: i'd like to override the uri of the apollo client's network interface without creating a new one.
i share the initial client with the combined redux reducer so it's mandatory to use the same instance. i tried to override the networkInterface property of the client but it doesn't work and maybe it should not and i tried to override the uri with a middleware but it's not clear what property of the request object should i set in there.

  1. is it possbile to create a network interface without setting the uri? i couldn't do that so i use a dummy uri at the moment
  2. is it possible to override the uri of the apollo client at all?
  3. what is the preferred way to do that?

Most helpful comment

import { HTTPFetchNetworkInterface } from 'apollo-client'

class NetworkInterface extends HTTPFetchNetworkInterface {
  setUri(uri) {
    this._uri = uri
  }
}

const networkInterface = new NetworkInterface('/grapqlendpoint1')
networkInterface.setUri('/graphqlendpoint2')

thanks @calebmer !

All 4 comments

I'm also interested in this. I tried a few methods of trying to set the client's uri in context for the rest of the tree, but ultimately I had to create new clients.

If you want to do this, you should write your own network interface! 馃槉

It鈥檚 not that bad, you can even extend HTTPFetchNetworkInterface if you would like: https://github.com/apollographql/apollo-client/blob/master/src/transport/networkInterface.ts

import { HTTPFetchNetworkInterface } from 'apollo-client'

class NetworkInterface extends HTTPFetchNetworkInterface {
  setUri(uri) {
    this._uri = uri
  }
}

const networkInterface = new NetworkInterface('/grapqlendpoint1')
networkInterface.setUri('/graphqlendpoint2')

thanks @calebmer !

Great! Looks like we can close this, thanks for the tip @calebmer

Was this page helpful?
0 / 5 - 0 ratings

Related issues

elie222 picture elie222  路  3Comments

helfer picture helfer  路  3Comments

canercandan picture canercandan  路  3Comments

treecy picture treecy  路  3Comments

timbotnik picture timbotnik  路  3Comments