Class: PlatformosCheck::GraphqlFile
- Inherits:
-
AppFile
- Object
- AppFile
- PlatformosCheck::GraphqlFile
show all
- Defined in:
- lib/platformos_check/graphql_file.rb
Constant Summary
collapse
- DIR_PREFIX =
%r{\A/?((marketplace_builder|app)/(graph_queries|graphql)s?/|modules/((\w|-)*)/(private|public)/(graph_queries|graphql)s?/)}
Instance Attribute Summary
Attributes inherited from AppFile
#storage, #version
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from AppFile
#==, #build_name, #initialize, #liquid?, #module_name, #name, #path, #relative_path, #remove_extension, #source, #yaml?
Class Method Details
.parse(_source) ⇒ Object
64
65
66
|
# File 'lib/platformos_check/graphql_file.rb', line 64
def self.parse(_source)
Struct.new(:warnings, :root)
end
|
Instance Method Details
#defined_arguments ⇒ Object
74
75
76
|
# File 'lib/platformos_check/graphql_file.rb', line 74
def defined_arguments
@defined_arguments ||= variables.map(&:name)
end
|
#dir_prefix ⇒ Object
28
29
30
|
# File 'lib/platformos_check/graphql_file.rb', line 28
def dir_prefix
DIR_PREFIX
end
|
#parse ⇒ Object
52
53
54
|
# File 'lib/platformos_check/graphql_file.rb', line 52
def parse
@parse ||= GraphQL.parse(source)
end
|
#required_arguments ⇒ Object
68
69
70
71
72
|
# File 'lib/platformos_check/graphql_file.rb', line 68
def required_arguments
@required_arguments ||= variables.each_with_object([]) do |v, vars|
vars << v.name if v.type.is_a?(GraphQL::Language::Nodes::NonNullType)
end
end
|
#rewriter ⇒ Object
24
25
26
|
# File 'lib/platformos_check/graphql_file.rb', line 24
def rewriter
@rewriter ||= AppFileRewriter.new(@relative_path, source)
end
|
#root ⇒ Object
60
61
62
|
# File 'lib/platformos_check/graphql_file.rb', line 60
def root
parse.root
end
|
#source_excerpt(line) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/platformos_check/graphql_file.rb', line 32
def source_excerpt(line)
original_lines = source.split("\n")
original_lines[bounded(0, line - 1, original_lines.size - 1)].strip
rescue StandardError => e
PlatformosCheck.bug(" Exception while running `source_excerpt(\#{line})`:\n ```\n \#{e.class}: \#{e.message}\n \#{e.backtrace.join(\"\\n \")}\n ```\n\n path: \#{path}\n\n source:\n ```\n \#{source}\n ```\n EOS\nend\n")
|
#warnings ⇒ Object
56
57
58
|
# File 'lib/platformos_check/graphql_file.rb', line 56
def warnings
parse.warnings
end
|
#write ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/platformos_check/graphql_file.rb', line 9
def write
content = rewriter.to_s
return unless source != content
@storage.write(@relative_path, content.gsub("\n", @eol))
@source = content
@rewriter = nil
@ast = nil
@variables = nil
@definition = nil
@parse = nil
@required_arguments = nil
@defined_arguments = nil
end
|