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

API suggestions #1

Open
josephsavona opened this issue May 28, 2017 · 0 comments
Open

API suggestions #1

josephsavona opened this issue May 28, 2017 · 0 comments

Comments

@josephsavona
Copy link

josephsavona commented May 28, 2017

Hey @robrichard! Thanks again for publishing this! Following up on our discussion on your PR, I have a couple suggestions for the API. Mainly it would be nice to hide the details a bit - for example not requiring the user to call retain() or sendQuery(). An example of this style is @denvned's https://github.com/denvned/isomorphic-relay

For Relay Modern, the equivalent might be something like:

// server
import { prefetchQuery, Renderer } from '...';

async function serverRender() {
  const {data, props} = await prefetchQuery(environment, graphql`...`, variables); // throws on error
  const markup = React.renderToString(
    <Renderer {...props} />
  );
  // render markup plus JSON.stringify(data)
}

// client
import {loadPrefetchedQuery, Renderer} from '...';
const props = loadPrefetchedQuery(env, query, vars, data); // data is JSON.parse(...) of data from server
ReactDOM.render(
  <Renderer {...props} />
);

Key points are that the details are hidden from the user, and that Renderer accepts input that is most easily created by executing one of prefetchQuery() (server) or loadPrefetchedQuery() (client). As far as loading prefetched data on the client, you can use environment.getStore().publish(new Source(data)).

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

1 participant