From 9297025d0b7ddf095eb618dfaaab2ff8f2018d8b Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Tue, 19 Dec 2023 11:01:45 +0000 Subject: Add latest changes from gitlab-org/gitlab@16-7-stable-ee --- .../javascripts/deploy_keys/graphql/client.js | 47 +++++++++ .../mutations/confirm_action.mutation.graphql | 3 + .../graphql/mutations/disable_key.mutation.graphql | 3 + .../graphql/mutations/enable_key.mutation.graphql | 3 + .../mutations/update_current_page.mutation.graphql | 3 + .../update_current_scope.mutation.graphql | 3 + .../queries/confirm_remove_key.query.graphql | 5 + .../graphql/queries/current_page.query.graphql | 3 + .../graphql/queries/current_scope.query.graphql | 3 + .../graphql/queries/deploy_keys.query.graphql | 26 +++++ .../javascripts/deploy_keys/graphql/resolvers.js | 106 +++++++++++++++++++++ .../deploy_keys/graphql/typedefs.graphql | 45 +++++++++ 12 files changed, 250 insertions(+) create mode 100644 app/assets/javascripts/deploy_keys/graphql/client.js create mode 100644 app/assets/javascripts/deploy_keys/graphql/mutations/confirm_action.mutation.graphql create mode 100644 app/assets/javascripts/deploy_keys/graphql/mutations/disable_key.mutation.graphql create mode 100644 app/assets/javascripts/deploy_keys/graphql/mutations/enable_key.mutation.graphql create mode 100644 app/assets/javascripts/deploy_keys/graphql/mutations/update_current_page.mutation.graphql create mode 100644 app/assets/javascripts/deploy_keys/graphql/mutations/update_current_scope.mutation.graphql create mode 100644 app/assets/javascripts/deploy_keys/graphql/queries/confirm_remove_key.query.graphql create mode 100644 app/assets/javascripts/deploy_keys/graphql/queries/current_page.query.graphql create mode 100644 app/assets/javascripts/deploy_keys/graphql/queries/current_scope.query.graphql create mode 100644 app/assets/javascripts/deploy_keys/graphql/queries/deploy_keys.query.graphql create mode 100644 app/assets/javascripts/deploy_keys/graphql/resolvers.js create mode 100644 app/assets/javascripts/deploy_keys/graphql/typedefs.graphql (limited to 'app/assets/javascripts/deploy_keys/graphql') diff --git a/app/assets/javascripts/deploy_keys/graphql/client.js b/app/assets/javascripts/deploy_keys/graphql/client.js new file mode 100644 index 00000000000..3c183963683 --- /dev/null +++ b/app/assets/javascripts/deploy_keys/graphql/client.js @@ -0,0 +1,47 @@ +import VueApollo from 'vue-apollo'; +import createDefaultClient from '~/lib/graphql'; +import typeDefs from './typedefs.graphql'; +import { resolvers } from './resolvers'; + +export const createApolloProvider = (endpoints) => { + const defaultClient = createDefaultClient(resolvers(endpoints), { + typeDefs, + cacheConfig: { + typePolicies: { + Query: { + fields: { + currentScope: { + read(data) { + return data || 'enabledKeys'; + }, + }, + currentPage: { + read(data) { + return data || 1; + }, + }, + pageInfo: { + read(data) { + return data || {}; + }, + }, + deployKeyToRemove: { + read(data) { + return data || null; + }, + }, + }, + }, + LocalDeployKey: { + deployKeysProjects: { + merge(_, incoming) { + return incoming; + }, + }, + }, + }, + }, + }); + + return new VueApollo({ defaultClient }); +}; diff --git a/app/assets/javascripts/deploy_keys/graphql/mutations/confirm_action.mutation.graphql b/app/assets/javascripts/deploy_keys/graphql/mutations/confirm_action.mutation.graphql new file mode 100644 index 00000000000..adc78e6d2d2 --- /dev/null +++ b/app/assets/javascripts/deploy_keys/graphql/mutations/confirm_action.mutation.graphql @@ -0,0 +1,3 @@ +mutation confirmDisable($id: ID) { + confirmDisable(id: $id) @client +} diff --git a/app/assets/javascripts/deploy_keys/graphql/mutations/disable_key.mutation.graphql b/app/assets/javascripts/deploy_keys/graphql/mutations/disable_key.mutation.graphql new file mode 100644 index 00000000000..923dd636785 --- /dev/null +++ b/app/assets/javascripts/deploy_keys/graphql/mutations/disable_key.mutation.graphql @@ -0,0 +1,3 @@ +mutation disableKey($id: ID!) { + disableKey(id: $id) @client +} diff --git a/app/assets/javascripts/deploy_keys/graphql/mutations/enable_key.mutation.graphql b/app/assets/javascripts/deploy_keys/graphql/mutations/enable_key.mutation.graphql new file mode 100644 index 00000000000..fb978679b7c --- /dev/null +++ b/app/assets/javascripts/deploy_keys/graphql/mutations/enable_key.mutation.graphql @@ -0,0 +1,3 @@ +mutation enableKey($id: ID!) { + enableKey(id: $id) @client +} diff --git a/app/assets/javascripts/deploy_keys/graphql/mutations/update_current_page.mutation.graphql b/app/assets/javascripts/deploy_keys/graphql/mutations/update_current_page.mutation.graphql new file mode 100644 index 00000000000..8e6438cdad0 --- /dev/null +++ b/app/assets/javascripts/deploy_keys/graphql/mutations/update_current_page.mutation.graphql @@ -0,0 +1,3 @@ +mutation updateCurrentDeployKeyPage($page: String) { + currentPage(page: $page) @client +} diff --git a/app/assets/javascripts/deploy_keys/graphql/mutations/update_current_scope.mutation.graphql b/app/assets/javascripts/deploy_keys/graphql/mutations/update_current_scope.mutation.graphql new file mode 100644 index 00000000000..3502eee5142 --- /dev/null +++ b/app/assets/javascripts/deploy_keys/graphql/mutations/update_current_scope.mutation.graphql @@ -0,0 +1,3 @@ +mutation updateCurrentScope($scope: DeployKeysScope) { + currentScope(scope: $scope) @client +} diff --git a/app/assets/javascripts/deploy_keys/graphql/queries/confirm_remove_key.query.graphql b/app/assets/javascripts/deploy_keys/graphql/queries/confirm_remove_key.query.graphql new file mode 100644 index 00000000000..11d6a6ab83c --- /dev/null +++ b/app/assets/javascripts/deploy_keys/graphql/queries/confirm_remove_key.query.graphql @@ -0,0 +1,5 @@ +query confirmRemoveKey { + deployKeyToRemove @client { + id + } +} diff --git a/app/assets/javascripts/deploy_keys/graphql/queries/current_page.query.graphql b/app/assets/javascripts/deploy_keys/graphql/queries/current_page.query.graphql new file mode 100644 index 00000000000..dc02d97531a --- /dev/null +++ b/app/assets/javascripts/deploy_keys/graphql/queries/current_page.query.graphql @@ -0,0 +1,3 @@ +query getCurrentDeployKeyPage { + currentPage @client +} diff --git a/app/assets/javascripts/deploy_keys/graphql/queries/current_scope.query.graphql b/app/assets/javascripts/deploy_keys/graphql/queries/current_scope.query.graphql new file mode 100644 index 00000000000..181f5c52254 --- /dev/null +++ b/app/assets/javascripts/deploy_keys/graphql/queries/current_scope.query.graphql @@ -0,0 +1,3 @@ +query getCurrentScope { + currentScope @client +} diff --git a/app/assets/javascripts/deploy_keys/graphql/queries/deploy_keys.query.graphql b/app/assets/javascripts/deploy_keys/graphql/queries/deploy_keys.query.graphql new file mode 100644 index 00000000000..c98da2920cc --- /dev/null +++ b/app/assets/javascripts/deploy_keys/graphql/queries/deploy_keys.query.graphql @@ -0,0 +1,26 @@ +query getDeployKeys($projectPath: ID!, $scope: DeployKeysScope, $page: Integer) { + project(fullPath: $projectPath) { + id + deployKeys(scope: $scope, page: $page) @client { + id + title + fingerprintSha256 + fingerprint + editPath + destroyedWhenOrphaned + almostOrphaned + expiresAt + createdAt + enablePath + disablePath + deployKeysProjects { + canPush + project { + id + fullPath + fullName + } + } + } + } +} diff --git a/app/assets/javascripts/deploy_keys/graphql/resolvers.js b/app/assets/javascripts/deploy_keys/graphql/resolvers.js new file mode 100644 index 00000000000..1993801636e --- /dev/null +++ b/app/assets/javascripts/deploy_keys/graphql/resolvers.js @@ -0,0 +1,106 @@ +import { gql } from '@apollo/client/core'; +import axios from '~/lib/utils/axios_utils'; +import { + convertObjectPropsToCamelCase, + parseIntPagination, + normalizeHeaders, +} from '~/lib/utils/common_utils'; +import pageInfoQuery from '~/graphql_shared/client/page_info.query.graphql'; +import currentPageQuery from './queries/current_page.query.graphql'; +import currentScopeQuery from './queries/current_scope.query.graphql'; +import confirmRemoveKeyQuery from './queries/confirm_remove_key.query.graphql'; + +export const mapDeployKey = (deployKey) => ({ + ...convertObjectPropsToCamelCase(deployKey, { deep: true }), + __typename: 'LocalDeployKey', +}); + +export const resolvers = (endpoints) => ({ + Project: { + deployKeys(_, { scope, page }, { client }) { + const key = `${scope}Endpoint`; + let { [key]: endpoint } = endpoints; + + if (!endpoint) { + endpoint = endpoints.enabledKeysEndpoint; + } + + return axios.get(endpoint, { params: { page } }).then(({ headers, data }) => { + const normalizedHeaders = normalizeHeaders(headers); + const pageInfo = { + ...parseIntPagination(normalizedHeaders), + __typename: 'LocalPageInfo', + }; + client.writeQuery({ + query: pageInfoQuery, + variables: { input: { page, scope } }, + data: { pageInfo }, + }); + return data?.keys?.map(mapDeployKey) || []; + }); + }, + }, + Mutation: { + currentPage(_, { page }, { client }) { + client.writeQuery({ + query: currentPageQuery, + data: { currentPage: page }, + }); + }, + currentScope(_, { scope }, { client }) { + client.writeQuery({ + query: currentPageQuery, + data: { currentPage: 1 }, + }); + client.writeQuery({ + query: currentScopeQuery, + data: { currentScope: scope }, + }); + }, + disableKey(_, _variables, { client }) { + const { + deployKeyToRemove: { id }, + } = client.readQuery({ + query: confirmRemoveKeyQuery, + }); + + const fragment = gql` + fragment DisablePath on LocalDeployKey { + disablePath + } + `; + + const { disablePath } = client.readFragment({ fragment, id: `LocalDeployKey:${id}` }); + + return axios.put(disablePath).then(({ data }) => { + client.cache.evict({ fieldName: 'deployKeyToRemove' }); + client.cache.evict({ id: `LocalDeployKey:${id}` }); + client.cache.gc(); + + return data; + }); + }, + enableKey(_, { id }, { client }) { + const fragment = gql` + fragment EnablePath on LocalDeployKey { + enablePath + } + `; + + const { enablePath } = client.readFragment({ fragment, id: `LocalDeployKey:${id}` }); + + return axios.put(enablePath).then(({ data }) => { + client.cache.evict({ id: `LocalDeployKey:${id}` }); + client.cache.gc(); + + return data; + }); + }, + confirmDisable(_, { id }, { client }) { + client.writeQuery({ + query: confirmRemoveKeyQuery, + data: { deployKeyToRemove: id ? { id, __type: 'LocalDeployKey' } : null }, + }); + }, + }, +}); diff --git a/app/assets/javascripts/deploy_keys/graphql/typedefs.graphql b/app/assets/javascripts/deploy_keys/graphql/typedefs.graphql new file mode 100644 index 00000000000..a08dda3da92 --- /dev/null +++ b/app/assets/javascripts/deploy_keys/graphql/typedefs.graphql @@ -0,0 +1,45 @@ +#import "~/graphql_shared/client/page_info.typedefs.graphql" + +enum DeployKeysScope { + enabledKeys + availableProjectKeys + availablePublicKeys +} + +enum LocalDeployKeyActions { + enable + disable +} + +type LocalProject { + id: ID! + fullPath: String + fullName: String +} + +type LocalDeployKeysProject { + canPush: Boolean + projects: [LocalProject] +} + +type LocalDeployKey { + id: ID! + title: String + fingerprintSha256: String + fingerprint: String + editPath: String + isEnabled: Boolean + destroyedWhenOrphaned: Boolean + almostOrphaned: Boolean + expiresAt: String + createdAt: String + deployKeysProjects: [LocalDeployKeysProject] +} + +extend type LocalPageInfoInput { + scope: DeployKeysScope +} + +extend type Project { + deployKeys: [LocalDeployKey] +} -- cgit v1.2.3