denvned/isomorphic-relay

Document injected data format.

bigblind opened this issue · 5 comments

Hi,

I'd like to use just the client-side part of this. My app is built using Django, and I'd prefer not to add anything that requires javascript evaluation on the server. I can probably generate the json in Python. But in order to do that I'd like to know how the data is structured.

@bigblind if you're going to be rendering this client-side only, you should be able to use the regular react-relay module.

@bigblind naturally, it will become your responsibility as a developer to provide all the correct data that Relay would request if it was rendered on the server, and update the data whenever you update the components, etc. Should not be too hard, just something to keep in mind when you're making changes. I am not sure if I am reading the change logs correctly, but it seems like with 0.8 this is possible just with react-relay as @hellatan suggested?

@thelordoftheboards What API method on relay would I call then to inject the data? I asked about this in the Relay issue tracker, and they directed me here, and it seems pretty clear that I need the injectPreparedData method that isomorphic-relay provides.

@bigblind ok, i think i see what you mean based on your comment in your relay comment. As you mentioned, i would imagine you would use the injectPreparedData method in your client-side entry file and you would be responsible for passing the json to that method.

You'd obviously need to mimic the data structure that that method requires, which looks something like this:

[ { query:
     { calls: [],
       children: [Object],
       directives: [],
       fieldName: 'viewer',
       isDeferred: false,
       kind: 'Query',
       metadata: [Object],
       name: 'CollectionsLandingQueryRoute',
       type: 'Viewer' },
    result: { viewer: [Object] } } ]

Hypothetically it sounds like it could work, but I'm pretty new to isomorphic react (as in started using it the past couple days) so I'm not 100% sure what the inner workings of injectPreparedData is doing.

The reason why there's query.result.viewer is due to this bug in relay.

The data is an array of { query: ConcreteQuery, response: Object }.

The shape of ConcreteQuery is described here. And the response is just a response of GraphQL server for that query. But note that ConcreteQuery is not a part of Relay public API, and can be changed or removed in any release. Also, isomorphic-relay might not use ConcreteQuery in future versions, but take advantage of GraphMode instead (when it is ready).