Module: Gitlab::Graphql::Queries

Defined in:
lib/gitlab/graphql/queries.rb

Defined Under Namespace

Classes: ClientFieldRedactor, Definition, FileNotFound, Fragments, WrappedError

Constant Summary collapse

IMPORT_RE =
/^#\s*import "(?<path>[^"]+)"$/m.freeze
EE_ELSE_CE =
/^ee_else_ce/.freeze
HOME_RE =
/^~/.freeze
HOME_EE =
%r{^ee/}.freeze
DOTS_RE =
%r{^(\.\./)+}.freeze
DOT_RE =
%r{^\./}.freeze
IMPLICIT_ROOT =
%r{^app/}.freeze
CONN_DIRECTIVE =
/@connection\(key: "\w+"\)/.freeze

Class Method Summary collapse

Class Method Details

.allObject


282
283
284
285
286
# File 'lib/gitlab/graphql/queries.rb', line 282

def self.all
  ['.', 'ee'].flat_map do |prefix|
    find(Rails.root / prefix / 'app/assets/javascripts') + find(Rails.root / prefix / 'app/graphql/queries')
  end
end

.find(root) ⇒ Object


266
267
268
269
270
271
272
273
274
275
276
# File 'lib/gitlab/graphql/queries.rb', line 266

def self.find(root)
  definitions = []

  ::Find.find(root.to_s) do |path|
    definitions << Definition.new(path, fragments) if query_for_gitlab_schema?(path)
  end

  definitions
rescue Errno::ENOENT
  [] # root does not exist
end

.fragmentsObject


278
279
280
# File 'lib/gitlab/graphql/queries.rb', line 278

def self.fragments
  @fragments ||= Fragments.new(Rails.root)
end

.known_failure?(path) ⇒ Boolean

Returns:

  • (Boolean)

288
289
290
291
292
# File 'lib/gitlab/graphql/queries.rb', line 288

def self.known_failure?(path)
  @known_failures ||= YAML.safe_load(File.read(Rails.root.join('config', 'known_invalid_graphql_queries.yml')))

  @known_failures.fetch('filenames', []).any? { |known_failure| path.to_s.ends_with?(known_failure) }
end

.query_for_gitlab_schema?(path) ⇒ Boolean

Returns:

  • (Boolean)

294
295
296
297
298
299
# File 'lib/gitlab/graphql/queries.rb', line 294

def self.query_for_gitlab_schema?(path)
  path.ends_with?('.graphql') &&
    !path.ends_with?('.fragment.graphql') &&
    !path.ends_with?('typedefs.graphql') &&
    !/.*\.customer\.(query|mutation)\.graphql$/.match?(path)
end