graphql 2.3.5 → 2.3.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/lib/graphql/analysis/analyzer.rb +89 -0
  3. data/lib/graphql/analysis/field_usage.rb +82 -0
  4. data/lib/graphql/analysis/max_query_complexity.rb +20 -0
  5. data/lib/graphql/analysis/max_query_depth.rb +20 -0
  6. data/lib/graphql/analysis/query_complexity.rb +183 -0
  7. data/lib/graphql/analysis/{ast/query_depth.rb → query_depth.rb} +23 -25
  8. data/lib/graphql/analysis/visitor.rb +283 -0
  9. data/lib/graphql/analysis.rb +92 -1
  10. data/lib/graphql/dataloader/async_dataloader.rb +2 -0
  11. data/lib/graphql/execution/interpreter/runtime.rb +6 -6
  12. data/lib/graphql/execution/interpreter.rb +1 -1
  13. data/lib/graphql/execution/lookahead.rb +10 -10
  14. data/lib/graphql/introspection/directive_type.rb +1 -1
  15. data/lib/graphql/introspection/entry_points.rb +2 -2
  16. data/lib/graphql/introspection/field_type.rb +1 -1
  17. data/lib/graphql/introspection/schema_type.rb +13 -3
  18. data/lib/graphql/introspection/type_type.rb +5 -5
  19. data/lib/graphql/language/document_from_schema_definition.rb +19 -26
  20. data/lib/graphql/language/lexer.rb +0 -3
  21. data/lib/graphql/language/sanitized_printer.rb +1 -1
  22. data/lib/graphql/language.rb +0 -1
  23. data/lib/graphql/query/context.rb +4 -0
  24. data/lib/graphql/query/null_context.rb +4 -0
  25. data/lib/graphql/query/validation_pipeline.rb +2 -2
  26. data/lib/graphql/query.rb +26 -3
  27. data/lib/graphql/schema/always_visible.rb +1 -0
  28. data/lib/graphql/schema/argument.rb +19 -5
  29. data/lib/graphql/schema/directive.rb +2 -0
  30. data/lib/graphql/schema/enum.rb +4 -4
  31. data/lib/graphql/schema/field.rb +13 -1
  32. data/lib/graphql/schema/has_single_input_argument.rb +2 -1
  33. data/lib/graphql/schema/input_object.rb +8 -7
  34. data/lib/graphql/schema/introspection_system.rb +2 -14
  35. data/lib/graphql/schema/member/has_arguments.rb +7 -6
  36. data/lib/graphql/schema/member/has_fields.rb +6 -4
  37. data/lib/graphql/schema/resolver.rb +5 -5
  38. data/lib/graphql/schema/subset.rb +397 -0
  39. data/lib/graphql/schema/type_expression.rb +2 -2
  40. data/lib/graphql/schema/validator/all_validator.rb +60 -0
  41. data/lib/graphql/schema/validator.rb +2 -0
  42. data/lib/graphql/schema/warden.rb +88 -1
  43. data/lib/graphql/schema.rb +44 -15
  44. data/lib/graphql/static_validation/base_visitor.rb +6 -5
  45. data/lib/graphql/static_validation/literal_validator.rb +4 -4
  46. data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +1 -1
  47. data/lib/graphql/static_validation/rules/arguments_are_defined.rb +1 -1
  48. data/lib/graphql/static_validation/rules/directives_are_defined.rb +1 -2
  49. data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +1 -1
  50. data/lib/graphql/static_validation/rules/fields_will_merge.rb +7 -7
  51. data/lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb +3 -3
  52. data/lib/graphql/static_validation/rules/fragment_types_exist.rb +1 -1
  53. data/lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb +1 -1
  54. data/lib/graphql/static_validation/rules/mutation_root_exists.rb +1 -1
  55. data/lib/graphql/static_validation/rules/query_root_exists.rb +1 -1
  56. data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +3 -3
  57. data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present.rb +3 -3
  58. data/lib/graphql/static_validation/rules/subscription_root_exists.rb +1 -1
  59. data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +1 -1
  60. data/lib/graphql/static_validation/rules/variables_are_input_types.rb +1 -1
  61. data/lib/graphql/static_validation/validation_context.rb +2 -2
  62. data/lib/graphql/subscriptions/broadcast_analyzer.rb +11 -5
  63. data/lib/graphql/subscriptions/event.rb +1 -1
  64. data/lib/graphql/subscriptions.rb +3 -3
  65. data/lib/graphql/testing/helpers.rb +2 -2
  66. data/lib/graphql/types/relay/connection_behaviors.rb +10 -0
  67. data/lib/graphql/types/relay/edge_behaviors.rb +10 -0
  68. data/lib/graphql/types/relay/page_info_behaviors.rb +4 -0
  69. data/lib/graphql/version.rb +1 -1
  70. metadata +12 -13
  71. data/lib/graphql/analysis/ast/analyzer.rb +0 -91
  72. data/lib/graphql/analysis/ast/field_usage.rb +0 -84
  73. data/lib/graphql/analysis/ast/max_query_complexity.rb +0 -22
  74. data/lib/graphql/analysis/ast/max_query_depth.rb +0 -22
  75. data/lib/graphql/analysis/ast/query_complexity.rb +0 -185
  76. data/lib/graphql/analysis/ast/visitor.rb +0 -284
  77. data/lib/graphql/analysis/ast.rb +0 -94
  78. data/lib/graphql/language/token.rb +0 -34
  79. data/lib/graphql/schema/invalid_type_error.rb +0 -7
@@ -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
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
- module GraphQL
3
- class Schema
4
- class InvalidTypeError < GraphQL::Error
5
- end
6
- end
7
- end