diff options
Diffstat (limited to 'app/assets/javascripts/graphql_shared/utils.js')
-rw-r--r-- | app/assets/javascripts/graphql_shared/utils.js | 19 |
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}`; }; |