Relay: Warning that injecting a network layer would overwrite a previously injected layer

Created on 6 May 2016  路  7Comments  路  Source: facebook/relay

Since 0.8.1 I am receiving this new warning >> Warning: RelayNetworkLayer: Call received to injectImplementation(), but a layer was already injected. << when I try to inject my default network layer. I want to separate my GraphQL server from my React/Relay app. I have not injected any other network layer before that. Relay seems to do this by default.

Relay.injectNetworkLayer(
  new Relay.DefaultNetworkLayer(process.env.GRAPHQL_ENDPOINT)
);

What is the right way to go about it to avoid this warning?

Most helpful comment

This is fixed and will be resolved in the next release (see #1111). Sorry about the noise, and thanks for the report!

All 7 comments

This is fixed and will be resolved in the next release (see #1111). Sorry about the noise, and thanks for the report!

@wincent I still see this warning when using Relay.injectNetworkLayer(new Relay.DefaultNetworkLayer(url, options)) with [email protected].

@sedubois: That suggests that a layer was already injected. Would need to see some code to troubleshoot further.

@wincent Yes, a layer was already injected, but I want to update the headers after user authentication. The code is here.

a layer was already injected

Then everything is working as intended. This is why this is a warning and not an error. The purpose is to help people avoid overwriting a layer by mistake (this actually happened at FB, when two separate teams had their own competing layers in a shared context) but still allow people who have a legitimate reason for injecting more than once to do so, albeit with a warning.

If the warning is truly obnoxious to you then we could look at adding a force kind of flag to effectively suppress the warning.

This is why this is a warning and not an error

@wincent It's actually an error (red and still appears when filtering only for Errors in chrome console):

screen shot 2016-10-25 at 18 22 33

If the warning is truly obnoxious to you then we could look at adding a force kind of flag to effectively suppress the warning.

That would be really welcome, yes 馃槉 I believe the scenario I described is valid and common, and should therefore not pollute the console.

It uses warning (here). Seems like that ends up calling console.error. Feel free to submit a PR.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fedbalves picture fedbalves  路  3Comments

piotrblasiak picture piotrblasiak  路  3Comments

bondanherumurti picture bondanherumurti  路  3Comments

derekdowling picture derekdowling  路  3Comments

HsuTing picture HsuTing  路  3Comments