facebook / facebook/relay

RecordProxy returns 'undefined' in delete mutation.

Open
#3,470 2 comments 0 reactions 0 assignees View on GitHub
wontfix
Dominant language
Rust
Stars
19k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

I'm trying to implement a delete mutation. Even if the relay dev tools shows the connection I cannot get the RecordProxy in the store. I have checked the RecordSelectorProxy instance returned by the updater function. It returns the instance but the record corresponding to userId is undefined (VXNlck5vZGU6MTY1: undefined) as follows:

```
RelayRecordSourceSelectorProxy {__mutator: RelayRecordSourceMutator, __recordSource: RelayRecordSourceProxy, _readSelector: {…}}
__mutator: RelayRecordSourceMutator
__sources: (2) [RelayMapRecordSourceMapImpl, RelayMapRecordSourceMapImpl]
_base: RelayMapRecordSourceMapImpl {_records: Map(2)}
_sink: RelayMapRecordSourceMapImpl {_records: Map(2)}
__proto__: Object
__recordSource: RelayRecordSourceProxy
__mutator: RelayRecordSourceMutator {__sources: Array(2), _base: RelayMapRecordSourceMapImpl, _sink: RelayMapRecordSourceMapImpl}
_getDataID: ƒ defaultGetDataID(fieldValue, typeName)
_handlerProvider: null
_idsMarkedForInvalidation: Set(0) {}
_invalidatedStore: false
_proxies:
VXNlck5vZGU6MTY1: undefined
client:local:0: RelayRecordProxy {_dataID: "client:local:0", _mutator: RelayRecordSourceMutator, _source: RelayRecordSourceProxy}
client:local:0:deleteSubscription(input:{"subId":"R2VuZXJhbFN1YnNjcmlwdGlvbk5vZGU6NjQ4"}): RelayRecordProxy {_dataID: "client:local:0:deleteSubscription(input:{"subId":"R2VuZXJhbFN1YnNjcmlwdGlvbk5vZGU6NjQ4"})", _mutator: RelayRecordSourceMutator, _source: RelayRecordSourceProxy}
__proto__: Object
__proto__: Object
_readSelector: {kind: "SingularReaderSelector", dataID: "client:local:0", isWithinUnmatchedTypeRefinement: false, node: {…}, variables: {…}, …}
__proto__: Object
```

## Store as shown in dev tools:
https://ibb.co/VLHKhFF

## Mutation:
```
const mutation = graphql`
mutation DeleteSubscriptionMutation($input: DeleteSubscriptionInput!) {
deleteSubscription(input: $input) {
deletedSubscriptionId
}
}
`;

function sharedUpdater(store, deletedSubscriptionId) {
const userProxy = store.get(localStorage.getItem(GC_USER_ID));

console.log(userProxy);
const connection = ConnectionHandler.getConnection(
userProxy,
"SettingsPage_userSubscriptions"
);

if (connection) {
ConnectionHandler.deleteNode(connection, deletedSubscriptionId);
}
}

export default (subId, callback) => {
const variables = {
input: {
subId: subId
}
};

commitMutation(environment, {
mutation,
updater(store) {
const payload = store.getRootField("deleteSubscription");
sharedUpdater(store, payload.getValue("deletedSubscriptionId"));
},
optimisticUpdater(store) {
sharedUpdater(store, subId);
},
variables,
>> onCompleted: (response, errors) => {
if (response.deleteSubscription != null) {
callback();
} else {
console.log("Unable to delete subscription!");
}
},
onError: err => console.error(err)
});
};

```

## Root Query:

```
const userDetailsQuery = graphql`
query SettingsPageContainerWrapper_UserDetails_Query($id: ID!, $user: ID) {
user(id: $id) {
email
isPremium
isActive
...SettingsPage_user_Subscription @arguments(user: $user)
}
settings {
isAuthenticated
userId
isNavActivated
selectedSourceId
selectedParentId
treeStates
selectedNodeId
isParent
}
}
`;

```
## Fragment:
```
export default createFragmentContainer(SettingsPage, {
user_Subscription: graphql`
fragment SettingsPage_user_Subscription on UserNode
@argumentDefinitions(user: { type: "ID" }) {
userSubscriptions(user: $user, first: 100)
@connection(key: "SettingsPage_userSubscriptions", filters: []) {
edges {
node {
id
name
parent {
id
}
}
}
}
}
`
});

```
## Errors in Console log:
```
1. TypeError: Cannot read property 'getLinkedRecord' of undefined

2. Warning: A store update was detected within another store update. Please make sure new store updates aren’t being executed within an updater function for a different update.

3. RelayObservable: Unhandled Error TypeError: Cannot read property 'getLinkedRecord' of undefined

```
Please help.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.