relay
relay copied to clipboard
TypeScript: Property 'invalidateStore' does not exist on type 'RecordSourceProxy'
When using commitLocalUpdate
to invalidate the store the TS compiler throws and error:
Property 'invalidateStore' does not exist on type 'RecordSourceProxy'
You can reproduce by writing the following in a TypeScript project:
commitLocalUpdate(relayEnvironment, (store : RecordSourceProxy) => {
store.invalidateStore(); // Property 'invalidateStore' does not exist on type 'RecordSourceProxy'
});
I believe that RecordSourceProxy
needs to be updated in updater: StoreUpdater
to RecordSourceSelectorProxy
.
If someone points me in the right direction on where to make this change, I can make a PR.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
A year after, the issue is still there. It's seems to be possible to invalidate store after mutation, but it isn't when using commitLocalUpdate
Would be super helpful to have this implemented or for there to be another documented alternative to invalidating the store outside of a mutation or subscription.
This is already fixed by the typescript implementation here: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/relay-runtime/lib/mutations/commitLocalUpdate.d.ts
And @vxm5091 you should be able to do something like this to invalidating the store:
import { useRelayEnvironment } from 'react-relay/hooks'
import { commitLocalUpdate } from 'react-relay';
export const useInvalidateRelayStore = () => {
const environment = useRelayEnvironment();
return () => {
commitLocalUpdate(environment, store => {
store.invalidateStore()
});
};
}
I think we can close this issue in my opinion.