summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/graphql_shared
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-08-02 12:09:59 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-08-02 12:09:59 +0000
commit3eec6c2511af2b10cd25be64dcd84c4a35a7bcdb (patch)
tree8af0733be4f7cb507353ed97ca8d6b4e9e374b7f /app/assets/javascripts/graphql_shared
parent1930898566965dbc1bd779089ec9e58e17674268 (diff)
downloadgitlab-ce-3eec6c2511af2b10cd25be64dcd84c4a35a7bcdb.tar.gz
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.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/app/assets/javascripts/graphql_shared/utils.js b/app/assets/javascripts/graphql_shared/utils.js
index 18f9a50bbce..828ddd95ffc 100644
--- a/app/assets/javascripts/graphql_shared/utils.js
+++ b/app/assets/javascripts/graphql_shared/utils.js
@@ -2,6 +2,21 @@ import { isArray } from 'lodash';
/**
* Ids generated by GraphQL endpoints are usually in the format
+ * gid://gitlab/Environments/123. This method checks if the passed id follows that format
+ *
+ * @param {String|Number} id The id value
+ * @returns {Boolean}
+ */
+export const isGid = (id) => {
+ if (typeof id === 'string' && id.startsWith('gid://gitlab/')) {
+ return true;
+ }
+
+ return false;
+};
+
+/**
+ * Ids generated by GraphQL endpoints are usually in the format
* gid://gitlab/Environments/123. This method extracts Id number
* from the Id path
*
@@ -35,6 +50,10 @@ export const convertToGraphQLId = (type, id) => {
throw new TypeError(`id must be a number or string; got ${typeof id}`);
}
+ if (isGid(id)) {
+ return id;
+ }
+
return `gid://gitlab/${type}/${id}`;
};