Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
dbc5c4e8
Commit
dbc5c4e8
authored
Dec 03, 2019
by
Alex Kalderimis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds ability to assert expected superclass in object_from_id
With suggestions from @rpereira2
parent
82226d53
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
1 deletion
+8
-1
app/graphql/gitlab_schema.rb
app/graphql/gitlab_schema.rb
+8
-1
No files found.
app/graphql/gitlab_schema.rb
View file @
dbc5c4e8
...
...
@@ -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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment