MCPcopy Create free account
hub / github.com/emwalker/digraph / makeUpdater

Function makeUpdater

client/src/mutations/upsertLinkMutation.ts:24–61  ·  view source on GitHub ↗
(parentTopicId: string | null)

Source from the content-addressed store, hash-verified

22}
23
24function 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
63const query = graphql`
64 mutation upsertLinkMutation($input: UpsertLinkInput!) {

Callers 1

makeUpsertLinkCallbackFunction · 0.70

Calls 2

hasErrorsFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected