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
EE_ELSE_CE =
/^ee_else_ce/
HOME_RE =
/^~/
HOME_EE =
%r{^ee/}
DOTS_RE =
%r{^(\.\./)+}
DOT_RE =
%r{^\./}
IMPLICIT_ROOT =
%r{^app/}
CONN_DIRECTIVE =
/@connection\(key: "\w+"\)/

Class Method Summary collapse

Class Method Details

.allObject



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

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



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

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



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

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

.known_failure?(path) ⇒ Boolean

Returns:

  • (Boolean)


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

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)


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

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