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
f94230ef
Commit
f94230ef
authored
Jan 05, 2021
by
Alex Kalderimis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Hide private methods, and avoid boolean blindness
parent
f3c1ef8b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
20 deletions
+22
-20
lib/gitlab/graphql/queries.rb
lib/gitlab/graphql/queries.rb
+20
-18
spec/lib/gitlab/graphql/queries_spec.rb
spec/lib/gitlab/graphql/queries_spec.rb
+2
-2
No files found.
lib/gitlab/graphql/queries.rb
View file @
f94230ef
...
...
@@ -52,8 +52,8 @@ module Gitlab
@ee_else_ce
=
[]
end
def
text
(
ee
=
fals
e
)
qs
=
[
query
]
+
all_imports
(
e
e
).
uniq
.
sort
.
map
{
|
p
|
fragment
(
p
).
query
}
def
text
(
mode: :c
e
)
qs
=
[
query
]
+
all_imports
(
mode:
mod
e
).
uniq
.
sort
.
map
{
|
p
|
fragment
(
p
).
query
}
qs
.
join
(
"
\n\n
"
).
gsub
(
/\n\n+/
,
"
\n\n
"
)
end
...
...
@@ -77,13 +77,13 @@ module Gitlab
@query
=
nil
end
def
all_imports
(
ee
=
fals
e
)
def
all_imports
(
mode: :c
e
)
return
[]
if
query
.
nil?
home
=
ee
?
@fragments
.
home_ee
:
@fragments
.
home
home
=
mode
==
:
ee
?
@fragments
.
home_ee
:
@fragments
.
home
eithers
=
@ee_else_ce
.
map
{
|
p
|
home
+
p
}
(
imports
+
eithers
).
flat_map
{
|
p
|
[
p
]
+
@fragments
.
get
(
p
).
all_imports
(
e
e
)
}
(
imports
+
eithers
).
flat_map
{
|
p
|
[
p
]
+
@fragments
.
get
(
p
).
all_imports
(
mode:
mod
e
)
}
end
def
all_errors
...
...
@@ -94,6 +94,21 @@ module Gitlab
paths
.
map
{
|
p
|
fragment
(
p
).
all_errors
}.
reduce
(
@errors
.
to_set
)
{
|
a
,
b
|
a
|
b
}
end
def
validate
(
schema
)
return
[
:client_query
,
[]]
if
CLIENT_DIRECTIVE
.
match?
(
text
)
errs
=
all_errors
.
presence
||
schema
.
validate
(
text
)
if
@ee_else_ce
.
present?
errs
+=
schema
.
validate
(
text
(
mode: :ee
))
end
[
:validated
,
errs
]
rescue
::
GraphQL
::
ParseError
=>
e
[
:validated
,
[
WrappedError
.
new
(
e
)]]
end
private
def
fragment
(
path
)
@fragments
.
get
(
path
)
end
...
...
@@ -123,19 +138,6 @@ module Gitlab
path
.
to_s
+
'/'
end
def
validate
(
schema
)
return
[
:client_query
,
[]]
if
CLIENT_DIRECTIVE
.
match?
(
text
)
errs
=
all_errors
.
presence
||
schema
.
validate
(
text
)
if
@ee_else_ce
.
present?
errs
+=
schema
.
validate
(
text
(
true
))
end
[
:validated
,
errs
]
rescue
::
GraphQL
::
ParseError
=>
e
[
:validated
,
[
WrappedError
.
new
(
e
)]]
end
end
class
Fragments
...
...
spec/lib/gitlab/graphql/queries_spec.rb
View file @
f94230ef
...
...
@@ -171,8 +171,8 @@ RSpec.describe Gitlab::Graphql::Queries do
it_behaves_like
'a valid GraphQL query for the blog schema'
it
'can resolve the ee fields'
do
expect
(
subject
.
text
(
fals
e
)).
not_to
include
(
'verified'
)
expect
(
subject
.
text
(
tru
e
)).
to
include
(
'verified'
)
expect
(
subject
.
text
(
mode: :c
e
)).
not_to
include
(
'verified'
)
expect
(
subject
.
text
(
mode: :e
e
)).
to
include
(
'verified'
)
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