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

Is it possible to have server-side rendering? #11

Open
mongjong59 opened this issue Jan 6, 2017 · 2 comments
Open

Is it possible to have server-side rendering? #11

mongjong59 opened this issue Jan 6, 2017 · 2 comments

Comments

@mongjong59
Copy link

I tried to set up server-side rendering with isomorphic-relay. But I got stuck because it seems that with ExecJS (with Node.js backend), Promises can't be consumed. I tried a very basic Promise in my server startup file.

var promise = Promise.resolve("foobar");
var response = promise.then((res) => { console.log(res) }, (e) => {console.log(e)})
console.log(response)

The above code will log [Object Promise]. But normally it should be foobar and {}. I didn't find much about whether Promise are supported in ExecJS. But this is obviously a key in server-side rendering with a GraphQL client. Do you have any idea on this issue?

@gauravtiwari
Copy link
Owner

Hey @nostophilia, I haven't tried server side rendering with relay yet. You can checkout this repo, https://github.com/brandfolder/rails-graphql-relay (looks outdated though). I will look into this too.

@mongjong59
Copy link
Author

mongjong59 commented Feb 19, 2017

@gauravtiwari
Seems we can get it work by means of React on Rails Node.js SSR (I pushed a fix on the server file, merged with v6.5.0).

However it doesn't seem an ideal way as it means extra Rails call stack which is not necessary. It would be great if we can:

  1. extract GraphQL queries for the app on Rails side
  2. Schema.execute(query)
  3. hydrate Relay/Apollo store
  4. render the app

This seems more feasible with Relay as the code of Isomorphic React Relay implies while the getQueriesFromTree of Apollo doesn't seem to return root queries with all sub-queries. Do you have idea whether there's an API for extracting root queries in Relay or Apollo and do they both support store hydration?

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

No branches or pull requests

2 participants