react-relay-network-modern
react-relay-network-modern copied to clipboard
Add docs on adopting middleware
I may just be really dense, but hopefully this feedback is helpful. I've been using Relay with a fetchQuery function as detailed in the Relay docs. Now I'd like to add an Authorization header and came across this project to do so. Given it's middleware, I'd expect to set it up to wrap my fetchQuery function, but there's no indication in the docs how to do that. I came across an answer on StackOverflow that suggests using urlMiddleware in place of fetchQuery. If that's really the intended approach, I think the docs could be clearer in indicating that.
This project is not just middleware, it replaces the standard Network implementation (i.e. it defines its own fetchQuery) with an addition of middleware. So the answer you linked to in stackoverflow is really all the code you need to create the network part of the environment, so there is no need to define your own fetchQuery.
Okay. That's helpful, but I still think having a short transition section in the docs would be helpful. Even reading that StackOverflow answer, it's not clear to me how variables and query text ought to be handled. urlMiddleware doesn't have options for either and the StackOverflow answer glosses over that detail.
It may be that react-relay-network-modern does something sensible under the covers, but that's not really spelled out anywhere that I can find.
RelayNetworkLayer from this project is a full implementation of a Network Layer which implies that query text and variables are all handled under the hood. Use it instead of injecting a fetchQuery into the default Network, then when using any kind of functionality from Relay (like QueryRenderer etc.) each request and response will be passed through the middleware stack.