All files / app/assets/javascripts/packages_and_registries/settings/group/graphql/utils cache_update.js

100% Statements 12/12
100% Branches 6/6
100% Functions 3/3
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34      28x 21x       21x   21x 21x 9x       21x 7x       21x 5x           21x          
import { produce } from 'immer';
import getGroupPackagesSettingsQuery from '../queries/get_group_packages_settings.query.graphql';
 
export const updateGroupPackageSettings = (fullPath) => (client, { data: updatedData }) => {
  const queryAndParams = {
    query: getGroupPackagesSettingsQuery,
    variables: { fullPath },
  };
  const sourceData = client.readQuery(queryAndParams);
 
  const data = produce(sourceData, (draftState) => {
    if (updatedData.updateNamespacePackageSettings) {
      draftState.group.packageSettings = {
        ...updatedData.updateNamespacePackageSettings.packageSettings,
      };
    }
    if (updatedData.updateDependencyProxySettings) {
      draftState.group.dependencyProxySetting = {
        ...updatedData.updateDependencyProxySettings.dependencyProxySetting,
      };
    }
    if (updatedData.updateDependencyProxyImageTtlGroupPolicy) {
      draftState.group.dependencyProxyImageTtlPolicy = {
        ...updatedData.updateDependencyProxyImageTtlGroupPolicy.dependencyProxyImageTtlPolicy,
      };
    }
  });
 
  client.writeQuery({
    ...queryAndParams,
    data,
  });
};