feat: refactor verify connection mutation with the REST API endpoint

This commit is contained in:
kasia.oczkowska
2024-09-20 13:05:21 +01:00
committed by Ali BARIN
parent dc0273148c
commit 4d5fc50f1a
8 changed files with 37 additions and 92 deletions

View File

@@ -6,36 +6,7 @@ const cache = new InMemoryCache({
},
Mutation: {
mutationType: true,
fields: {
verifyConnection: {
merge(existing, verifiedConnection, { readField, cache }) {
const appKey = readField('key', verifiedConnection);
const appCacheId = cache.identify({
__typename: 'App',
key: appKey,
});
cache.modify({
id: appCacheId,
fields: {
connections: (existingConnections) => {
const existingConnectionIndex = existingConnections.findIndex(
(connection) => {
return connection.__ref === verifiedConnection.__ref;
}
);
const connectionExists = existingConnectionIndex !== -1;
// newly created and verified connection
if (!connectionExists) {
return [verifiedConnection, ...existingConnections];
}
return existingConnections;
},
},
});
return verifiedConnection;
},
},
},
fields: {},
},
},
});