-
Notifications
You must be signed in to change notification settings - Fork 53
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
Allow for one off query overrides #43
Conversation
Hello, my name is Todd and I'm a huge fan of your codebase! An issue I'm encountering though is due to how the current solution for isomorphic rendering requires modifying the network global via injectNetworkLayer, so I'm pitching this change to the relay team: facebook/relay#1290 Instead of changing our serverside rendering context via injectNetworkLayer and routing queries through a FIFO system, I'd like to pass an overrides object as an additional argument, where fields are provided to modify my request as needed in the network layer. Please weigh in as you feel in both this thread and that one, as I am still getting comfortable with Relay. If this works for everyone though, this should be all that's needed to make server side rendering much cleaner.
Capstone to denvned/isomorphic-relay#43 and facebook/relay#1290 Allows for serverside rendering without a FIFO system
@toddtarsi what are you modifying in the requests in your override? Could you instead make a new network layer for each request? This is how you could do it if you needed to set unique auth info app.get('/my-route', function(req, res) {
const networkLayer = new Relay.DefaultNetworkLayer('https://example.com/graphql', {
headers: {
Authorization: req.get('Authorization')
}
});
IsomorphicRelay.prepareData(rootContainerProps, networkLayer).then({data, props} => {
...
})
}) |
You can do it that way, but I really worry about that. Doesn't that call From this thread On Tuesday, July 19, 2016, Rob Richard [email protected] wrote:
|
I could be wrong, but I think it's not an issue since relay 0.8.0. Prior to that, there was only one global Relay.Store. Now you can make a new Relay.Environment for each request, each with its own networkLayer. That's exactly what the current version of isomorphic-relay does (https://github.com/denvned/isomorphic-relay/blob/master/src/prepareData.js#L10). It's calling injectNetworkLayer on the custom environment, not the global Relay.injectNetworkLayer. |
Oh, awesome! Thank you very much for taking the time to explain that.
|
My use case is satisfied, and if you'd like, I can close this pull. Thanks! |
Closing this, thank you again @robrichard |
Hello, my name is Todd and I'm a huge fan of your codebase!
An issue I'm encountering though is due to how the current solution for serverside rendering requires modifying the network global via injectNetworkLayer, so I'm pitching this change to the relay team: facebook/relay#1290
Instead of changing our serverside rendering context via injectNetworkLayer and routing queries through a FIFO system, I'd like to pass an overrides object as an additional argument, where fields are provided to modify my request as needed in the network layer. Please weigh in as you feel in both this thread and that one, as I am still getting comfortable with Relay. If this works for everyone though, this should be all that's needed to make server side rendering much cleaner.