summaryrefslogtreecommitdiff
path: root/app/graphql/gitlab_schema.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/graphql/gitlab_schema.rb')
-rw-r--r--app/graphql/gitlab_schema.rb9
1 files changed, 8 insertions, 1 deletions
diff --git a/app/graphql/gitlab_schema.rb b/app/graphql/gitlab_schema.rb
index a5ddf316572..ccbb1d56030 100644
--- a/app/graphql/gitlab_schema.rb
+++ b/app/graphql/gitlab_schema.rb
@@ -57,13 +57,20 @@ class GitlabSchema < GraphQL::Schema
object.to_global_id
end
- def object_from_id(global_id, _ctx = nil)
+ def object_from_id(global_id, ctx = {})
+ expected_type = ctx[:expected_type]
gid = GlobalID.parse(global_id)
unless gid
raise Gitlab::Graphql::Errors::ArgumentError, "#{global_id} is not a valid GitLab id."
end
+ if expected_type && !gid.model_class.ancestors.include?(expected_type)
+ vars = { global_id: global_id, expected_type: expected_type }
+ msg = _('%{global_id} is not a valid id for %{expected_type}.') % vars
+ raise Gitlab::Graphql::Errors::ArgumentError, msg
+ end
+
if gid.model_class < ApplicationRecord
Gitlab::Graphql::Loaders::BatchModelLoader.new(gid.model_class, gid.model_id).find
elsif gid.model_class.respond_to?(:lazy_find)