Joon
Joon

Reputation: 9874

How to manually update Relay store without querying server?

Let's say I have some data that I obtained through a non-graphql endpoint for example from third party server (firebase).

How do I put the data into the local relay store? Is there an easy way to add / edit / overwrite data to relay store directly without going through query or mutation?

Upvotes: 5

Views: 844

Answers (2)

brysgo
brysgo

Reputation: 848

I would use relay without a server, defining your graphql schema locally and doing your API requests from your graphql schema the same way you would query a database in your schema.

https://github.com/relay-tools/relay-local-schema

Upvotes: 0

Igorsvee
Igorsvee

Reputation: 4201

A non public RelayStoreData field is accessible from the Relay.Store instance and it gives you direct access to the records contained in the store. I haven't done anything with this myself but you could try modifying the cache directly like this:

RelayStore._storeData._cachedStore._records[recordId][fieldName]=newValue

Upvotes: 3

Related Questions