relay-rails-blog icon indicating copy to clipboard operation
relay-rails-blog copied to clipboard

Is it possible to have server-side rendering?

Open mongjong59 opened this issue 8 years ago • 2 comments

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?

mongjong59 avatar Jan 06 '17 04:01 mongjong59

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.

gauravtiwari avatar Jan 06 '17 08:01 gauravtiwari

@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?

mongjong59 avatar Feb 19 '17 08:02 mongjong59