(parentTopicId: string | null)
| 22 | } |
| 23 | |
| 24 | function makeUpdater(parentTopicId: string | null) { |
| 25 | if (!parentTopicId) return null |
| 26 | |
| 27 | return (store: RecordSourceSelectorProxy) => { |
| 28 | const connectionId = ConnectionHandler.getConnectionID(parentTopicId, |
| 29 | 'ViewTopicPage_topic_children', { searchString: '' }) |
| 30 | |
| 31 | if (!connectionId) { |
| 32 | console.log('no connection id found under topic:', parentTopicId) |
| 33 | return |
| 34 | } |
| 35 | |
| 36 | const connection = store.get(connectionId) |
| 37 | if (!connection) return |
| 38 | |
| 39 | const payload = store.getRootField('upsertLink') |
| 40 | if (!payload) { |
| 41 | console.log('payload not found in mutation response') |
| 42 | return |
| 43 | } |
| 44 | |
| 45 | if (hasErrors(payload)) return |
| 46 | |
| 47 | const linkEdge = payload.getLinkedRecord('linkEdge') |
| 48 | if (!linkEdge) { |
| 49 | console.log('no topic edge found in mutation response') |
| 50 | return |
| 51 | } |
| 52 | |
| 53 | const prevEdges = connection.getLinkedRecords('edges') || [] |
| 54 | const index = prevEdges.findIndex((edge) => { |
| 55 | const node = edge.getLinkedRecord('node') |
| 56 | return node?.getValue('__typename') == 'Link' |
| 57 | }) |
| 58 | prevEdges.splice(index, 0, linkEdge) |
| 59 | connection.setLinkedRecords(prevEdges, 'edges') |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | const query = graphql` |
| 64 | mutation upsertLinkMutation($input: UpsertLinkInput!) { |
no test coverage detected