graphql 2.0.17.2 → 2.0.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/lib/graphql/analysis/ast.rb +2 -2
  3. data/lib/graphql/backtrace/trace.rb +96 -0
  4. data/lib/graphql/backtrace/tracer.rb +1 -1
  5. data/lib/graphql/backtrace.rb +6 -1
  6. data/lib/graphql/execution/interpreter/arguments.rb +1 -1
  7. data/lib/graphql/execution/interpreter/arguments_cache.rb +2 -3
  8. data/lib/graphql/execution/interpreter/resolve.rb +19 -0
  9. data/lib/graphql/execution/interpreter/runtime.rb +254 -211
  10. data/lib/graphql/execution/interpreter.rb +9 -14
  11. data/lib/graphql/execution/lazy.rb +2 -4
  12. data/lib/graphql/execution/multiplex.rb +2 -1
  13. data/lib/graphql/filter.rb +7 -2
  14. data/lib/graphql/language/document_from_schema_definition.rb +25 -9
  15. data/lib/graphql/language/lexer.rb +216 -1505
  16. data/lib/graphql/language/nodes.rb +27 -9
  17. data/lib/graphql/language/parser.rb +509 -491
  18. data/lib/graphql/language/parser.y +43 -38
  19. data/lib/graphql/pagination/active_record_relation_connection.rb +0 -8
  20. data/lib/graphql/pagination/connection.rb +5 -5
  21. data/lib/graphql/query/context.rb +62 -31
  22. data/lib/graphql/query/null_context.rb +1 -1
  23. data/lib/graphql/query.rb +22 -5
  24. data/lib/graphql/schema/argument.rb +7 -9
  25. data/lib/graphql/schema/build_from_definition.rb +15 -3
  26. data/lib/graphql/schema/enum_value.rb +2 -5
  27. data/lib/graphql/schema/field.rb +44 -31
  28. data/lib/graphql/schema/field_extension.rb +1 -4
  29. data/lib/graphql/schema/find_inherited_value.rb +2 -7
  30. data/lib/graphql/schema/member/base_dsl_methods.rb +13 -11
  31. data/lib/graphql/schema/member/has_arguments.rb +1 -1
  32. data/lib/graphql/schema/member/has_ast_node.rb +12 -0
  33. data/lib/graphql/schema/member/has_deprecation_reason.rb +3 -4
  34. data/lib/graphql/schema/member/has_directives.rb +15 -10
  35. data/lib/graphql/schema/member/has_fields.rb +87 -37
  36. data/lib/graphql/schema/member/has_validators.rb +2 -2
  37. data/lib/graphql/schema/member/relay_shortcuts.rb +19 -0
  38. data/lib/graphql/schema/member/type_system_helpers.rb +1 -1
  39. data/lib/graphql/schema/object.rb +2 -4
  40. data/lib/graphql/schema/resolver/has_payload_type.rb +9 -9
  41. data/lib/graphql/schema/resolver.rb +4 -4
  42. data/lib/graphql/schema/timeout.rb +24 -28
  43. data/lib/graphql/schema/validator.rb +1 -1
  44. data/lib/graphql/schema/warden.rb +11 -2
  45. data/lib/graphql/schema.rb +72 -1
  46. data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +12 -4
  47. data/lib/graphql/static_validation/rules/fields_will_merge.rb +2 -2
  48. data/lib/graphql/static_validation/validator.rb +1 -1
  49. data/lib/graphql/tracing/active_support_notifications_trace.rb +16 -0
  50. data/lib/graphql/tracing/appoptics_trace.rb +231 -0
  51. data/lib/graphql/tracing/appsignal_trace.rb +77 -0
  52. data/lib/graphql/tracing/data_dog_trace.rb +148 -0
  53. data/lib/graphql/tracing/legacy_trace.rb +65 -0
  54. data/lib/graphql/tracing/new_relic_trace.rb +75 -0
  55. data/lib/graphql/tracing/notifications_trace.rb +42 -0
  56. data/lib/graphql/tracing/platform_trace.rb +109 -0
  57. data/lib/graphql/tracing/platform_tracing.rb +15 -3
  58. data/lib/graphql/tracing/prometheus_trace.rb +89 -0
  59. data/lib/graphql/tracing/prometheus_tracing/graphql_collector.rb +1 -1
  60. data/lib/graphql/tracing/prometheus_tracing.rb +3 -3
  61. data/lib/graphql/tracing/scout_trace.rb +72 -0
  62. data/lib/graphql/tracing/statsd_trace.rb +56 -0
  63. data/lib/graphql/tracing/trace.rb +75 -0
  64. data/lib/graphql/tracing.rb +16 -39
  65. data/lib/graphql/type_kinds.rb +6 -3
  66. data/lib/graphql/types/relay/base_connection.rb +1 -1
  67. data/lib/graphql/types/relay/connection_behaviors.rb +24 -2
  68. data/lib/graphql/types/relay/edge_behaviors.rb +16 -2
  69. data/lib/graphql/types/relay/node_behaviors.rb +7 -1
  70. data/lib/graphql/types/relay/page_info_behaviors.rb +7 -2
  71. data/lib/graphql/types/relay.rb +0 -1
  72. data/lib/graphql/version.rb +1 -1
  73. data/lib/graphql.rb +16 -9
  74. metadata +33 -8
  75. data/lib/graphql/language/lexer.rl +0 -280
  76. data/lib/graphql/types/relay/default_relay.rb +0 -27
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5cbd730813400698874611de3530561d41834415405126cd11bbc9510355a7fd
4
- data.tar.gz: 1d44a4cbf48dcda27e68a077ee8f15306e9aec7d8855b350c9244260140647c7
3
+ metadata.gz: 43f1cc3ef36a54a31f8afa03ee3109b34f046e26c427acfb80599a2dd245cf14
4
+ data.tar.gz: 4e4a15c766650e36004175de15cfcb9f67c6b4e7d24e2f91712a6ad3f8681453
5
5
  SHA512:
6
- metadata.gz: 055e43980b9dac59a81824a4254410007ba73469c36ffdd426d8e960b04695c38cfe019e2147e9dca5dac4e6bb498c857810976691a3bf7c2da93cd4da3a5c73
7
- data.tar.gz: 9572eba439a8a5dec10683dc6bd4c5d8516853d7e23da047d324b57d95c70485a742fbd79f25f9ee74111135006d667cb42d78243e21f06c1273d22fc21ed0f4
6
+ metadata.gz: 908f3790bcc773bb6c7fe3db1f5e2ccabf361ece7b462b80fc4e59911167eabb8baf544739f31ac425579bca61b56b46937ac60e7a54a03827228016457388de
7
+ data.tar.gz: 62fb9dc90ab55aff66d3d1621fc28b18c0c9599e2f8a7f8521d372a6f549c85ac0a2e50a0d43cb77bde728cb44f85b178bb37388c6bd3d2aed5f8e91723a79ef
@@ -21,7 +21,7 @@ module GraphQL
21
21
  def analyze_multiplex(multiplex, analyzers)
22
22
  multiplex_analyzers = analyzers.map { |analyzer| analyzer.new(multiplex) }
23
23
 
24
- multiplex.trace("analyze_multiplex", { multiplex: multiplex }) do
24
+ multiplex.current_trace.analyze_multiplex(multiplex: multiplex) do
25
25
  query_results = multiplex.queries.map do |query|
26
26
  if query.valid?
27
27
  analyze_query(
@@ -48,7 +48,7 @@ module GraphQL
48
48
  # @param analyzers [Array<GraphQL::Analysis::AST::Analyzer>]
49
49
  # @return [Array<Any>] Results from those analyzers
50
50
  def analyze_query(query, analyzers, multiplex_analyzers: [])
51
- query.trace("analyze_query", { query: query }) do
51
+ query.current_trace.analyze_query(query: query) do
52
52
  query_analyzers = analyzers
53
53
  .map { |analyzer| analyzer.new(query) }
54
54
  .select { |analyzer| analyzer.analyze? }
@@ -0,0 +1,96 @@
1
+ # frozen_string_literal: true
2
+ module GraphQL
3
+ class Backtrace
4
+ module Trace
5
+ def validate(query:, validate:)
6
+ if query.multiplex
7
+ push_query_backtrace_context(query)
8
+ end
9
+ super
10
+ end
11
+
12
+ def analyze_query(query:)
13
+ if query.multiplex # missing for stand-alone static validation
14
+ push_query_backtrace_context(query)
15
+ end
16
+ super
17
+ end
18
+
19
+ def execute_query(query:)
20
+ push_query_backtrace_context(query)
21
+ super
22
+ end
23
+
24
+ def execute_query_lazy(query:, multiplex:)
25
+ query ||= multiplex.queries.first
26
+ push_query_backtrace_context(query)
27
+ super
28
+ end
29
+
30
+ def execute_field(field:, query:, ast_node:, arguments:, object:)
31
+ push_field_backtrace_context(field, query, ast_node, arguments, object)
32
+ super
33
+ end
34
+
35
+ def execute_field_lazy(field:, query:, ast_node:, arguments:, object:)
36
+ push_field_backtrace_context(field, query, ast_node, arguments, object)
37
+ super
38
+ end
39
+
40
+ def execute_multiplex(multiplex:)
41
+ super
42
+ rescue StandardError => err
43
+ # This is an unhandled error from execution,
44
+ # Re-raise it with a GraphQL trace.
45
+ multiplex_context = multiplex.context
46
+ potential_context = multiplex_context[:last_graphql_backtrace_context]
47
+
48
+ if potential_context.is_a?(GraphQL::Query::Context) ||
49
+ potential_context.is_a?(Backtrace::Frame)
50
+ raise TracedError.new(err, potential_context)
51
+ else
52
+ raise
53
+ end
54
+ ensure
55
+ multiplex_context = multiplex.context
56
+ multiplex_context.delete(:graphql_backtrace_contexts)
57
+ multiplex_context.delete(:last_graphql_backtrace_context)
58
+ end
59
+
60
+ private
61
+
62
+ def push_query_backtrace_context(query)
63
+ push_data = query
64
+ multiplex = query.multiplex
65
+ push_key = []
66
+ push_storage = multiplex.context[:graphql_backtrace_contexts] ||= {}
67
+ push_storage[push_key] = push_data
68
+ multiplex.context[:last_graphql_backtrace_context] = push_data
69
+ end
70
+
71
+ def push_field_backtrace_context(field, query, ast_node, arguments, object)
72
+ multiplex = query.multiplex
73
+ push_key = query.context[:current_path]
74
+ push_storage = multiplex.context[:graphql_backtrace_contexts]
75
+ parent_frame = push_storage[push_key[0..-2]]
76
+
77
+ if parent_frame.is_a?(GraphQL::Query)
78
+ parent_frame = parent_frame.context
79
+ end
80
+
81
+ push_data = Frame.new(
82
+ query: query,
83
+ path: push_key,
84
+ ast_node: ast_node,
85
+ field: field,
86
+ object: object,
87
+ arguments: arguments,
88
+ parent_frame: parent_frame,
89
+ )
90
+
91
+ push_storage[push_key] = push_data
92
+ multiplex.context[:last_graphql_backtrace_context] = push_data
93
+ end
94
+ end
95
+ end
96
+ end
@@ -25,7 +25,7 @@ module GraphQL
25
25
  when "execute_field", "execute_field_lazy"
26
26
  query = metadata[:query]
27
27
  multiplex = query.multiplex
28
- push_key = metadata[:path]
28
+ push_key = query.context[:current_path]
29
29
  parent_frame = multiplex.context[:graphql_backtrace_contexts][push_key[0..-2]]
30
30
 
31
31
  if parent_frame.is_a?(GraphQL::Query)
@@ -3,6 +3,7 @@ require "graphql/backtrace/inspect_result"
3
3
  require "graphql/backtrace/table"
4
4
  require "graphql/backtrace/traced_error"
5
5
  require "graphql/backtrace/tracer"
6
+ require "graphql/backtrace/trace"
6
7
  module GraphQL
7
8
  # Wrap unhandled errors with {TracedError}.
8
9
  #
@@ -23,7 +24,7 @@ module GraphQL
23
24
  def_delegators :to_a, :each, :[]
24
25
 
25
26
  def self.use(schema_defn)
26
- schema_defn.tracer(self::Tracer)
27
+ schema_defn.trace_with(self::Trace)
27
28
  end
28
29
 
29
30
  def initialize(context, value: nil)
@@ -54,5 +55,9 @@ module GraphQL
54
55
  @parent_frame = parent_frame
55
56
  end
56
57
  end
58
+
59
+ class DefaultBacktraceTrace < GraphQL::Tracing::Trace
60
+ include GraphQL::Backtrace::Trace
61
+ end
57
62
  end
58
63
  end
@@ -80,7 +80,7 @@ module GraphQL
80
80
  )
81
81
  end
82
82
 
83
- NO_ARGS = {}.freeze
83
+ NO_ARGS = GraphQL::EmptyObjects::EMPTY_HASH
84
84
  EMPTY = self.new(argument_values: nil, keyword_arguments: NO_ARGS).freeze
85
85
  end
86
86
  end
@@ -55,9 +55,8 @@ module GraphQL
55
55
 
56
56
  private
57
57
 
58
- NO_ARGUMENTS = {}.freeze
59
-
60
- NO_VALUE_GIVEN = Object.new
58
+ NO_ARGUMENTS = GraphQL::EmptyObjects::EMPTY_HASH
59
+ NO_VALUE_GIVEN = NOT_CONFIGURED
61
60
 
62
61
  def self.prepare_args_hash(query, ast_arg_or_hash_or_value)
63
62
  case ast_arg_or_hash_or_value
@@ -11,6 +11,25 @@ module GraphQL
11
11
  nil
12
12
  end
13
13
 
14
+ def self.resolve_each_depth(lazies_at_depth, dataloader)
15
+ depths = lazies_at_depth.keys
16
+ depths.sort!
17
+ next_depth = depths.first
18
+ if next_depth
19
+ lazies = lazies_at_depth[next_depth]
20
+ lazies_at_depth.delete(next_depth)
21
+ if lazies.any?
22
+ dataloader.append_job {
23
+ lazies.each(&:value) # resolve these Lazy instances
24
+ }
25
+ # Run lazies _and_ dataloader, see if more are enqueued
26
+ dataloader.run
27
+ resolve_each_depth(lazies_at_depth, dataloader)
28
+ end
29
+ end
30
+ nil
31
+ end
32
+
14
33
  # After getting `results` back from an interpreter evaluation,
15
34
  # continue it until you get a response-ready Ruby value.
16
35
  #