graphql 2.0.13 → 2.3.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (228) hide show
  1. checksums.yaml +4 -4
  2. data/lib/generators/graphql/install/mutation_root_generator.rb +2 -2
  3. data/lib/generators/graphql/install/templates/base_mutation.erb +2 -0
  4. data/lib/generators/graphql/install/templates/mutation_type.erb +2 -0
  5. data/lib/generators/graphql/install_generator.rb +3 -0
  6. data/lib/generators/graphql/mutation_delete_generator.rb +1 -1
  7. data/lib/generators/graphql/mutation_update_generator.rb +1 -1
  8. data/lib/generators/graphql/relay.rb +18 -1
  9. data/lib/generators/graphql/templates/base_argument.erb +2 -0
  10. data/lib/generators/graphql/templates/base_connection.erb +2 -0
  11. data/lib/generators/graphql/templates/base_edge.erb +2 -0
  12. data/lib/generators/graphql/templates/base_enum.erb +2 -0
  13. data/lib/generators/graphql/templates/base_field.erb +2 -0
  14. data/lib/generators/graphql/templates/base_input_object.erb +2 -0
  15. data/lib/generators/graphql/templates/base_interface.erb +2 -0
  16. data/lib/generators/graphql/templates/base_object.erb +2 -0
  17. data/lib/generators/graphql/templates/base_resolver.erb +6 -0
  18. data/lib/generators/graphql/templates/base_scalar.erb +2 -0
  19. data/lib/generators/graphql/templates/base_union.erb +2 -0
  20. data/lib/generators/graphql/templates/graphql_controller.erb +2 -0
  21. data/lib/generators/graphql/templates/loader.erb +2 -0
  22. data/lib/generators/graphql/templates/mutation.erb +2 -0
  23. data/lib/generators/graphql/templates/node_type.erb +2 -0
  24. data/lib/generators/graphql/templates/query_type.erb +2 -0
  25. data/lib/generators/graphql/templates/schema.erb +8 -0
  26. data/lib/graphql/analysis/analyzer.rb +89 -0
  27. data/lib/graphql/analysis/field_usage.rb +82 -0
  28. data/lib/graphql/analysis/max_query_complexity.rb +20 -0
  29. data/lib/graphql/analysis/max_query_depth.rb +20 -0
  30. data/lib/graphql/analysis/query_complexity.rb +183 -0
  31. data/lib/graphql/analysis/query_depth.rb +58 -0
  32. data/lib/graphql/analysis/visitor.rb +283 -0
  33. data/lib/graphql/analysis.rb +92 -1
  34. data/lib/graphql/backtrace/inspect_result.rb +0 -12
  35. data/lib/graphql/backtrace/table.rb +2 -2
  36. data/lib/graphql/backtrace/trace.rb +93 -0
  37. data/lib/graphql/backtrace/tracer.rb +1 -1
  38. data/lib/graphql/backtrace.rb +2 -1
  39. data/lib/graphql/coercion_error.rb +1 -9
  40. data/lib/graphql/dataloader/async_dataloader.rb +88 -0
  41. data/lib/graphql/dataloader/null_dataloader.rb +1 -1
  42. data/lib/graphql/dataloader/request.rb +5 -0
  43. data/lib/graphql/dataloader/source.rb +89 -45
  44. data/lib/graphql/dataloader.rb +115 -142
  45. data/lib/graphql/duration_encoding_error.rb +16 -0
  46. data/lib/graphql/execution/interpreter/argument_value.rb +5 -1
  47. data/lib/graphql/execution/interpreter/arguments.rb +1 -1
  48. data/lib/graphql/execution/interpreter/arguments_cache.rb +33 -33
  49. data/lib/graphql/execution/interpreter/resolve.rb +19 -0
  50. data/lib/graphql/execution/interpreter/runtime/graphql_result.rb +175 -0
  51. data/lib/graphql/execution/interpreter/runtime.rb +331 -455
  52. data/lib/graphql/execution/interpreter.rb +125 -61
  53. data/lib/graphql/execution/lazy.rb +6 -12
  54. data/lib/graphql/execution/lookahead.rb +124 -46
  55. data/lib/graphql/execution/multiplex.rb +3 -117
  56. data/lib/graphql/execution.rb +0 -1
  57. data/lib/graphql/introspection/directive_type.rb +3 -3
  58. data/lib/graphql/introspection/dynamic_fields.rb +1 -1
  59. data/lib/graphql/introspection/entry_points.rb +11 -5
  60. data/lib/graphql/introspection/field_type.rb +2 -2
  61. data/lib/graphql/introspection/schema_type.rb +10 -13
  62. data/lib/graphql/introspection/type_type.rb +17 -10
  63. data/lib/graphql/introspection.rb +3 -2
  64. data/lib/graphql/language/block_string.rb +34 -18
  65. data/lib/graphql/language/definition_slice.rb +1 -1
  66. data/lib/graphql/language/document_from_schema_definition.rb +75 -59
  67. data/lib/graphql/language/lexer.rb +358 -1506
  68. data/lib/graphql/language/nodes.rb +166 -93
  69. data/lib/graphql/language/parser.rb +795 -1953
  70. data/lib/graphql/language/printer.rb +340 -160
  71. data/lib/graphql/language/sanitized_printer.rb +21 -23
  72. data/lib/graphql/language/static_visitor.rb +167 -0
  73. data/lib/graphql/language/visitor.rb +188 -141
  74. data/lib/graphql/language.rb +61 -1
  75. data/lib/graphql/load_application_object_failed_error.rb +5 -1
  76. data/lib/graphql/pagination/active_record_relation_connection.rb +0 -8
  77. data/lib/graphql/pagination/array_connection.rb +6 -6
  78. data/lib/graphql/pagination/connection.rb +33 -6
  79. data/lib/graphql/pagination/mongoid_relation_connection.rb +1 -2
  80. data/lib/graphql/query/context/scoped_context.rb +101 -0
  81. data/lib/graphql/query/context.rb +117 -112
  82. data/lib/graphql/query/null_context.rb +12 -25
  83. data/lib/graphql/query/validation_pipeline.rb +6 -5
  84. data/lib/graphql/query/variables.rb +3 -3
  85. data/lib/graphql/query.rb +86 -30
  86. data/lib/graphql/railtie.rb +9 -6
  87. data/lib/graphql/rake_task.rb +29 -11
  88. data/lib/graphql/rubocop/graphql/base_cop.rb +1 -1
  89. data/lib/graphql/schema/addition.rb +59 -23
  90. data/lib/graphql/schema/always_visible.rb +11 -0
  91. data/lib/graphql/schema/argument.rb +55 -26
  92. data/lib/graphql/schema/base_64_encoder.rb +3 -5
  93. data/lib/graphql/schema/build_from_definition.rb +56 -32
  94. data/lib/graphql/schema/directive/one_of.rb +24 -0
  95. data/lib/graphql/schema/directive/specified_by.rb +14 -0
  96. data/lib/graphql/schema/directive/transform.rb +1 -1
  97. data/lib/graphql/schema/directive.rb +15 -3
  98. data/lib/graphql/schema/enum.rb +35 -24
  99. data/lib/graphql/schema/enum_value.rb +2 -3
  100. data/lib/graphql/schema/field/connection_extension.rb +2 -16
  101. data/lib/graphql/schema/field/scope_extension.rb +8 -1
  102. data/lib/graphql/schema/field.rb +147 -107
  103. data/lib/graphql/schema/field_extension.rb +1 -4
  104. data/lib/graphql/schema/find_inherited_value.rb +2 -7
  105. data/lib/graphql/schema/has_single_input_argument.rb +158 -0
  106. data/lib/graphql/schema/input_object.rb +47 -11
  107. data/lib/graphql/schema/interface.rb +15 -21
  108. data/lib/graphql/schema/introspection_system.rb +7 -17
  109. data/lib/graphql/schema/late_bound_type.rb +10 -0
  110. data/lib/graphql/schema/list.rb +2 -2
  111. data/lib/graphql/schema/loader.rb +2 -3
  112. data/lib/graphql/schema/member/base_dsl_methods.rb +18 -14
  113. data/lib/graphql/schema/member/build_type.rb +11 -3
  114. data/lib/graphql/schema/member/has_arguments.rb +170 -130
  115. data/lib/graphql/schema/member/has_ast_node.rb +12 -0
  116. data/lib/graphql/schema/member/has_deprecation_reason.rb +3 -4
  117. data/lib/graphql/schema/member/has_directives.rb +81 -61
  118. data/lib/graphql/schema/member/has_fields.rb +100 -38
  119. data/lib/graphql/schema/member/has_interfaces.rb +65 -10
  120. data/lib/graphql/schema/member/has_unresolved_type_error.rb +5 -1
  121. data/lib/graphql/schema/member/has_validators.rb +32 -6
  122. data/lib/graphql/schema/member/relay_shortcuts.rb +19 -0
  123. data/lib/graphql/schema/member/scoped.rb +19 -0
  124. data/lib/graphql/schema/member/type_system_helpers.rb +16 -0
  125. data/lib/graphql/schema/member/validates_input.rb +3 -3
  126. data/lib/graphql/schema/mutation.rb +7 -0
  127. data/lib/graphql/schema/object.rb +16 -5
  128. data/lib/graphql/schema/printer.rb +11 -8
  129. data/lib/graphql/schema/relay_classic_mutation.rb +7 -129
  130. data/lib/graphql/schema/resolver/has_payload_type.rb +9 -9
  131. data/lib/graphql/schema/resolver.rb +47 -32
  132. data/lib/graphql/schema/scalar.rb +3 -3
  133. data/lib/graphql/schema/subscription.rb +11 -4
  134. data/lib/graphql/schema/subset.rb +397 -0
  135. data/lib/graphql/schema/timeout.rb +25 -29
  136. data/lib/graphql/schema/type_expression.rb +2 -2
  137. data/lib/graphql/schema/type_membership.rb +3 -0
  138. data/lib/graphql/schema/union.rb +11 -2
  139. data/lib/graphql/schema/unique_within_type.rb +1 -1
  140. data/lib/graphql/schema/validator/all_validator.rb +60 -0
  141. data/lib/graphql/schema/validator.rb +4 -2
  142. data/lib/graphql/schema/warden.rb +238 -93
  143. data/lib/graphql/schema.rb +498 -103
  144. data/lib/graphql/static_validation/all_rules.rb +2 -1
  145. data/lib/graphql/static_validation/base_visitor.rb +7 -6
  146. data/lib/graphql/static_validation/definition_dependencies.rb +7 -1
  147. data/lib/graphql/static_validation/literal_validator.rb +24 -7
  148. data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +1 -1
  149. data/lib/graphql/static_validation/rules/arguments_are_defined.rb +1 -1
  150. data/lib/graphql/static_validation/rules/directives_are_defined.rb +1 -2
  151. data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +1 -1
  152. data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +12 -4
  153. data/lib/graphql/static_validation/rules/fields_will_merge.rb +10 -10
  154. data/lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb +3 -3
  155. data/lib/graphql/static_validation/rules/fragment_types_exist.rb +1 -1
  156. data/lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb +1 -1
  157. data/lib/graphql/static_validation/rules/mutation_root_exists.rb +1 -1
  158. data/lib/graphql/static_validation/rules/one_of_input_objects_are_valid.rb +66 -0
  159. data/lib/graphql/static_validation/rules/one_of_input_objects_are_valid_error.rb +29 -0
  160. data/lib/graphql/static_validation/rules/query_root_exists.rb +1 -1
  161. data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +4 -4
  162. data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present.rb +5 -5
  163. data/lib/graphql/static_validation/rules/subscription_root_exists.rb +1 -1
  164. data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +18 -27
  165. data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +1 -1
  166. data/lib/graphql/static_validation/rules/variables_are_input_types.rb +1 -1
  167. data/lib/graphql/static_validation/validation_context.rb +5 -5
  168. data/lib/graphql/static_validation/validator.rb +4 -1
  169. data/lib/graphql/static_validation.rb +0 -1
  170. data/lib/graphql/subscriptions/action_cable_subscriptions.rb +11 -4
  171. data/lib/graphql/subscriptions/broadcast_analyzer.rb +11 -5
  172. data/lib/graphql/subscriptions/event.rb +11 -10
  173. data/lib/graphql/subscriptions/serialize.rb +2 -0
  174. data/lib/graphql/subscriptions.rb +20 -13
  175. data/lib/graphql/testing/helpers.rb +151 -0
  176. data/lib/graphql/testing.rb +2 -0
  177. data/lib/graphql/tracing/active_support_notifications_trace.rb +16 -0
  178. data/lib/graphql/tracing/appoptics_trace.rb +251 -0
  179. data/lib/graphql/tracing/appoptics_tracing.rb +2 -2
  180. data/lib/graphql/tracing/appsignal_trace.rb +77 -0
  181. data/lib/graphql/tracing/data_dog_trace.rb +183 -0
  182. data/lib/graphql/tracing/data_dog_tracing.rb +9 -21
  183. data/lib/graphql/{execution/instrumentation.rb → tracing/legacy_hooks_trace.rb} +10 -28
  184. data/lib/graphql/tracing/legacy_trace.rb +69 -0
  185. data/lib/graphql/tracing/new_relic_trace.rb +75 -0
  186. data/lib/graphql/tracing/notifications_trace.rb +45 -0
  187. data/lib/graphql/tracing/platform_trace.rb +118 -0
  188. data/lib/graphql/tracing/platform_tracing.rb +17 -3
  189. data/lib/graphql/tracing/{prometheus_tracing → prometheus_trace}/graphql_collector.rb +4 -2
  190. data/lib/graphql/tracing/prometheus_trace.rb +89 -0
  191. data/lib/graphql/tracing/prometheus_tracing.rb +3 -3
  192. data/lib/graphql/tracing/scout_trace.rb +72 -0
  193. data/lib/graphql/tracing/sentry_trace.rb +112 -0
  194. data/lib/graphql/tracing/statsd_trace.rb +56 -0
  195. data/lib/graphql/tracing/trace.rb +76 -0
  196. data/lib/graphql/tracing.rb +20 -40
  197. data/lib/graphql/type_kinds.rb +7 -4
  198. data/lib/graphql/types/iso_8601_duration.rb +77 -0
  199. data/lib/graphql/types/relay/base_connection.rb +1 -1
  200. data/lib/graphql/types/relay/connection_behaviors.rb +68 -6
  201. data/lib/graphql/types/relay/edge_behaviors.rb +33 -5
  202. data/lib/graphql/types/relay/node_behaviors.rb +8 -2
  203. data/lib/graphql/types/relay/page_info_behaviors.rb +11 -2
  204. data/lib/graphql/types/relay.rb +0 -1
  205. data/lib/graphql/types/string.rb +1 -1
  206. data/lib/graphql/types.rb +1 -0
  207. data/lib/graphql/version.rb +1 -1
  208. data/lib/graphql.rb +27 -20
  209. data/readme.md +13 -3
  210. metadata +96 -47
  211. data/lib/graphql/analysis/ast/analyzer.rb +0 -84
  212. data/lib/graphql/analysis/ast/field_usage.rb +0 -57
  213. data/lib/graphql/analysis/ast/max_query_complexity.rb +0 -22
  214. data/lib/graphql/analysis/ast/max_query_depth.rb +0 -22
  215. data/lib/graphql/analysis/ast/query_complexity.rb +0 -230
  216. data/lib/graphql/analysis/ast/query_depth.rb +0 -55
  217. data/lib/graphql/analysis/ast/visitor.rb +0 -269
  218. data/lib/graphql/analysis/ast.rb +0 -81
  219. data/lib/graphql/deprecation.rb +0 -9
  220. data/lib/graphql/filter.rb +0 -53
  221. data/lib/graphql/language/lexer.rl +0 -280
  222. data/lib/graphql/language/parser.y +0 -554
  223. data/lib/graphql/language/token.rb +0 -34
  224. data/lib/graphql/schema/base_64_bp.rb +0 -26
  225. data/lib/graphql/schema/invalid_type_error.rb +0 -7
  226. data/lib/graphql/static_validation/type_stack.rb +0 -216
  227. data/lib/graphql/subscriptions/instrumentation.rb +0 -28
  228. data/lib/graphql/types/relay/default_relay.rb +0 -21
@@ -1,554 +0,0 @@
1
- class GraphQL::Language::Parser
2
- rule
3
- target: document
4
-
5
- document: definitions_list { result = make_node(:Document, definitions: val[0])}
6
-
7
- definitions_list:
8
- definition { result = [val[0]]}
9
- | definitions_list definition { val[0] << val[1] }
10
-
11
- definition:
12
- executable_definition
13
- | type_system_definition
14
- | type_system_extension
15
-
16
- executable_definition:
17
- operation_definition
18
- | fragment_definition
19
-
20
- operation_definition:
21
- operation_type operation_name_opt variable_definitions_opt directives_list_opt selection_set {
22
- result = make_node(
23
- :OperationDefinition, {
24
- operation_type: val[0],
25
- name: val[1],
26
- variables: val[2],
27
- directives: val[3],
28
- selections: val[4],
29
- position_source: val[0],
30
- }
31
- )
32
- }
33
- | LCURLY selection_list RCURLY {
34
- result = make_node(
35
- :OperationDefinition, {
36
- operation_type: "query",
37
- selections: val[1],
38
- position_source: val[0],
39
- }
40
- )
41
- }
42
- | LCURLY RCURLY {
43
- result = make_node(
44
- :OperationDefinition, {
45
- operation_type: "query",
46
- selections: [],
47
- position_source: val[0],
48
- }
49
- )
50
- }
51
-
52
- operation_type:
53
- QUERY
54
- | MUTATION
55
- | SUBSCRIPTION
56
-
57
- operation_name_opt:
58
- /* none */ { result = nil }
59
- | name
60
-
61
- variable_definitions_opt:
62
- /* none */ { result = EMPTY_ARRAY }
63
- | LPAREN variable_definitions_list RPAREN { result = val[1] }
64
-
65
- variable_definitions_list:
66
- variable_definition { result = [val[0]] }
67
- | variable_definitions_list variable_definition { val[0] << val[1] }
68
-
69
- variable_definition:
70
- VAR_SIGN name COLON type default_value_opt {
71
- result = make_node(:VariableDefinition, {
72
- name: val[1],
73
- type: val[3],
74
- default_value: val[4],
75
- position_source: val[0],
76
- })
77
- }
78
-
79
- type:
80
- nullable_type { result = val[0] }
81
- | nullable_type BANG { result = make_node(:NonNullType, of_type: val[0]) }
82
-
83
- nullable_type:
84
- name { result = make_node(:TypeName, name: val[0])}
85
- | LBRACKET type RBRACKET { result = make_node(:ListType, of_type: val[1]) }
86
-
87
- default_value_opt:
88
- /* none */ { result = nil }
89
- | EQUALS literal_value { result = val[1] }
90
-
91
- selection_set:
92
- LCURLY selection_list RCURLY { result = val[1] }
93
-
94
- selection_set_opt:
95
- /* none */ { result = EMPTY_ARRAY }
96
- | selection_set { result = val[0] }
97
-
98
- selection_list:
99
- selection { result = [result] }
100
- | selection_list selection { val[0] << val[1] }
101
-
102
- selection:
103
- field
104
- | fragment_spread
105
- | inline_fragment
106
-
107
- field:
108
- name arguments_opt directives_list_opt selection_set_opt {
109
- result = make_node(
110
- :Field, {
111
- name: val[0],
112
- arguments: val[1],
113
- directives: val[2],
114
- selections: val[3],
115
- position_source: val[0],
116
- }
117
- )
118
- }
119
- | name COLON name arguments_opt directives_list_opt selection_set_opt {
120
- result = make_node(
121
- :Field, {
122
- alias: val[0],
123
- name: val[2],
124
- arguments: val[3],
125
- directives: val[4],
126
- selections: val[5],
127
- position_source: val[0],
128
- }
129
- )
130
- }
131
-
132
- name:
133
- name_without_on
134
- | ON
135
-
136
- schema_keyword:
137
- SCHEMA
138
- | SCALAR
139
- | TYPE
140
- | IMPLEMENTS
141
- | INTERFACE
142
- | UNION
143
- | ENUM
144
- | INPUT
145
- | DIRECTIVE
146
-
147
- name_without_on:
148
- IDENTIFIER
149
- | FRAGMENT
150
- | REPEATABLE
151
- | TRUE
152
- | FALSE
153
- | operation_type
154
- | schema_keyword
155
-
156
- enum_name: /* any identifier, but not "true", "false" or "null" */
157
- IDENTIFIER
158
- | FRAGMENT
159
- | REPEATABLE
160
- | ON
161
- | operation_type
162
- | schema_keyword
163
-
164
- enum_value_definition:
165
- description_opt enum_name directives_list_opt { result = make_node(:EnumValueDefinition, name: val[1], directives: val[2], description: val[0] || get_description(val[1]), definition_line: val[1].line, position_source: val[0] || val[1]) }
166
-
167
- enum_value_definitions:
168
- enum_value_definition { result = [val[0]] }
169
- | enum_value_definitions enum_value_definition { result = val[0] << val[1] }
170
-
171
- arguments_opt:
172
- /* none */ { result = EMPTY_ARRAY }
173
- | LPAREN arguments_list RPAREN { result = val[1] }
174
-
175
- arguments_list:
176
- argument { result = [val[0]] }
177
- | arguments_list argument { val[0] << val[1] }
178
-
179
- argument:
180
- name COLON input_value { result = make_node(:Argument, name: val[0], value: val[2], position_source: val[0])}
181
-
182
- literal_value:
183
- FLOAT { result = val[0].to_f }
184
- | INT { result = val[0].to_i }
185
- | STRING { result = val[0].to_s }
186
- | TRUE { result = true }
187
- | FALSE { result = false }
188
- | null_value
189
- | enum_value
190
- | list_value
191
- | object_literal_value
192
-
193
- input_value:
194
- literal_value
195
- | variable
196
- | object_value
197
-
198
- null_value: NULL { result = make_node(:NullValue, name: val[0], position_source: val[0]) }
199
- variable: VAR_SIGN name { result = make_node(:VariableIdentifier, name: val[1], position_source: val[0]) }
200
-
201
- list_value:
202
- LBRACKET RBRACKET { result = EMPTY_ARRAY }
203
- | LBRACKET list_value_list RBRACKET { result = val[1] }
204
-
205
- list_value_list:
206
- input_value { result = [val[0]] }
207
- | list_value_list input_value { val[0] << val[1] }
208
-
209
- object_value:
210
- LCURLY RCURLY { result = make_node(:InputObject, arguments: [], position_source: val[0])}
211
- | LCURLY object_value_list RCURLY { result = make_node(:InputObject, arguments: val[1], position_source: val[0])}
212
-
213
- object_value_list:
214
- object_value_field { result = [val[0]] }
215
- | object_value_list object_value_field { val[0] << val[1] }
216
-
217
- object_value_field:
218
- name COLON input_value { result = make_node(:Argument, name: val[0], value: val[2], position_source: val[0])}
219
-
220
- /* like the previous, but with literals only: */
221
- object_literal_value:
222
- LCURLY RCURLY { result = make_node(:InputObject, arguments: [], position_source: val[0])}
223
- | LCURLY object_literal_value_list RCURLY { result = make_node(:InputObject, arguments: val[1], position_source: val[0])}
224
-
225
- object_literal_value_list:
226
- object_literal_value_field { result = [val[0]] }
227
- | object_literal_value_list object_literal_value_field { val[0] << val[1] }
228
-
229
- object_literal_value_field:
230
- name COLON literal_value { result = make_node(:Argument, name: val[0], value: val[2], position_source: val[0])}
231
-
232
- enum_value: enum_name { result = make_node(:Enum, name: val[0], position_source: val[0]) }
233
-
234
- directives_list_opt:
235
- /* none */ { result = EMPTY_ARRAY }
236
- | directives_list
237
-
238
- directives_list:
239
- directive { result = [val[0]] }
240
- | directives_list directive { val[0] << val[1] }
241
-
242
- directive: DIR_SIGN name arguments_opt { result = make_node(:Directive, name: val[1], arguments: val[2], position_source: val[0]) }
243
-
244
- fragment_spread:
245
- ELLIPSIS name_without_on directives_list_opt { result = make_node(:FragmentSpread, name: val[1], directives: val[2], position_source: val[0]) }
246
-
247
- inline_fragment:
248
- ELLIPSIS ON type directives_list_opt selection_set {
249
- result = make_node(:InlineFragment, {
250
- type: val[2],
251
- directives: val[3],
252
- selections: val[4],
253
- position_source: val[0]
254
- })
255
- }
256
- | ELLIPSIS directives_list_opt selection_set {
257
- result = make_node(:InlineFragment, {
258
- type: nil,
259
- directives: val[1],
260
- selections: val[2],
261
- position_source: val[0]
262
- })
263
- }
264
-
265
- fragment_definition:
266
- FRAGMENT fragment_name_opt ON type directives_list_opt selection_set {
267
- result = make_node(:FragmentDefinition, {
268
- name: val[1],
269
- type: val[3],
270
- directives: val[4],
271
- selections: val[5],
272
- position_source: val[0],
273
- }
274
- )
275
- }
276
-
277
- fragment_name_opt:
278
- /* none */ { result = nil }
279
- | name_without_on
280
-
281
- type_system_definition:
282
- schema_definition
283
- | type_definition
284
- | directive_definition
285
-
286
- schema_definition:
287
- SCHEMA directives_list_opt LCURLY operation_type_definition_list RCURLY { result = make_node(:SchemaDefinition, position_source: val[0], definition_line: val[0].line, directives: val[1], **val[3]) }
288
-
289
- operation_type_definition_list:
290
- operation_type_definition
291
- | operation_type_definition_list operation_type_definition { result = val[0].merge(val[1]) }
292
-
293
- operation_type_definition:
294
- operation_type COLON name { result = { val[0].to_s.to_sym => val[2] } }
295
-
296
- type_definition:
297
- scalar_type_definition
298
- | object_type_definition
299
- | interface_type_definition
300
- | union_type_definition
301
- | enum_type_definition
302
- | input_object_type_definition
303
-
304
- type_system_extension:
305
- schema_extension
306
- | type_extension
307
-
308
- schema_extension:
309
- EXTEND SCHEMA directives_list_opt LCURLY operation_type_definition_list RCURLY { result = make_node(:SchemaExtension, position_source: val[0], directives: val[2], **val[4]) }
310
- | EXTEND SCHEMA directives_list { result = make_node(:SchemaExtension, position_source: val[0], directives: val[2]) }
311
-
312
- type_extension:
313
- scalar_type_extension
314
- | object_type_extension
315
- | interface_type_extension
316
- | union_type_extension
317
- | enum_type_extension
318
- | input_object_type_extension
319
-
320
- scalar_type_extension: EXTEND SCALAR name directives_list { result = make_node(:ScalarTypeExtension, name: val[2], directives: val[3], position_source: val[0]) }
321
-
322
- object_type_extension:
323
- /* TODO - This first one shouldn't be necessary but parser is getting confused */
324
- EXTEND TYPE name implements field_definition_list_opt { result = make_node(:ObjectTypeExtension, name: val[2], interfaces: val[3], directives: [], fields: val[4], position_source: val[0]) }
325
- | EXTEND TYPE name implements_opt directives_list_opt field_definition_list_opt { result = make_node(:ObjectTypeExtension, name: val[2], interfaces: val[3], directives: val[4], fields: val[5], position_source: val[0]) }
326
- | EXTEND TYPE name implements_opt directives_list { result = make_node(:ObjectTypeExtension, name: val[2], interfaces: val[3], directives: val[4], fields: [], position_source: val[0]) }
327
- | EXTEND TYPE name implements { result = make_node(:ObjectTypeExtension, name: val[2], interfaces: val[3], directives: [], fields: [], position_source: val[0]) }
328
-
329
- interface_type_extension:
330
- EXTEND INTERFACE name implements_opt directives_list_opt field_definition_list_opt { result = make_node(:InterfaceTypeExtension, name: val[2], interfaces: val[3], directives: val[4], fields: val[5], position_source: val[0]) }
331
- | EXTEND INTERFACE name implements_opt directives_list { result = make_node(:InterfaceTypeExtension, name: val[2], interfaces: val[3], directives: val[4], fields: [], position_source: val[0]) }
332
- | EXTEND INTERFACE name implements { result = make_node(:InterfaceTypeExtension, name: val[2], interfaces: val[3], directives: [], fields: [], position_source: val[0]) }
333
-
334
- union_type_extension:
335
- EXTEND UNION name directives_list_opt EQUALS union_members { result = make_node(:UnionTypeExtension, name: val[2], directives: val[3], types: val[5], position_source: val[0]) }
336
- | EXTEND UNION name directives_list { result = make_node(:UnionTypeExtension, name: val[2], directives: val[3], types: [], position_source: val[0]) }
337
-
338
- enum_type_extension:
339
- EXTEND ENUM name directives_list_opt LCURLY enum_value_definitions RCURLY { result = make_node(:EnumTypeExtension, name: val[2], directives: val[3], values: val[5], position_source: val[0]) }
340
- | EXTEND ENUM name directives_list { result = make_node(:EnumTypeExtension, name: val[2], directives: val[3], values: [], position_source: val[0]) }
341
-
342
- input_object_type_extension:
343
- EXTEND INPUT name directives_list_opt LCURLY input_value_definition_list RCURLY { result = make_node(:InputObjectTypeExtension, name: val[2], directives: val[3], fields: val[5], position_source: val[0]) }
344
- | EXTEND INPUT name directives_list { result = make_node(:InputObjectTypeExtension, name: val[2], directives: val[3], fields: [], position_source: val[0]) }
345
-
346
- description: STRING
347
-
348
- description_opt:
349
- /* none */
350
- | description
351
-
352
- scalar_type_definition:
353
- description_opt SCALAR name directives_list_opt {
354
- result = make_node(:ScalarTypeDefinition, name: val[2], directives: val[3], description: val[0] || get_description(val[1]), definition_line: val[1].line, position_source: val[0] || val[1])
355
- }
356
-
357
- object_type_definition:
358
- description_opt TYPE name implements_opt directives_list_opt field_definition_list_opt {
359
- result = make_node(:ObjectTypeDefinition, name: val[2], interfaces: val[3], directives: val[4], fields: val[5], description: val[0] || get_description(val[1]), definition_line: val[1].line, position_source: val[0] || val[1])
360
- }
361
-
362
- implements_opt:
363
- /* none */ { result = EMPTY_ARRAY }
364
- | implements
365
-
366
- implements:
367
- IMPLEMENTS AMP interfaces_list { result = val[2] }
368
- | IMPLEMENTS interfaces_list { result = val[1] }
369
- | IMPLEMENTS legacy_interfaces_list { result = val[1] }
370
-
371
- interfaces_list:
372
- name { result = [make_node(:TypeName, name: val[0], position_source: val[0])] }
373
- | interfaces_list AMP name { val[0] << make_node(:TypeName, name: val[2], position_source: val[2]) }
374
-
375
- legacy_interfaces_list:
376
- name { result = [make_node(:TypeName, name: val[0], position_source: val[0])] }
377
- | legacy_interfaces_list name { val[0] << make_node(:TypeName, name: val[1], position_source: val[1]) }
378
-
379
- input_value_definition:
380
- description_opt name COLON type default_value_opt directives_list_opt {
381
- result = make_node(:InputValueDefinition, name: val[1], type: val[3], default_value: val[4], directives: val[5], description: val[0] || get_description(val[1]), definition_line: val[1].line, position_source: val[0] || val[1])
382
- }
383
-
384
- input_value_definition_list:
385
- input_value_definition { result = [val[0]] }
386
- | input_value_definition_list input_value_definition { val[0] << val[1] }
387
-
388
- arguments_definitions_opt:
389
- /* none */ { result = EMPTY_ARRAY }
390
- | LPAREN input_value_definition_list RPAREN { result = val[1] }
391
-
392
- field_definition:
393
- description_opt name arguments_definitions_opt COLON type directives_list_opt {
394
- result = make_node(:FieldDefinition, name: val[1], arguments: val[2], type: val[4], directives: val[5], description: val[0] || get_description(val[1]), definition_line: val[1].line, position_source: val[0] || val[1])
395
- }
396
-
397
- field_definition_list_opt:
398
- /* none */ { result = EMPTY_ARRAY }
399
- | LCURLY field_definition_list RCURLY { result = val[1] }
400
-
401
- field_definition_list:
402
- /* none - this is not actually valid but graphql-ruby used to print this */ { result = EMPTY_ARRAY }
403
- | field_definition { result = [val[0]] }
404
- | field_definition_list field_definition { val[0] << val[1] }
405
-
406
- interface_type_definition:
407
- description_opt INTERFACE name implements_opt directives_list_opt field_definition_list_opt {
408
- result = make_node(:InterfaceTypeDefinition, name: val[2], interfaces: val[3], directives: val[4], fields: val[5], description: val[0] || get_description(val[1]), definition_line: val[1].line, position_source: val[0] || val[1])
409
- }
410
-
411
- union_members:
412
- name { result = [make_node(:TypeName, name: val[0], position_source: val[0])]}
413
- | union_members PIPE name { val[0] << make_node(:TypeName, name: val[2], position_source: val[2]) }
414
-
415
- union_type_definition:
416
- description_opt UNION name directives_list_opt EQUALS union_members {
417
- result = make_node(:UnionTypeDefinition, name: val[2], directives: val[3], types: val[5], description: val[0] || get_description(val[1]), definition_line: val[1].line, position_source: val[0] || val[1])
418
- }
419
-
420
- enum_type_definition:
421
- description_opt ENUM name directives_list_opt LCURLY enum_value_definitions RCURLY {
422
- result = make_node(:EnumTypeDefinition, name: val[2], directives: val[3], values: val[5], description: val[0] || get_description(val[1]), definition_line: val[1].line, position_source: val[0] || val[1])
423
- }
424
-
425
- input_object_type_definition:
426
- description_opt INPUT name directives_list_opt LCURLY input_value_definition_list RCURLY {
427
- result = make_node(:InputObjectTypeDefinition, name: val[2], directives: val[3], fields: val[5], description: val[0] || get_description(val[1]), definition_line: val[1].line, position_source: val[0] || val[1])
428
- }
429
-
430
- directive_definition:
431
- description_opt DIRECTIVE DIR_SIGN name arguments_definitions_opt directive_repeatable_opt ON directive_locations {
432
- result = make_node(:DirectiveDefinition, name: val[3], arguments: val[4], locations: val[7], repeatable: !!val[5], description: val[0] || get_description(val[1]), definition_line: val[1].line, position_source: val[0] || val[1])
433
- }
434
-
435
- directive_repeatable_opt:
436
- /* nothing */
437
- | REPEATABLE
438
-
439
- directive_locations:
440
- name { result = [make_node(:DirectiveLocation, name: val[0].to_s, position_source: val[0])] }
441
- | directive_locations PIPE name { val[0] << make_node(:DirectiveLocation, name: val[2].to_s, position_source: val[2]) }
442
- end
443
-
444
- ---- header ----
445
-
446
-
447
- ---- inner ----
448
-
449
- EMPTY_ARRAY = [].freeze
450
-
451
- def initialize(query_string, filename:, tracer: Tracing::NullTracer)
452
- raise GraphQL::ParseError.new("No query string was present", nil, nil, query_string) if query_string.nil?
453
- @query_string = query_string
454
- @filename = filename
455
- @tracer = tracer
456
- @reused_next_token = [nil, nil]
457
- end
458
-
459
- def parse_document
460
- @document ||= begin
461
- # Break the string into tokens
462
- @tracer.trace("lex", {query_string: @query_string}) do
463
- @tokens ||= GraphQL.scan(@query_string)
464
- end
465
- # From the tokens, build an AST
466
- @tracer.trace("parse", {query_string: @query_string}) do
467
- if @tokens.empty?
468
- raise GraphQL::ParseError.new("Unexpected end of document", nil, nil, @query_string)
469
- else
470
- do_parse
471
- end
472
- end
473
- end
474
- end
475
-
476
- class << self
477
- attr_accessor :cache
478
-
479
- def parse(query_string, filename: nil, tracer: GraphQL::Tracing::NullTracer)
480
- new(query_string, filename: filename, tracer: tracer).parse_document
481
- end
482
-
483
- def parse_file(filename, tracer: GraphQL::Tracing::NullTracer)
484
- if cache
485
- cache.fetch(filename) do
486
- parse(File.read(filename), filename: filename, tracer: tracer)
487
- end
488
- else
489
- parse(File.read(filename), filename: filename, tracer: tracer)
490
- end
491
- end
492
- end
493
-
494
- private
495
-
496
- def next_token
497
- lexer_token = @tokens.shift
498
- if lexer_token.nil?
499
- nil
500
- else
501
- @reused_next_token[0] = lexer_token.name
502
- @reused_next_token[1] = lexer_token
503
- @reused_next_token
504
- end
505
- end
506
-
507
- def get_description(token)
508
- comments = []
509
-
510
- loop do
511
- prev_token = token
512
- token = token.prev_token
513
-
514
- break if token.nil?
515
- break if token.name != :COMMENT
516
- break if prev_token.line != token.line + 1
517
-
518
- comments.unshift(token.to_s.sub(/^#\s*/, ""))
519
- end
520
-
521
- return nil if comments.empty?
522
-
523
- comments.join("\n")
524
- end
525
-
526
- def on_error(parser_token_id, lexer_token, vstack)
527
- if lexer_token == "$" || lexer_token == nil
528
- raise GraphQL::ParseError.new("Unexpected end of document", nil, nil, @query_string, filename: @filename)
529
- else
530
- parser_token_name = token_to_str(parser_token_id)
531
- if parser_token_name.nil?
532
- raise GraphQL::ParseError.new("Parse Error on unknown token: {token_id: #{parser_token_id}, lexer_token: #{lexer_token}} from #{@query_string}", nil, nil, @query_string, filename: @filename)
533
- else
534
- line, col = lexer_token.line_and_column
535
- if lexer_token.name == :BAD_UNICODE_ESCAPE
536
- raise GraphQL::ParseError.new("Parse error on bad Unicode escape sequence: #{lexer_token.to_s.inspect} (#{parser_token_name}) at [#{line}, #{col}]", line, col, @query_string, filename: @filename)
537
- else
538
- raise GraphQL::ParseError.new("Parse error on #{lexer_token.to_s.inspect} (#{parser_token_name}) at [#{line}, #{col}]", line, col, @query_string, filename: @filename)
539
- end
540
- end
541
- end
542
- end
543
-
544
- def make_node(node_name, assigns)
545
- assigns.each do |key, value|
546
- if key != :position_source && value.is_a?(GraphQL::Language::Token)
547
- assigns[key] = value.to_s
548
- end
549
- end
550
-
551
- assigns[:filename] = @filename
552
-
553
- GraphQL::Language::Nodes.const_get(node_name).new(assigns)
554
- 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,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'base64'
4
-
5
- # backport from ruby v2.5 to v2.2 that has no `padding` things
6
- # @api private
7
- module Base64Bp
8
- extend Base64
9
-
10
- module_function
11
-
12
- def urlsafe_encode64(bin, padding:)
13
- str = strict_encode64(bin)
14
- str.tr!("+/", "-_")
15
- str.delete!("=") unless padding
16
- str
17
- end
18
-
19
- def urlsafe_decode64(str)
20
- str = str.tr("-_", "+/")
21
- if !str.end_with?("=") && str.length % 4 != 0
22
- str = str.ljust((str.length + 3) & ~3, "=")
23
- end
24
- strict_decode64(str)
25
- end
26
- 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