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
0c185707
Commit
0c185707
authored
Feb 05, 2021
by
Alex Kalderimis
Committed by
Bob Van Landuyt
Feb 05, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add gitlab:graphql:analyze task
parent
06655b7f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
1 deletion
+43
-1
lib/gitlab/graphql/queries.rb
lib/gitlab/graphql/queries.rb
+14
-0
lib/tasks/gitlab/graphql.rake
lib/tasks/gitlab/graphql.rake
+25
-1
spec/lib/gitlab/graphql/queries_spec.rb
spec/lib/gitlab/graphql/queries_spec.rb
+4
-0
No files found.
lib/gitlab/graphql/queries.rb
View file @
0c185707
...
@@ -145,6 +145,20 @@ module Gitlab
...
@@ -145,6 +145,20 @@ module Gitlab
return
redacted
if
printer
.
fields_printed
>
0
return
redacted
if
printer
.
fields_printed
>
0
end
end
def
complexity
(
schema
)
# See BaseResolver::resolver_complexity
# we want to see the max possible complexity.
fake_args
=
Struct
.
new
(
:if
,
:keyword_arguments
)
.
new
(
nil
,
{
sort:
true
,
search:
true
})
query
=
GraphQL
::
Query
.
new
(
schema
,
text
)
# We have no arguments, so fake them.
query
.
define_singleton_method
(
:arguments_for
)
{
|
_x
,
_y
|
fake_args
}
GraphQL
::
Analysis
::
AST
.
analyze_query
(
query
,
[
GraphQL
::
Analysis
::
AST
::
QueryComplexity
]).
first
end
def
query
def
query
return
@query
if
defined?
(
@query
)
return
@query
if
defined?
(
@query
)
...
...
lib/tasks/gitlab/graphql.rake
View file @
0c185707
...
@@ -33,7 +33,31 @@ namespace :gitlab do
...
@@ -33,7 +33,31 @@ namespace :gitlab do
)
)
namespace
:graphql
do
namespace
:graphql
do
desc
'Gitlab | GraphQL | Validate queries'
desc
'GitLab | GraphQL | Analyze queries'
task
analyze:
[
:environment
,
:enable_feature_flags
]
do
|
t
,
args
|
queries
=
if
args
.
to_a
.
present?
args
.
to_a
.
flat_map
{
|
path
|
Gitlab
::
Graphql
::
Queries
.
find
(
path
)
}
else
Gitlab
::
Graphql
::
Queries
.
all
end
queries
.
each
do
|
defn
|
$stdout
.
puts
defn
.
file
summary
,
errs
=
defn
.
validate
(
GitlabSchema
)
if
summary
==
:client_query
$stdout
.
puts
" - client query"
elsif
errs
.
present?
$stdout
.
puts
" - invalid query"
else
$stdout
.
puts
" - complexity:
#{
defn
.
complexity
(
GitlabSchema
)
}
"
end
$stdout
.
puts
""
end
end
desc
'GitLab | GraphQL | Validate queries'
task
validate:
[
:environment
,
:enable_feature_flags
]
do
|
t
,
args
|
task
validate:
[
:environment
,
:enable_feature_flags
]
do
|
t
,
args
|
queries
=
if
args
.
to_a
.
present?
queries
=
if
args
.
to_a
.
present?
args
.
to_a
.
flat_map
{
|
path
|
Gitlab
::
Graphql
::
Queries
.
find
(
path
)
}
args
.
to_a
.
flat_map
{
|
path
|
Gitlab
::
Graphql
::
Queries
.
find
(
path
)
}
...
...
spec/lib/gitlab/graphql/queries_spec.rb
View file @
0c185707
...
@@ -151,6 +151,10 @@ RSpec.describe Gitlab::Graphql::Queries do
...
@@ -151,6 +151,10 @@ RSpec.describe Gitlab::Graphql::Queries do
let
(
:path
)
{
'post_by_slug.graphql'
}
let
(
:path
)
{
'post_by_slug.graphql'
}
it_behaves_like
'a valid GraphQL query for the blog schema'
it_behaves_like
'a valid GraphQL query for the blog schema'
it
'has a complexity'
do
expect
(
subject
.
complexity
(
schema
)).
to
be
<
10
end
end
end
context
'a query with an import'
do
context
'a query with an import'
do
...
...
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