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



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

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



274
275
276
277
278
279
280
281
282
283
284
# File 'lib/gitlab/graphql/queries.rb', line 274

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



286
287
288
# File 'lib/gitlab/graphql/queries.rb', line 286

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

.known_failure?(path) ⇒ Boolean

Returns:

  • (Boolean)


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

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)


302
303
304
305
306
307
# File 'lib/gitlab/graphql/queries.rb', line 302

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