Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-12-19 14:01:45 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-12-19 14:01:45 +0300
commit9297025d0b7ddf095eb618dfaaab2ff8f2018d8b (patch)
tree865198c01d1824a9b098127baa3ab980c9cd2c06 /app/assets/javascripts/deploy_keys/graphql
parent6372471f43ee03c05a7c1f8b0c6ac6b8a7431dbe (diff)
Add latest changes from gitlab-org/gitlab@16-7-stable-eev16.7.0-rc42
Diffstat (limited to 'app/assets/javascripts/deploy_keys/graphql')
-rw-r--r--app/assets/javascripts/deploy_keys/graphql/client.js47
-rw-r--r--app/assets/javascripts/deploy_keys/graphql/mutations/confirm_action.mutation.graphql3
-rw-r--r--app/assets/javascripts/deploy_keys/graphql/mutations/disable_key.mutation.graphql3
-rw-r--r--app/assets/javascripts/deploy_keys/graphql/mutations/enable_key.mutation.graphql3
-rw-r--r--app/assets/javascripts/deploy_keys/graphql/mutations/update_current_page.mutation.graphql3
-rw-r--r--app/assets/javascripts/deploy_keys/graphql/mutations/update_current_scope.mutation.graphql3
-rw-r--r--app/assets/javascripts/deploy_keys/graphql/queries/confirm_remove_key.query.graphql5
-rw-r--r--app/assets/javascripts/deploy_keys/graphql/queries/current_page.query.graphql3
-rw-r--r--app/assets/javascripts/deploy_keys/graphql/queries/current_scope.query.graphql3
-rw-r--r--app/assets/javascripts/deploy_keys/graphql/queries/deploy_keys.query.graphql26
-rw-r--r--app/assets/javascripts/deploy_keys/graphql/resolvers.js106
-rw-r--r--app/assets/javascripts/deploy_keys/graphql/typedefs.graphql45
12 files changed, 250 insertions, 0 deletions
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]
+}