2022-11-23 12:31:31 -08:00
|
|
|
import { ListDomainsDocument, ListDomainsQuery } from '../../graphql/domain.generated';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add an entry to the list domains cache.
|
|
|
|
|
*/
|
2022-12-23 11:06:47 -08:00
|
|
|
export const addToListDomainsCache = (client, newDomain, pageSize) => {
|
2022-11-23 12:31:31 -08:00
|
|
|
// Read the data from our cache for this query.
|
|
|
|
|
const currData: ListDomainsQuery | null = client.readQuery({
|
|
|
|
|
query: ListDomainsDocument,
|
|
|
|
|
variables: {
|
|
|
|
|
input: {
|
|
|
|
|
start: 0,
|
|
|
|
|
count: pageSize,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Add our new domain into the existing list.
|
|
|
|
|
const newDomains = [newDomain, ...(currData?.listDomains?.domains || [])];
|
|
|
|
|
|
|
|
|
|
// Write our data back to the cache.
|
|
|
|
|
client.writeQuery({
|
|
|
|
|
query: ListDomainsDocument,
|
|
|
|
|
variables: {
|
|
|
|
|
input: {
|
|
|
|
|
start: 0,
|
|
|
|
|
count: pageSize,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
data: {
|
|
|
|
|
listDomains: {
|
|
|
|
|
start: 0,
|
|
|
|
|
count: (currData?.listDomains?.count || 0) + 1,
|
|
|
|
|
total: (currData?.listDomains?.total || 0) + 1,
|
|
|
|
|
domains: newDomains,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Remove an entry from the list domains cache.
|
|
|
|
|
*/
|
2022-12-23 11:06:47 -08:00
|
|
|
export const removeFromListDomainsCache = (client, urn, page, pageSize) => {
|
2022-11-23 12:31:31 -08:00
|
|
|
// Read the data from our cache for this query.
|
|
|
|
|
const currData: ListDomainsQuery | null = client.readQuery({
|
|
|
|
|
query: ListDomainsDocument,
|
|
|
|
|
variables: {
|
|
|
|
|
input: {
|
|
|
|
|
start: (page - 1) * pageSize,
|
|
|
|
|
count: pageSize,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Remove the domain from the existing domain set.
|
|
|
|
|
const newDomains = [...(currData?.listDomains?.domains || []).filter((domain) => domain.urn !== urn)];
|
|
|
|
|
|
|
|
|
|
// Write our data back to the cache.
|
|
|
|
|
client.writeQuery({
|
|
|
|
|
query: ListDomainsDocument,
|
|
|
|
|
variables: {
|
|
|
|
|
input: {
|
|
|
|
|
start: (page - 1) * pageSize,
|
|
|
|
|
count: pageSize,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
data: {
|
|
|
|
|
listDomains: {
|
|
|
|
|
start: currData?.listDomains?.start || 0,
|
|
|
|
|
count: (currData?.listDomains?.count || 1) - 1,
|
|
|
|
|
total: (currData?.listDomains?.total || 1) - 1,
|
|
|
|
|
domains: newDomains,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
};
|