-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to dynamically change the network layer? #1215
Comments
Very strange, but it should work. If it does not help, you may try my OSS implementation of network layer https://github.com/nodkz/react-relay-network-layer It contains several good middlewares, which solves common tasks. So your code may be implemented such way: const tokenInGlobalVars = null;
signIn().then(token => {
tokenInGlobalVars = token;
});
Relay.injectNetworkLayer(new RelayNetworkLayer([
urlMiddleware({
url: (req) => 'http://some-server/graphql', // this method will be called every time, so you may change url on fly
}),
authMiddleware({
token: () => tokenInGlobalVars,
allowEmptyToken: true,
}),
], { disableBatchQuery: true })); Also was discussion where and how to store a token on the client side: relay-tools/react-relay-network-layer#6 |
I already in 0.9.0, I am sure when calling injectNetworkLayer second time, it will cause an exception. @nodkz, thanks for your powerful library, I will use it soon. |
I'd recommend using @nodkz's layer like he describes. The intention is to not inject new network layers all the time, but rather inject a single layer that is flexible enough to embody your desired behavior. (We made this stricter in response to bugs that cropped up internally in large apps where we were trying to update the layer in multiple places and unknowingly clobbering previous adjustments.) As I think this is now resolved, going to mark it as closed. |
How to call injectNetworkLayer without token when bootstrapping, and then overwrite the networklayer after signing in, like the following code shows:
The text was updated successfully, but these errors were encountered: