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
@@ -1,280 +0,0 @@
1
- %%{
2
- machine graphql_lexer;
3
-
4
- IDENTIFIER = [_A-Za-z][_0-9A-Za-z]*;
5
- NEWLINE = [\c\r\n];
6
- BLANK = [, \t]+;
7
- COMMENT = '#' [^\n\r]*;
8
- INT = '-'? ('0'|[1-9][0-9]*);
9
- FLOAT_DECIMAL = '.'[0-9]+;
10
- FLOAT_EXP = ('e' | 'E')?('+' | '-')?[0-9]+;
11
- FLOAT = INT FLOAT_DECIMAL? FLOAT_EXP?;
12
- ON = 'on';
13
- FRAGMENT = 'fragment';
14
- TRUE = 'true';
15
- FALSE = 'false';
16
- NULL = 'null';
17
- QUERY = 'query';
18
- MUTATION = 'mutation';
19
- SUBSCRIPTION = 'subscription';
20
- SCHEMA = 'schema';
21
- SCALAR = 'scalar';
22
- TYPE = 'type';
23
- EXTEND = 'extend';
24
- IMPLEMENTS = 'implements';
25
- INTERFACE = 'interface';
26
- UNION = 'union';
27
- ENUM = 'enum';
28
- INPUT = 'input';
29
- DIRECTIVE = 'directive';
30
- REPEATABLE = 'repeatable';
31
- LCURLY = '{';
32
- RCURLY = '}';
33
- LPAREN = '(';
34
- RPAREN = ')';
35
- LBRACKET = '[';
36
- RBRACKET = ']';
37
- COLON = ':';
38
- QUOTE = '"';
39
- BACKSLASH = '\\';
40
- # Could limit to hex here, but “bad unicode escape” on 0XXF is probably a
41
- # more helpful error than “unknown char”
42
- UNICODE_DIGIT = [0-9A-Za-z];
43
- FOUR_DIGIT_UNICODE = UNICODE_DIGIT{4};
44
- N_DIGIT_UNICODE = LCURLY UNICODE_DIGIT{4,} RCURLY;
45
- UNICODE_ESCAPE = '\\u' (FOUR_DIGIT_UNICODE | N_DIGIT_UNICODE);
46
- # https://graphql.github.io/graphql-spec/June2018/#sec-String-Value
47
- STRING_ESCAPE = '\\' [\\/bfnrt];
48
- BLOCK_QUOTE = '"""';
49
- ESCAPED_BLOCK_QUOTE = '\\"""';
50
- BLOCK_STRING_CHAR = (ESCAPED_BLOCK_QUOTE | ^QUOTE | QUOTE{1,2} ^QUOTE);
51
- ESCAPED_QUOTE = '\\"';
52
- STRING_CHAR = ((ESCAPED_QUOTE | ^QUOTE) - BACKSLASH) | UNICODE_ESCAPE | STRING_ESCAPE;
53
- VAR_SIGN = '$';
54
- DIR_SIGN = '@';
55
- ELLIPSIS = '...';
56
- EQUALS = '=';
57
- BANG = '!';
58
- PIPE = '|';
59
- AMP = '&';
60
-
61
- QUOTED_STRING = QUOTE STRING_CHAR* QUOTE;
62
- BLOCK_STRING = BLOCK_QUOTE BLOCK_STRING_CHAR* QUOTE{0,2} BLOCK_QUOTE;
63
- # catch-all for anything else. must be at the bottom for precedence.
64
- UNKNOWN_CHAR = /./;
65
-
66
- # Used with ragel -V for graphviz visualization
67
- str := |*
68
- QUOTED_STRING => { emit_string(ts, te, meta, block: false) };
69
- *|;
70
-
71
- main := |*
72
- INT => { emit(:INT, ts, te, meta) };
73
- FLOAT => { emit(:FLOAT, ts, te, meta) };
74
- ON => { emit(:ON, ts, te, meta, "on") };
75
- FRAGMENT => { emit(:FRAGMENT, ts, te, meta, "fragment") };
76
- TRUE => { emit(:TRUE, ts, te, meta, "true") };
77
- FALSE => { emit(:FALSE, ts, te, meta, "false") };
78
- NULL => { emit(:NULL, ts, te, meta, "null") };
79
- QUERY => { emit(:QUERY, ts, te, meta, "query") };
80
- MUTATION => { emit(:MUTATION, ts, te, meta, "mutation") };
81
- SUBSCRIPTION => { emit(:SUBSCRIPTION, ts, te, meta, "subscription") };
82
- SCHEMA => { emit(:SCHEMA, ts, te, meta) };
83
- SCALAR => { emit(:SCALAR, ts, te, meta) };
84
- TYPE => { emit(:TYPE, ts, te, meta) };
85
- EXTEND => { emit(:EXTEND, ts, te, meta) };
86
- IMPLEMENTS => { emit(:IMPLEMENTS, ts, te, meta) };
87
- INTERFACE => { emit(:INTERFACE, ts, te, meta) };
88
- UNION => { emit(:UNION, ts, te, meta) };
89
- ENUM => { emit(:ENUM, ts, te, meta) };
90
- INPUT => { emit(:INPUT, ts, te, meta) };
91
- DIRECTIVE => { emit(:DIRECTIVE, ts, te, meta) };
92
- REPEATABLE => { emit(:REPEATABLE, ts, te, meta, "repeatable") };
93
- RCURLY => { emit(:RCURLY, ts, te, meta, "}") };
94
- LCURLY => { emit(:LCURLY, ts, te, meta, "{") };
95
- RPAREN => { emit(:RPAREN, ts, te, meta, ")") };
96
- LPAREN => { emit(:LPAREN, ts, te, meta, "(")};
97
- RBRACKET => { emit(:RBRACKET, ts, te, meta, "]") };
98
- LBRACKET => { emit(:LBRACKET, ts, te, meta, "[") };
99
- COLON => { emit(:COLON, ts, te, meta, ":") };
100
- QUOTED_STRING => { emit_string(ts, te, meta, block: false) };
101
- BLOCK_STRING => { emit_string(ts, te, meta, block: true) };
102
- VAR_SIGN => { emit(:VAR_SIGN, ts, te, meta, "$") };
103
- DIR_SIGN => { emit(:DIR_SIGN, ts, te, meta, "@") };
104
- ELLIPSIS => { emit(:ELLIPSIS, ts, te, meta, "...") };
105
- EQUALS => { emit(:EQUALS, ts, te, meta, "=") };
106
- BANG => { emit(:BANG, ts, te, meta, "!") };
107
- PIPE => { emit(:PIPE, ts, te, meta, "|") };
108
- AMP => { emit(:AMP, ts, te, meta, "&") };
109
- IDENTIFIER => { emit(:IDENTIFIER, ts, te, meta) };
110
- COMMENT => { record_comment(ts, te, meta) };
111
-
112
- NEWLINE => {
113
- meta[:line] += 1
114
- meta[:col] = 1
115
- };
116
-
117
- BLANK => { meta[:col] += te - ts };
118
-
119
- UNKNOWN_CHAR => { emit(:UNKNOWN_CHAR, ts, te, meta) };
120
-
121
- *|;
122
- }%%
123
-
124
- # frozen_string_literal: true
125
-
126
- module GraphQL
127
- module Language
128
- module Lexer
129
- def self.tokenize(query_string)
130
- run_lexer(query_string)
131
- end
132
-
133
- # Replace any escaped unicode or whitespace with the _actual_ characters
134
- # To avoid allocating more strings, this modifies the string passed into it
135
- def self.replace_escaped_characters_in_place(raw_string)
136
- raw_string.gsub!(ESCAPES, ESCAPES_REPLACE)
137
- raw_string.gsub!(UTF_8) do |_matched_str|
138
- codepoint_1 = ($1 || $2).to_i(16)
139
- codepoint_2 = $3
140
-
141
- if codepoint_2
142
- codepoint_2 = codepoint_2.to_i(16)
143
- if (codepoint_1 >= 0xD800 && codepoint_1 <= 0xDBFF) && # leading surrogate
144
- (codepoint_2 >= 0xDC00 && codepoint_2 <= 0xDFFF) # trailing surrogate
145
- # A surrogate pair
146
- combined = ((codepoint_1 - 0xD800) * 0x400) + (codepoint_2 - 0xDC00) + 0x10000
147
- [combined].pack('U'.freeze)
148
- else
149
- # Two separate code points
150
- [codepoint_1].pack('U'.freeze) + [codepoint_2].pack('U'.freeze)
151
- end
152
- else
153
- [codepoint_1].pack('U'.freeze)
154
- end
155
- end
156
- nil
157
- end
158
-
159
- private
160
-
161
- %% write data;
162
-
163
- def self.run_lexer(query_string)
164
- data = query_string.unpack(PACK_DIRECTIVE)
165
- eof = data.length
166
-
167
- # Since `Lexer` is a module, store all lexer state
168
- # in this local variable:
169
- meta = {
170
- line: 1,
171
- col: 1,
172
- data: data,
173
- tokens: [],
174
- previous_token: nil,
175
- }
176
-
177
- p ||= 0
178
- pe ||= data.length
179
-
180
- %% write init;
181
-
182
- %% write exec;
183
-
184
- meta[:tokens]
185
- end
186
-
187
- def self.record_comment(ts, te, meta)
188
- token = GraphQL::Language::Token.new(
189
- :COMMENT,
190
- meta[:data][ts, te - ts].pack(PACK_DIRECTIVE).force_encoding(UTF_8_ENCODING),
191
- meta[:line],
192
- meta[:col],
193
- meta[:previous_token],
194
- )
195
-
196
- meta[:previous_token] = token
197
-
198
- meta[:col] += te - ts
199
- end
200
-
201
- def self.emit(token_name, ts, te, meta, token_value = nil)
202
- token_value ||= meta[:data][ts, te - ts].pack(PACK_DIRECTIVE).force_encoding(UTF_8_ENCODING)
203
- meta[:tokens] << token = GraphQL::Language::Token.new(
204
- token_name,
205
- token_value,
206
- meta[:line],
207
- meta[:col],
208
- meta[:previous_token],
209
- )
210
- meta[:previous_token] = token
211
- # Bump the column counter for the next token
212
- meta[:col] += te - ts
213
- end
214
-
215
- ESCAPES = /\\["\\\/bfnrt]/
216
- ESCAPES_REPLACE = {
217
- '\\"' => '"',
218
- "\\\\" => "\\",
219
- "\\/" => '/',
220
- "\\b" => "\b",
221
- "\\f" => "\f",
222
- "\\n" => "\n",
223
- "\\r" => "\r",
224
- "\\t" => "\t",
225
- }
226
-
227
- UTF_8 = /\\u(?:([\dAa-f]{4})|\{([\da-f]{4,})\})(?:\\u([\dAa-f]{4}))?/i
228
-
229
-
230
- VALID_STRING = /\A(?:[^\\]|#{ESCAPES}|#{UTF_8})*\z/o
231
-
232
- PACK_DIRECTIVE = "c*"
233
- UTF_8_ENCODING = "UTF-8"
234
-
235
- def self.emit_string(ts, te, meta, block:)
236
- quotes_length = block ? 3 : 1
237
- value = meta[:data][ts + quotes_length, te - ts - 2 * quotes_length].pack(PACK_DIRECTIVE).force_encoding(UTF_8_ENCODING) || ''
238
- line_incr = 0
239
- if block && !value.empty?
240
- line_incr = value.count("\n")
241
- value = GraphQL::Language::BlockString.trim_whitespace(value)
242
- end
243
-
244
- if !value.valid_encoding? || !value.match?(VALID_STRING)
245
- meta[:tokens] << token = GraphQL::Language::Token.new(
246
- :BAD_UNICODE_ESCAPE,
247
- value,
248
- meta[:line],
249
- meta[:col],
250
- meta[:previous_token],
251
- )
252
- else
253
- replace_escaped_characters_in_place(value)
254
-
255
- if !value.valid_encoding?
256
- meta[:tokens] << token = GraphQL::Language::Token.new(
257
- :BAD_UNICODE_ESCAPE,
258
- value,
259
- meta[:line],
260
- meta[:col],
261
- meta[:previous_token],
262
- )
263
- else
264
- meta[:tokens] << token = GraphQL::Language::Token.new(
265
- :STRING,
266
- value,
267
- meta[:line],
268
- meta[:col],
269
- meta[:previous_token],
270
- )
271
- end
272
- end
273
-
274
- meta[:previous_token] = token
275
- meta[:col] += te - ts
276
- meta[:line] += line_incr
277
- end
278
- end
279
- end
280
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module GraphQL
4
- module Types
5
- module Relay
6
- module DefaultRelay
7
- def self.extended(child_class)
8
- child_class.default_relay(true)
9
- end
10
-
11
- def default_relay(new_value)
12
- @default_relay = new_value
13
- end
14
-
15
- def default_relay?
16
- if defined?(@default_relay)
17
- @default_relay
18
- elsif self.is_a?(Class)
19
- superclass.respond_to?(:default_relay?) && superclass.default_relay?
20
- else
21
- false
22
- end
23
- end
24
- end
25
- end
26
- end
27
- end