graphql 2.3.5 → 2.3.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/graphql/analysis/analyzer.rb +89 -0
- data/lib/graphql/analysis/field_usage.rb +82 -0
- data/lib/graphql/analysis/max_query_complexity.rb +20 -0
- data/lib/graphql/analysis/max_query_depth.rb +20 -0
- data/lib/graphql/analysis/query_complexity.rb +183 -0
- data/lib/graphql/analysis/{ast/query_depth.rb → query_depth.rb} +23 -25
- data/lib/graphql/analysis/visitor.rb +283 -0
- data/lib/graphql/analysis.rb +92 -1
- data/lib/graphql/dataloader/async_dataloader.rb +2 -0
- data/lib/graphql/dataloader/source.rb +5 -2
- data/lib/graphql/execution/interpreter/runtime.rb +6 -6
- data/lib/graphql/execution/interpreter.rb +1 -1
- data/lib/graphql/execution/lookahead.rb +10 -10
- data/lib/graphql/introspection/directive_type.rb +1 -1
- data/lib/graphql/introspection/entry_points.rb +2 -2
- data/lib/graphql/introspection/field_type.rb +1 -1
- data/lib/graphql/introspection/schema_type.rb +6 -11
- data/lib/graphql/introspection/type_type.rb +5 -5
- data/lib/graphql/language/document_from_schema_definition.rb +19 -26
- data/lib/graphql/language/lexer.rb +0 -3
- data/lib/graphql/language/parser.rb +9 -1
- data/lib/graphql/language/sanitized_printer.rb +1 -1
- data/lib/graphql/language.rb +0 -1
- data/lib/graphql/query/context.rb +4 -0
- data/lib/graphql/query/null_context.rb +4 -0
- data/lib/graphql/query/validation_pipeline.rb +2 -2
- data/lib/graphql/query.rb +26 -3
- data/lib/graphql/schema/always_visible.rb +1 -0
- data/lib/graphql/schema/argument.rb +19 -5
- data/lib/graphql/schema/directive.rb +2 -0
- data/lib/graphql/schema/enum.rb +9 -5
- data/lib/graphql/schema/field.rb +13 -1
- data/lib/graphql/schema/has_single_input_argument.rb +2 -1
- data/lib/graphql/schema/input_object.rb +8 -7
- data/lib/graphql/schema/introspection_system.rb +2 -14
- data/lib/graphql/schema/member/has_arguments.rb +7 -6
- data/lib/graphql/schema/member/has_fields.rb +6 -4
- data/lib/graphql/schema/member/has_unresolved_type_error.rb +5 -1
- data/lib/graphql/schema/resolver.rb +5 -5
- data/lib/graphql/schema/subset.rb +397 -0
- data/lib/graphql/schema/type_expression.rb +2 -2
- data/lib/graphql/schema/validator/all_validator.rb +60 -0
- data/lib/graphql/schema/validator.rb +2 -0
- data/lib/graphql/schema/warden.rb +88 -1
- data/lib/graphql/schema.rb +44 -15
- data/lib/graphql/static_validation/base_visitor.rb +6 -5
- data/lib/graphql/static_validation/literal_validator.rb +4 -4
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +1 -1
- data/lib/graphql/static_validation/rules/arguments_are_defined.rb +1 -1
- data/lib/graphql/static_validation/rules/directives_are_defined.rb +1 -2
- data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +1 -1
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +7 -7
- data/lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb +3 -3
- data/lib/graphql/static_validation/rules/fragment_types_exist.rb +1 -1
- data/lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb +1 -1
- data/lib/graphql/static_validation/rules/mutation_root_exists.rb +1 -1
- data/lib/graphql/static_validation/rules/query_root_exists.rb +1 -1
- data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +3 -3
- data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present.rb +3 -3
- data/lib/graphql/static_validation/rules/subscription_root_exists.rb +1 -1
- data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +18 -27
- data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +1 -1
- data/lib/graphql/static_validation/rules/variables_are_input_types.rb +1 -1
- data/lib/graphql/static_validation/validation_context.rb +2 -2
- data/lib/graphql/subscriptions/broadcast_analyzer.rb +11 -5
- data/lib/graphql/subscriptions/event.rb +1 -1
- data/lib/graphql/subscriptions.rb +3 -3
- data/lib/graphql/testing/helpers.rb +2 -2
- data/lib/graphql/types/relay/connection_behaviors.rb +10 -0
- data/lib/graphql/types/relay/edge_behaviors.rb +10 -0
- data/lib/graphql/types/relay/page_info_behaviors.rb +4 -0
- data/lib/graphql/version.rb +1 -1
- metadata +12 -13
- data/lib/graphql/analysis/ast/analyzer.rb +0 -91
- data/lib/graphql/analysis/ast/field_usage.rb +0 -84
- data/lib/graphql/analysis/ast/max_query_complexity.rb +0 -22
- data/lib/graphql/analysis/ast/max_query_depth.rb +0 -22
- data/lib/graphql/analysis/ast/query_complexity.rb +0 -185
- data/lib/graphql/analysis/ast/visitor.rb +0 -284
- data/lib/graphql/analysis/ast.rb +0 -94
- data/lib/graphql/language/token.rb +0 -34
- data/lib/graphql/schema/invalid_type_error.rb +0 -7
data/lib/graphql/analysis/ast.rb
DELETED
@@ -1,94 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require "graphql/analysis/ast/visitor"
|
3
|
-
require "graphql/analysis/ast/analyzer"
|
4
|
-
require "graphql/analysis/ast/field_usage"
|
5
|
-
require "graphql/analysis/ast/query_complexity"
|
6
|
-
require "graphql/analysis/ast/max_query_complexity"
|
7
|
-
require "graphql/analysis/ast/query_depth"
|
8
|
-
require "graphql/analysis/ast/max_query_depth"
|
9
|
-
require "timeout"
|
10
|
-
|
11
|
-
module GraphQL
|
12
|
-
module Analysis
|
13
|
-
module AST
|
14
|
-
module_function
|
15
|
-
# Analyze a multiplex, and all queries within.
|
16
|
-
# Multiplex analyzers are ran for all queries, keeping state.
|
17
|
-
# Query analyzers are ran per query, without carrying state between queries.
|
18
|
-
#
|
19
|
-
# @param multiplex [GraphQL::Execution::Multiplex]
|
20
|
-
# @param analyzers [Array<GraphQL::Analysis::AST::Analyzer>]
|
21
|
-
# @return [Array<Any>] Results from multiplex analyzers
|
22
|
-
def analyze_multiplex(multiplex, analyzers)
|
23
|
-
multiplex_analyzers = analyzers.map { |analyzer| analyzer.new(multiplex) }
|
24
|
-
|
25
|
-
multiplex.current_trace.analyze_multiplex(multiplex: multiplex) do
|
26
|
-
query_results = multiplex.queries.map do |query|
|
27
|
-
if query.valid?
|
28
|
-
analyze_query(
|
29
|
-
query,
|
30
|
-
query.analyzers,
|
31
|
-
multiplex_analyzers: multiplex_analyzers
|
32
|
-
)
|
33
|
-
else
|
34
|
-
[]
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
multiplex_results = multiplex_analyzers.map(&:result)
|
39
|
-
multiplex_errors = analysis_errors(multiplex_results)
|
40
|
-
|
41
|
-
multiplex.queries.each_with_index do |query, idx|
|
42
|
-
query.analysis_errors = multiplex_errors + analysis_errors(query_results[idx])
|
43
|
-
end
|
44
|
-
multiplex_results
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
# @param query [GraphQL::Query]
|
49
|
-
# @param analyzers [Array<GraphQL::Analysis::AST::Analyzer>]
|
50
|
-
# @return [Array<Any>] Results from those analyzers
|
51
|
-
def analyze_query(query, analyzers, multiplex_analyzers: [])
|
52
|
-
query.current_trace.analyze_query(query: query) do
|
53
|
-
query_analyzers = analyzers
|
54
|
-
.map { |analyzer| analyzer.new(query) }
|
55
|
-
.tap { _1.select!(&:analyze?) }
|
56
|
-
|
57
|
-
analyzers_to_run = query_analyzers + multiplex_analyzers
|
58
|
-
if analyzers_to_run.any?
|
59
|
-
|
60
|
-
analyzers_to_run.select!(&:visit?)
|
61
|
-
if analyzers_to_run.any?
|
62
|
-
visitor = GraphQL::Analysis::AST::Visitor.new(
|
63
|
-
query: query,
|
64
|
-
analyzers: analyzers_to_run
|
65
|
-
)
|
66
|
-
|
67
|
-
# `nil` or `0` causes no timeout
|
68
|
-
Timeout::timeout(query.validate_timeout_remaining) do
|
69
|
-
visitor.visit
|
70
|
-
end
|
71
|
-
|
72
|
-
if visitor.rescued_errors.any?
|
73
|
-
return visitor.rescued_errors
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
query_analyzers.map(&:result)
|
78
|
-
else
|
79
|
-
[]
|
80
|
-
end
|
81
|
-
end
|
82
|
-
rescue Timeout::Error
|
83
|
-
[GraphQL::AnalysisError.new("Timeout on validation of query")]
|
84
|
-
rescue GraphQL::UnauthorizedError
|
85
|
-
# This error was raised during analysis and will be returned the client before execution
|
86
|
-
[]
|
87
|
-
end
|
88
|
-
|
89
|
-
def analysis_errors(results)
|
90
|
-
results.flatten.tap { _1.select! { |r| r.is_a?(GraphQL::AnalysisError) } }
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module GraphQL
|
3
|
-
module Language
|
4
|
-
# Emitted by the lexer and passed to the parser.
|
5
|
-
# Contains type, value and position data.
|
6
|
-
class Token
|
7
|
-
# @return [Symbol] The kind of token this is
|
8
|
-
attr_reader :name
|
9
|
-
# @return [String] The text of this token
|
10
|
-
attr_reader :value
|
11
|
-
attr_reader :prev_token, :line, :col
|
12
|
-
|
13
|
-
def initialize(name, value, line, col, prev_token)
|
14
|
-
@name = name
|
15
|
-
@value = -value
|
16
|
-
@line = line
|
17
|
-
@col = col
|
18
|
-
@prev_token = prev_token
|
19
|
-
end
|
20
|
-
|
21
|
-
alias to_s value
|
22
|
-
def to_i; @value.to_i; end
|
23
|
-
def to_f; @value.to_f; end
|
24
|
-
|
25
|
-
def line_and_column
|
26
|
-
[@line, @col]
|
27
|
-
end
|
28
|
-
|
29
|
-
def inspect
|
30
|
-
"(#{@name} #{@value.inspect} [#{@line}:#{@col}])"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|