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>2020-11-27 18:09:34 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-11-27 18:09:34 +0300
commit4c39dd11dcbdab4fdd9424a62320a1fc773c2918 (patch)
treeb3bc6139fdc8d1e3254304222f06f82821c5aa64 /app/assets/javascripts/graphql_shared
parent95ff19a65c5236863e4c7c7e198bfc1e2fa70f07 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/graphql_shared')
-rw-r--r--app/assets/javascripts/graphql_shared/utils.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/app/assets/javascripts/graphql_shared/utils.js b/app/assets/javascripts/graphql_shared/utils.js
index 5487aeb9391..813e21b6ce9 100644
--- a/app/assets/javascripts/graphql_shared/utils.js
+++ b/app/assets/javascripts/graphql_shared/utils.js
@@ -14,3 +14,41 @@ export const MutationOperationMode = {
Remove: 'REMOVE',
Replace: 'REPLACE',
};
+
+/**
+ * Possible GraphQL entity types.
+ */
+export const TYPE_GROUP = 'Group';
+
+/**
+ * Ids generated by GraphQL endpoints are usually in the format
+ * gid://gitlab/Groups/123. This method takes a type and an id
+ * and interpolates the 2 values into the expected GraphQL ID format.
+ *
+ * @param {String} type The entity type
+ * @param {String|Number} id The id value
+ * @returns {String}
+ */
+export const convertToGraphQLId = (type, id) => {
+ if (typeof type !== 'string') {
+ throw new TypeError(`type must be a string; got ${typeof type}`);
+ }
+
+ if (!['number', 'string'].includes(typeof id)) {
+ throw new TypeError(`id must be a number or string; got ${typeof id}`);
+ }
+
+ return `gid://gitlab/${type}/${id}`;
+};
+
+/**
+ * Ids generated by GraphQL endpoints are usually in the format
+ * gid://gitlab/Groups/123. This method takes a type and an
+ * array of ids and tranforms the array values into the expected
+ * GraphQL ID format.
+ *
+ * @param {String} type The entity type
+ * @param {Array} ids An array of id values
+ * @returns {Array}
+ */
+export const convertToGraphQLIds = (type, ids) => ids.map(id => convertToGraphQLId(type, id));