diff options
Diffstat (limited to 'app/assets/javascripts/packages_and_registries/settings/group/graphql/utils')
2 files changed, 33 insertions, 0 deletions
diff --git a/app/assets/javascripts/packages_and_registries/settings/group/graphql/utils/cache_update.js b/app/assets/javascripts/packages_and_registries/settings/group/graphql/utils/cache_update.js new file mode 100644 index 00000000000..06b57fe013f --- /dev/null +++ b/app/assets/javascripts/packages_and_registries/settings/group/graphql/utils/cache_update.js @@ -0,0 +1,22 @@ +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) => { + // eslint-disable-next-line no-param-reassign + draftState.group.packageSettings = { + ...updatedData.updateNamespacePackageSettings.packageSettings, + }; + }); + + client.writeQuery({ + ...queryAndParams, + data, + }); +}; diff --git a/app/assets/javascripts/packages_and_registries/settings/group/graphql/utils/optimistic_responses.js b/app/assets/javascripts/packages_and_registries/settings/group/graphql/utils/optimistic_responses.js new file mode 100644 index 00000000000..f2c8de85bf8 --- /dev/null +++ b/app/assets/javascripts/packages_and_registries/settings/group/graphql/utils/optimistic_responses.js @@ -0,0 +1,11 @@ +export const updateGroupPackagesSettingsOptimisticResponse = (changes) => ({ + // eslint-disable-next-line @gitlab/require-i18n-strings + __typename: 'Mutation', + updateNamespacePackageSettings: { + __typename: 'UpdateNamespacePackageSettingsPayload', + errors: [], + packageSettings: { + ...changes, + }, + }, +}); |