Commit f94230ef authored by Alex Kalderimis's avatar Alex Kalderimis

Hide private methods, and avoid boolean blindness

parent f3c1ef8b
...@@ -52,8 +52,8 @@ module Gitlab ...@@ -52,8 +52,8 @@ module Gitlab
@ee_else_ce = [] @ee_else_ce = []
end end
def text(ee = false) def text(mode: :ce)
qs = [query] + all_imports(ee).uniq.sort.map { |p| fragment(p).query } qs = [query] + all_imports(mode: mode).uniq.sort.map { |p| fragment(p).query }
qs.join("\n\n").gsub(/\n\n+/, "\n\n") qs.join("\n\n").gsub(/\n\n+/, "\n\n")
end end
...@@ -77,13 +77,13 @@ module Gitlab ...@@ -77,13 +77,13 @@ module Gitlab
@query = nil @query = nil
end end
def all_imports(ee = false) def all_imports(mode: :ce)
return [] if query.nil? 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 } eithers = @ee_else_ce.map { |p| home + p }
(imports + eithers).flat_map { |p| [p] + @fragments.get(p).all_imports(ee) } (imports + eithers).flat_map { |p| [p] + @fragments.get(p).all_imports(mode: mode) }
end end
def all_errors def all_errors
...@@ -94,6 +94,21 @@ module Gitlab ...@@ -94,6 +94,21 @@ module Gitlab
paths.map { |p| fragment(p).all_errors }.reduce(@errors.to_set) { |a, b| a | b } paths.map { |p| fragment(p).all_errors }.reduce(@errors.to_set) { |a, b| a | b }
end 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) def fragment(path)
@fragments.get(path) @fragments.get(path)
end end
...@@ -123,19 +138,6 @@ module Gitlab ...@@ -123,19 +138,6 @@ module Gitlab
path.to_s + '/' path.to_s + '/'
end 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 end
class Fragments class Fragments
......
...@@ -171,8 +171,8 @@ RSpec.describe Gitlab::Graphql::Queries do ...@@ -171,8 +171,8 @@ RSpec.describe Gitlab::Graphql::Queries do
it_behaves_like 'a valid GraphQL query for the blog schema' it_behaves_like 'a valid GraphQL query for the blog schema'
it 'can resolve the ee fields' do it 'can resolve the ee fields' do
expect(subject.text(false)).not_to include('verified') expect(subject.text(mode: :ce)).not_to include('verified')
expect(subject.text(true)).to include('verified') expect(subject.text(mode: :ee)).to include('verified')
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment