feat: refactor verify connection mutation with the REST API endpoint
This commit is contained in:

committed by
Ali BARIN

parent
dc0273148c
commit
4d5fc50f1a
@@ -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: {},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
Reference in New Issue
Block a user