Skip to content
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 for serverside rendering #1290

Closed
wants to merge 6 commits into from

Conversation

toddtarsi
Copy link

@toddtarsi toddtarsi commented Jul 18, 2016

First off, thank you guys for making this. This codebase is really awesome, and I love the approach to everything. Currently though, the main known open source serverside rendering solution (isomorphic-relay, another great codebase) is kind of in a bad spot when it comes to credential passing.

An example of this can be seen with isomorphic-relay, where the solution for passing httponly cookies in serverside rendering involves converting the endpoint to run sequentially, which is a major deoptimizer. By exposing overrides like this, we could skirt that approach by instead just passing in one off data into the sendQueries call.

Admittedly, I don't know this codebase all too well, and there are probably a lot of gotchas I'm overlooking, but I wanted to put this out there and just see what your guys thoughts were. Also, if you just want to see more polish and consistency, let me know and I can refactor / rebase this as needed.

Thanks as always!

This should help with serverside rendering to allow for things like credential passing on proxied requests.
This helps for serverside rendering implementations, particularly in credential passing.
@ghost
Copy link

ghost commented Jul 18, 2016

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks!

@ghost ghost added the CLA Signed label Jul 18, 2016
@josephsavona
Copy link
Contributor

josephsavona commented Jul 18, 2016

Thanks for the PR. We're open to considering this, but can you provide more detail as to why this is needed and how it would be used? It would be helpful to have a link to examples or docs of how isomorphic-relay is forced to do serial fetching w/o this.

@ghost
Copy link

ghost commented Jul 18, 2016

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@toddtarsi
Copy link
Author

Absolutely, thank you for the prompt response:

This issue is closed in isomorphic-relay-router, but a quick read will help explain the issue:

denvned/isomorphic-relay-router#13

By exposing this code in relay, and then adding an extra argument for overrides to the prepareData operation in isomorphic-relay-router and isomorphic-relay, we could pass through cookie data to the sendQueries call that these wrap without the overhead of the solution above.

@toddtarsi
Copy link
Author

toddtarsi commented Jul 18, 2016

Ha, on second thought, that issue tracker rambles:
TLDR: Since node-fetch proxies requests, and there isn't a one off way to override these, serverside rendering hits a challenge where it needs to override this using injectNetworkLayer. Since injectNetworkLayer is a global, the only current solution is to guard from async attack vectors by converting the stack to run sequentially.
By allowing for an override to request details in the sendQueries call, it gives us a method to customize each request batch without injecting a new global network layer each time on the server.

Making sure CI build passes
I can rebase this pull down to 1 commit if it pans out
toddtarsi added a commit to toddtarsi/isomorphic-relay that referenced this pull request Jul 19, 2016
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.
@ghost ghost added the CLA Signed label Jul 19, 2016
toddtarsi added a commit to toddtarsi/isomorphic-relay-router that referenced this pull request Jul 19, 2016
Capstone to denvned/isomorphic-relay#43 and facebook/relay#1290
Allows for serverside rendering without a FIFO system
@ghost ghost added the CLA Signed label Jul 19, 2016
@toddtarsi
Copy link
Author

Hey all, after talking with @robrichard, it sounds like my use case was resolved when Relay.environment was able to be used non-globally.
denvned/isomorphic-relay#43
Thanks for taking the time to look this over, and if you'd like I can close this pull request now.
My use cases are resolved I believe.

@ghost ghost added the CLA Signed label Jul 19, 2016
@josephsavona
Copy link
Contributor

josephsavona commented Jul 19, 2016

@toddtarsi Great, I really thought we had already resolved that, glad Relay.Environment is working as intended :-). Thanks for the PR and for following up!

@toddtarsi
Copy link
Author

Absolutely, thanks for the quick responses from everyone. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants