On client side, I have list of ids for nodes that I fetch from Firebase in real-time.
I want to fetch data for those ids using node(id: $id).
I can manually create something like nodes(ids: $ids), but the problem is that each node will not be cached by Relay based on its id.
To utilize proper caching by node id, the only option seems to be to run node(id: $id) for each id.
However, I don't know how to achieve this in one-round trip.
Any thoughts?
The results of nodes(ids: ...) _are_ cached by id, per record.
Wait... there is nodes(ids: ...) ??? I thought there only was node(id..). I feel stupid now.
@josephsavona I am sorry, but I am using graphql-relay-js, but it only provides nodeField not nodesField, am I missing something?
What I mean is that Relay understands this field. The response is expected to be an array where the Nth element corresponds to the Nth id of the ids argument array.
You can use any field, and as long as the returned object implements the node interface (and thus provides a globally unique ID), Relay will know how to cache it and later on use the node field to expand/refetch/efficiently load more fields.
For example, you can have a custom field apples( ids: [42, 666, 1024], withShape: "round"){ .... } That field returns an array of AppleType object, and if AppleType is configure to implement the node interface then you can do the initial fetch in one pass from apples(...), and the information will be cached by Relay. Then, when the user clicks on the apple to see more details, you want to fetch more data to get apple.farmer.location and Relay will do the partial query against the node field without you manually specifying it.
Wow. I didn't know Relay was that smart. Thank you all! I will close this issue.