Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
513187669b6f
Commit
ddcfd8fe
authored
May 20, 2019
by
Brett Walker
Browse files
Use BatchModelLoader for parent in GroupType
parent
3ecae3c4ccbd
Changes
2
Hide whitespace changes
Inline
Side-by-side
app/graphql/types/group_type.rb
View file @
51318766
...
...
@@ -8,14 +8,16 @@ class GroupType < NamespaceType
expose_permissions
Types
::
PermissionTypes
::
Group
field
:web_url
,
GraphQL
::
STRING_TYPE
,
null:
tru
e
field
:web_url
,
GraphQL
::
STRING_TYPE
,
null:
fals
e
field
:avatar_url
,
GraphQL
::
STRING_TYPE
,
null:
true
,
resolve:
->
(
group
,
args
,
ctx
)
do
group
.
avatar_url
(
only_path:
false
)
end
if
::
Group
.
supports_nested_objects?
field
:parent
,
GroupType
,
null:
true
field
:parent
,
GroupType
,
null:
true
,
resolve:
->
(
obj
,
_args
,
_ctx
)
{
Gitlab
::
Graphql
::
Loaders
::
BatchModelLoader
.
new
(
Group
,
obj
.
parent_id
).
find
}
end
end
end
spec/graphql/resolvers/group_resolver_spec.rb
0 → 100644
View file @
51318766
# frozen_string_literal: true
require
'spec_helper'
describe
Resolvers
::
GroupResolver
do
include
GraphqlHelpers
set
(
:group1
)
{
create
(
:group
)
}
set
(
:group2
)
{
create
(
:group
)
}
describe
'#resolve'
do
it
'batch-resolves groups by full path'
do
paths
=
[
group1
.
full_path
,
group2
.
full_path
]
result
=
batch
(
max_queries:
1
)
do
paths
.
map
{
|
path
|
resolve_group
(
path
)
}
end
expect
(
result
).
to
contain_exactly
(
group1
,
group2
)
end
it
'resolves an unknown full_path to nil'
do
result
=
batch
{
resolve_group
(
'unknown/project'
)
}
expect
(
result
).
to
be_nil
end
end
def
resolve_group
(
full_path
)
resolve
(
described_class
,
args:
{
full_path:
full_path
})
end
end
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