summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/graphql_shared/utils.js
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-05-05 18:17:47 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2023-05-05 18:17:47 +0000
commitbc4cd6ffb93ae695f20ea54f4e4803d50c78a69e (patch)
tree2364d0f880af998b70356628f79cda64f13a11e7 /app/assets/javascripts/graphql_shared/utils.js
parent6634288474d2a83cac7b4205f3ffc736cc6b36db (diff)
downloadgitlab-ce-bc4cd6ffb93ae695f20ea54f4e4803d50c78a69e.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/graphql_shared/utils.js')
-rw-r--r--app/assets/javascripts/graphql_shared/utils.js25
1 files changed, 22 insertions, 3 deletions
diff --git a/app/assets/javascripts/graphql_shared/utils.js b/app/assets/javascripts/graphql_shared/utils.js
index 198d9f980f0..6a64e8a2fa8 100644
--- a/app/assets/javascripts/graphql_shared/utils.js
+++ b/app/assets/javascripts/graphql_shared/utils.js
@@ -16,7 +16,10 @@ export const isGid = (id) => {
return false;
};
-const parseGid = (gid) => parseInt(`${gid}`.replace(/gid:\/\/gitlab\/.*\//g, ''), 10);
+const parseGid = (gid) => {
+ const [type, id] = `${gid}`.replace(/gid:\/\/gitlab\//g, '').split('/');
+ return { type, id };
+};
/**
* Ids generated by GraphQL endpoints are usually in the format
@@ -27,8 +30,24 @@ const parseGid = (gid) => parseInt(`${gid}`.replace(/gid:\/\/gitlab\/.*\//g, '')
* @returns {Number}
*/
export const getIdFromGraphQLId = (gid = '') => {
- const parsedGid = parseGid(gid);
- return Number.isInteger(parsedGid) ? parsedGid : null;
+ const rawId = isGid(gid) ? parseGid(gid).id : gid;
+ const id = parseInt(rawId, 10);
+ return Number.isInteger(id) ? id : null;
+};
+
+/**
+ * Ids generated by GraphQL endpoints are usually in the format
+ * gid://gitlab/Environments/123. This method extracts Type string
+ * from the Id path
+ *
+ * @param {String} gid GraphQL global ID
+ * @returns {String}
+ */
+export const getTypeFromGraphQLId = (gid = '') => {
+ if (!isGid(gid)) return null;
+
+ const { type } = parseGid(gid);
+ return type || null;
};
export const MutationOperationMode = {