graphql 1.13.12 → 2.0.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (273) hide show
  1. checksums.yaml +4 -4
  2. data/lib/generators/graphql/install_generator.rb +1 -1
  3. data/lib/generators/graphql/relay.rb +3 -17
  4. data/lib/generators/graphql/templates/schema.erb +3 -0
  5. data/lib/graphql/analysis/ast/field_usage.rb +3 -1
  6. data/lib/graphql/analysis/ast/max_query_complexity.rb +0 -1
  7. data/lib/graphql/analysis/ast/query_complexity.rb +1 -1
  8. data/lib/graphql/analysis/ast/query_depth.rb +0 -1
  9. data/lib/graphql/analysis/ast/visitor.rb +43 -36
  10. data/lib/graphql/analysis/ast.rb +2 -12
  11. data/lib/graphql/analysis.rb +0 -7
  12. data/lib/graphql/backtrace/table.rb +2 -20
  13. data/lib/graphql/backtrace/trace.rb +96 -0
  14. data/lib/graphql/backtrace/tracer.rb +2 -3
  15. data/lib/graphql/backtrace.rb +7 -8
  16. data/lib/graphql/dataloader/null_dataloader.rb +3 -1
  17. data/lib/graphql/dataloader/source.rb +9 -0
  18. data/lib/graphql/dataloader.rb +4 -1
  19. data/lib/graphql/dig.rb +1 -1
  20. data/lib/graphql/execution/errors.rb +12 -82
  21. data/lib/graphql/execution/interpreter/arguments.rb +1 -1
  22. data/lib/graphql/execution/interpreter/arguments_cache.rb +2 -3
  23. data/lib/graphql/execution/interpreter/resolve.rb +26 -0
  24. data/lib/graphql/execution/interpreter/runtime.rb +300 -222
  25. data/lib/graphql/execution/interpreter.rb +187 -78
  26. data/lib/graphql/execution/lazy.rb +7 -21
  27. data/lib/graphql/execution/lookahead.rb +44 -40
  28. data/lib/graphql/execution/multiplex.rb +3 -174
  29. data/lib/graphql/execution.rb +11 -4
  30. data/lib/graphql/filter.rb +7 -2
  31. data/lib/graphql/introspection/directive_type.rb +2 -2
  32. data/lib/graphql/introspection/dynamic_fields.rb +3 -8
  33. data/lib/graphql/introspection/entry_points.rb +2 -15
  34. data/lib/graphql/introspection/field_type.rb +1 -1
  35. data/lib/graphql/introspection/schema_type.rb +2 -2
  36. data/lib/graphql/introspection/type_type.rb +13 -6
  37. data/lib/graphql/introspection.rb +4 -3
  38. data/lib/graphql/language/document_from_schema_definition.rb +43 -44
  39. data/lib/graphql/language/lexer.rb +216 -1488
  40. data/lib/graphql/language/nodes.rb +66 -40
  41. data/lib/graphql/language/parser.rb +539 -510
  42. data/lib/graphql/language/parser.y +53 -44
  43. data/lib/graphql/language/printer.rb +37 -21
  44. data/lib/graphql/language/visitor.rb +191 -83
  45. data/lib/graphql/pagination/active_record_relation_connection.rb +0 -8
  46. data/lib/graphql/pagination/array_connection.rb +4 -2
  47. data/lib/graphql/pagination/connection.rb +33 -6
  48. data/lib/graphql/pagination/connections.rb +3 -28
  49. data/lib/graphql/pagination/relation_connection.rb +2 -0
  50. data/lib/graphql/query/context.rb +156 -196
  51. data/lib/graphql/query/input_validation_result.rb +10 -1
  52. data/lib/graphql/query/null_context.rb +1 -4
  53. data/lib/graphql/query/validation_pipeline.rb +12 -37
  54. data/lib/graphql/query/variable_validation_error.rb +2 -2
  55. data/lib/graphql/query/variables.rb +35 -21
  56. data/lib/graphql/query.rb +39 -46
  57. data/lib/graphql/railtie.rb +0 -104
  58. data/lib/graphql/rake_task/validate.rb +1 -1
  59. data/lib/graphql/rake_task.rb +29 -1
  60. data/lib/graphql/relay/range_add.rb +9 -20
  61. data/lib/graphql/relay.rb +0 -15
  62. data/lib/graphql/schema/addition.rb +7 -9
  63. data/lib/graphql/schema/argument.rb +38 -47
  64. data/lib/graphql/schema/build_from_definition.rb +47 -21
  65. data/lib/graphql/schema/directive/one_of.rb +12 -0
  66. data/lib/graphql/schema/directive/transform.rb +1 -1
  67. data/lib/graphql/schema/directive.rb +12 -23
  68. data/lib/graphql/schema/enum.rb +29 -41
  69. data/lib/graphql/schema/enum_value.rb +2 -25
  70. data/lib/graphql/schema/field/connection_extension.rb +4 -0
  71. data/lib/graphql/schema/field.rb +256 -349
  72. data/lib/graphql/schema/field_extension.rb +1 -4
  73. data/lib/graphql/schema/find_inherited_value.rb +2 -7
  74. data/lib/graphql/schema/input_object.rb +57 -69
  75. data/lib/graphql/schema/interface.rb +0 -35
  76. data/lib/graphql/schema/introspection_system.rb +3 -8
  77. data/lib/graphql/schema/late_bound_type.rb +8 -2
  78. data/lib/graphql/schema/list.rb +18 -9
  79. data/lib/graphql/schema/loader.rb +1 -2
  80. data/lib/graphql/schema/member/base_dsl_methods.rb +17 -19
  81. data/lib/graphql/schema/member/build_type.rb +5 -7
  82. data/lib/graphql/schema/member/has_arguments.rb +147 -56
  83. data/lib/graphql/schema/member/has_ast_node.rb +12 -0
  84. data/lib/graphql/schema/member/has_deprecation_reason.rb +3 -4
  85. data/lib/graphql/schema/member/has_directives.rb +81 -61
  86. data/lib/graphql/schema/member/has_fields.rb +97 -40
  87. data/lib/graphql/schema/member/has_interfaces.rb +49 -10
  88. data/lib/graphql/schema/member/has_validators.rb +32 -6
  89. data/lib/graphql/schema/member/relay_shortcuts.rb +47 -2
  90. data/lib/graphql/schema/member/type_system_helpers.rb +17 -0
  91. data/lib/graphql/schema/member/validates_input.rb +3 -3
  92. data/lib/graphql/schema/member.rb +0 -6
  93. data/lib/graphql/schema/mutation.rb +0 -9
  94. data/lib/graphql/schema/non_null.rb +3 -9
  95. data/lib/graphql/schema/object.rb +15 -52
  96. data/lib/graphql/schema/relay_classic_mutation.rb +53 -42
  97. data/lib/graphql/schema/resolver/has_payload_type.rb +20 -10
  98. data/lib/graphql/schema/resolver.rb +43 -44
  99. data/lib/graphql/schema/scalar.rb +8 -23
  100. data/lib/graphql/schema/subscription.rb +0 -7
  101. data/lib/graphql/schema/timeout.rb +24 -28
  102. data/lib/graphql/schema/type_membership.rb +3 -0
  103. data/lib/graphql/schema/union.rb +10 -17
  104. data/lib/graphql/schema/validator.rb +1 -1
  105. data/lib/graphql/schema/warden.rb +37 -9
  106. data/lib/graphql/schema/wrapper.rb +0 -5
  107. data/lib/graphql/schema.rb +265 -968
  108. data/lib/graphql/static_validation/all_rules.rb +1 -0
  109. data/lib/graphql/static_validation/base_visitor.rb +4 -21
  110. data/lib/graphql/static_validation/definition_dependencies.rb +7 -1
  111. data/lib/graphql/static_validation/error.rb +2 -2
  112. data/lib/graphql/static_validation/literal_validator.rb +19 -1
  113. data/lib/graphql/static_validation/rules/directives_are_defined.rb +11 -5
  114. data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +12 -12
  115. data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +12 -4
  116. data/lib/graphql/static_validation/rules/fields_will_merge.rb +2 -2
  117. data/lib/graphql/static_validation/rules/one_of_input_objects_are_valid.rb +66 -0
  118. data/lib/graphql/static_validation/rules/one_of_input_objects_are_valid_error.rb +29 -0
  119. data/lib/graphql/static_validation/rules/unique_directives_per_location.rb +12 -6
  120. data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +1 -1
  121. data/lib/graphql/static_validation/validator.rb +3 -25
  122. data/lib/graphql/static_validation.rb +0 -2
  123. data/lib/graphql/subscriptions/action_cable_subscriptions.rb +7 -1
  124. data/lib/graphql/subscriptions/default_subscription_resolve_extension.rb +38 -1
  125. data/lib/graphql/subscriptions/event.rb +3 -8
  126. data/lib/graphql/subscriptions/instrumentation.rb +0 -51
  127. data/lib/graphql/subscriptions.rb +32 -20
  128. data/lib/graphql/tracing/active_support_notifications_trace.rb +16 -0
  129. data/lib/graphql/tracing/appoptics_trace.rb +231 -0
  130. data/lib/graphql/tracing/appsignal_trace.rb +77 -0
  131. data/lib/graphql/tracing/data_dog_trace.rb +148 -0
  132. data/lib/graphql/tracing/data_dog_tracing.rb +21 -2
  133. data/lib/graphql/tracing/legacy_trace.rb +65 -0
  134. data/lib/graphql/tracing/new_relic_trace.rb +75 -0
  135. data/lib/graphql/tracing/notifications_trace.rb +42 -0
  136. data/lib/graphql/tracing/platform_trace.rb +109 -0
  137. data/lib/graphql/tracing/platform_tracing.rb +33 -43
  138. data/lib/graphql/tracing/prometheus_trace.rb +89 -0
  139. data/lib/graphql/tracing/prometheus_tracing/graphql_collector.rb +1 -1
  140. data/lib/graphql/tracing/prometheus_tracing.rb +3 -3
  141. data/lib/graphql/tracing/scout_trace.rb +72 -0
  142. data/lib/graphql/tracing/statsd_trace.rb +56 -0
  143. data/lib/graphql/tracing/trace.rb +75 -0
  144. data/lib/graphql/tracing.rb +16 -40
  145. data/lib/graphql/type_kinds.rb +6 -3
  146. data/lib/graphql/types/iso_8601_date.rb +4 -1
  147. data/lib/graphql/types/iso_8601_date_time.rb +4 -0
  148. data/lib/graphql/types/relay/base_connection.rb +16 -6
  149. data/lib/graphql/types/relay/connection_behaviors.rb +29 -27
  150. data/lib/graphql/types/relay/edge_behaviors.rb +16 -5
  151. data/lib/graphql/types/relay/node_behaviors.rb +12 -2
  152. data/lib/graphql/types/relay/page_info_behaviors.rb +7 -2
  153. data/lib/graphql/types/relay.rb +0 -3
  154. data/lib/graphql/types/string.rb +1 -1
  155. data/lib/graphql/version.rb +1 -1
  156. data/lib/graphql.rb +17 -74
  157. metadata +33 -133
  158. data/lib/graphql/analysis/analyze_query.rb +0 -98
  159. data/lib/graphql/analysis/field_usage.rb +0 -45
  160. data/lib/graphql/analysis/max_query_complexity.rb +0 -26
  161. data/lib/graphql/analysis/max_query_depth.rb +0 -26
  162. data/lib/graphql/analysis/query_complexity.rb +0 -88
  163. data/lib/graphql/analysis/query_depth.rb +0 -43
  164. data/lib/graphql/analysis/reducer_state.rb +0 -48
  165. data/lib/graphql/argument.rb +0 -131
  166. data/lib/graphql/authorization.rb +0 -82
  167. data/lib/graphql/backtrace/legacy_tracer.rb +0 -56
  168. data/lib/graphql/backwards_compatibility.rb +0 -61
  169. data/lib/graphql/base_type.rb +0 -232
  170. data/lib/graphql/boolean_type.rb +0 -2
  171. data/lib/graphql/compatibility/execution_specification/counter_schema.rb +0 -53
  172. data/lib/graphql/compatibility/execution_specification/specification_schema.rb +0 -200
  173. data/lib/graphql/compatibility/execution_specification.rb +0 -436
  174. data/lib/graphql/compatibility/lazy_execution_specification/lazy_schema.rb +0 -111
  175. data/lib/graphql/compatibility/lazy_execution_specification.rb +0 -215
  176. data/lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb +0 -87
  177. data/lib/graphql/compatibility/query_parser_specification/query_assertions.rb +0 -79
  178. data/lib/graphql/compatibility/query_parser_specification.rb +0 -266
  179. data/lib/graphql/compatibility/schema_parser_specification.rb +0 -682
  180. data/lib/graphql/compatibility.rb +0 -5
  181. data/lib/graphql/define/assign_argument.rb +0 -12
  182. data/lib/graphql/define/assign_connection.rb +0 -13
  183. data/lib/graphql/define/assign_enum_value.rb +0 -18
  184. data/lib/graphql/define/assign_global_id_field.rb +0 -11
  185. data/lib/graphql/define/assign_mutation_function.rb +0 -34
  186. data/lib/graphql/define/assign_object_field.rb +0 -42
  187. data/lib/graphql/define/defined_object_proxy.rb +0 -53
  188. data/lib/graphql/define/instance_definable.rb +0 -255
  189. data/lib/graphql/define/no_definition_error.rb +0 -7
  190. data/lib/graphql/define/non_null_with_bang.rb +0 -16
  191. data/lib/graphql/define/type_definer.rb +0 -31
  192. data/lib/graphql/define.rb +0 -31
  193. data/lib/graphql/deprecated_dsl.rb +0 -55
  194. data/lib/graphql/directive/deprecated_directive.rb +0 -2
  195. data/lib/graphql/directive/include_directive.rb +0 -2
  196. data/lib/graphql/directive/skip_directive.rb +0 -2
  197. data/lib/graphql/directive.rb +0 -107
  198. data/lib/graphql/enum_type.rb +0 -133
  199. data/lib/graphql/execution/execute.rb +0 -333
  200. data/lib/graphql/execution/flatten.rb +0 -40
  201. data/lib/graphql/execution/instrumentation.rb +0 -92
  202. data/lib/graphql/execution/lazy/resolve.rb +0 -91
  203. data/lib/graphql/execution/typecast.rb +0 -50
  204. data/lib/graphql/field/resolve.rb +0 -59
  205. data/lib/graphql/field.rb +0 -226
  206. data/lib/graphql/float_type.rb +0 -2
  207. data/lib/graphql/function.rb +0 -128
  208. data/lib/graphql/id_type.rb +0 -2
  209. data/lib/graphql/input_object_type.rb +0 -138
  210. data/lib/graphql/int_type.rb +0 -2
  211. data/lib/graphql/interface_type.rb +0 -72
  212. data/lib/graphql/internal_representation/document.rb +0 -27
  213. data/lib/graphql/internal_representation/node.rb +0 -206
  214. data/lib/graphql/internal_representation/print.rb +0 -51
  215. data/lib/graphql/internal_representation/rewrite.rb +0 -184
  216. data/lib/graphql/internal_representation/scope.rb +0 -88
  217. data/lib/graphql/internal_representation/visit.rb +0 -36
  218. data/lib/graphql/internal_representation.rb +0 -7
  219. data/lib/graphql/language/lexer.rl +0 -260
  220. data/lib/graphql/list_type.rb +0 -80
  221. data/lib/graphql/non_null_type.rb +0 -71
  222. data/lib/graphql/object_type.rb +0 -130
  223. data/lib/graphql/query/arguments.rb +0 -189
  224. data/lib/graphql/query/arguments_cache.rb +0 -24
  225. data/lib/graphql/query/executor.rb +0 -52
  226. data/lib/graphql/query/literal_input.rb +0 -136
  227. data/lib/graphql/query/serial_execution/field_resolution.rb +0 -92
  228. data/lib/graphql/query/serial_execution/operation_resolution.rb +0 -19
  229. data/lib/graphql/query/serial_execution/selection_resolution.rb +0 -23
  230. data/lib/graphql/query/serial_execution/value_resolution.rb +0 -87
  231. data/lib/graphql/query/serial_execution.rb +0 -40
  232. data/lib/graphql/relay/array_connection.rb +0 -83
  233. data/lib/graphql/relay/base_connection.rb +0 -189
  234. data/lib/graphql/relay/connection_instrumentation.rb +0 -54
  235. data/lib/graphql/relay/connection_resolve.rb +0 -43
  236. data/lib/graphql/relay/connection_type.rb +0 -54
  237. data/lib/graphql/relay/edge.rb +0 -27
  238. data/lib/graphql/relay/edge_type.rb +0 -19
  239. data/lib/graphql/relay/edges_instrumentation.rb +0 -39
  240. data/lib/graphql/relay/global_id_resolve.rb +0 -17
  241. data/lib/graphql/relay/mongo_relation_connection.rb +0 -50
  242. data/lib/graphql/relay/mutation/instrumentation.rb +0 -23
  243. data/lib/graphql/relay/mutation/resolve.rb +0 -56
  244. data/lib/graphql/relay/mutation/result.rb +0 -38
  245. data/lib/graphql/relay/mutation.rb +0 -106
  246. data/lib/graphql/relay/node.rb +0 -39
  247. data/lib/graphql/relay/page_info.rb +0 -7
  248. data/lib/graphql/relay/relation_connection.rb +0 -188
  249. data/lib/graphql/relay/type_extensions.rb +0 -32
  250. data/lib/graphql/scalar_type.rb +0 -91
  251. data/lib/graphql/schema/catchall_middleware.rb +0 -35
  252. data/lib/graphql/schema/default_parse_error.rb +0 -10
  253. data/lib/graphql/schema/default_type_error.rb +0 -17
  254. data/lib/graphql/schema/member/accepts_definition.rb +0 -164
  255. data/lib/graphql/schema/member/cached_graphql_definition.rb +0 -58
  256. data/lib/graphql/schema/member/instrumentation.rb +0 -131
  257. data/lib/graphql/schema/middleware_chain.rb +0 -82
  258. data/lib/graphql/schema/possible_types.rb +0 -44
  259. data/lib/graphql/schema/rescue_middleware.rb +0 -60
  260. data/lib/graphql/schema/timeout_middleware.rb +0 -88
  261. data/lib/graphql/schema/traversal.rb +0 -228
  262. data/lib/graphql/schema/validation.rb +0 -313
  263. data/lib/graphql/static_validation/default_visitor.rb +0 -15
  264. data/lib/graphql/static_validation/no_validate_visitor.rb +0 -10
  265. data/lib/graphql/string_type.rb +0 -2
  266. data/lib/graphql/subscriptions/subscription_root.rb +0 -76
  267. data/lib/graphql/tracing/skylight_tracing.rb +0 -70
  268. data/lib/graphql/types/relay/default_relay.rb +0 -31
  269. data/lib/graphql/types/relay/node_field.rb +0 -24
  270. data/lib/graphql/types/relay/nodes_field.rb +0 -43
  271. data/lib/graphql/union_type.rb +0 -115
  272. data/lib/graphql/upgrader/member.rb +0 -937
  273. data/lib/graphql/upgrader/schema.rb +0 -38
@@ -1,682 +0,0 @@
1
- # frozen_string_literal: true
2
- module GraphQL
3
- module Compatibility
4
- # This asserts that a given parse function turns a string into
5
- # the proper tree of {{GraphQL::Language::Nodes}}.
6
- module SchemaParserSpecification
7
- # @yieldparam query_string [String] A query string to parse
8
- # @yieldreturn [GraphQL::Language::Nodes::Document]
9
- # @return [Class<Minitest::Test>] A test suite for this parse function
10
- def self.build_suite(&block)
11
- GraphQL::Deprecation.warn "#{self} will be removed from GraphQL-Ruby 2.0. There is no replacement, please open an issue on GitHub if you need support."
12
-
13
- Class.new(Minitest::Test) do
14
- @@parse_fn = block
15
-
16
- def parse(query_string)
17
- @@parse_fn.call(query_string)
18
- end
19
-
20
- def test_it_parses_object_types
21
- document = parse('
22
- # This is what
23
- # somebody said about something
24
- type Comment implements Node @deprecated(reason: "No longer supported") {
25
- id: ID!
26
- }
27
- ')
28
-
29
- type = document.definitions.first
30
- assert_equal GraphQL::Language::Nodes::ObjectTypeDefinition, type.class
31
- assert_equal 'Comment', type.name
32
- assert_equal "This is what\nsomebody said about something", type.description
33
- assert_equal ['Node'], type.interfaces.map(&:name)
34
- assert_equal ['id'], type.fields.map(&:name)
35
- assert_equal [], type.fields[0].arguments
36
- assert_equal 'ID', type.fields[0].type.of_type.name
37
- assert_equal 1, type.directives.length
38
-
39
- deprecated_directive = type.directives[0]
40
- assert_equal 'deprecated', deprecated_directive.name
41
- assert_equal 'reason', deprecated_directive.arguments[0].name
42
- assert_equal 'No longer supported', deprecated_directive.arguments[0].value
43
- end
44
-
45
- def test_it_parses_scalars
46
- document = parse('scalar DateTime')
47
-
48
- type = document.definitions.first
49
- assert_equal GraphQL::Language::Nodes::ScalarTypeDefinition, type.class
50
- assert_equal 'DateTime', type.name
51
- end
52
-
53
- def test_it_parses_enum_types
54
- document = parse('
55
- enum DogCommand {
56
- # Good dog
57
- SIT
58
- DOWN @deprecated(reason: "No longer supported")
59
- HEEL
60
- }
61
- ')
62
-
63
- type = document.definitions.first
64
- assert_equal GraphQL::Language::Nodes::EnumTypeDefinition, type.class
65
- assert_equal 'DogCommand', type.name
66
- assert_equal 3, type.values.length
67
-
68
- assert_equal 'SIT', type.values[0].name
69
- assert_equal [], type.values[0].directives
70
- assert_equal "Good dog", type.values[0].description
71
-
72
- assert_equal 'DOWN', type.values[1].name
73
- assert_equal 1, type.values[1].directives.length
74
- deprecated_directive = type.values[1].directives[0]
75
- assert_equal 'deprecated', deprecated_directive.name
76
- assert_equal 'reason', deprecated_directive.arguments[0].name
77
- assert_equal 'No longer supported', deprecated_directive.arguments[0].value
78
-
79
- assert_equal 'HEEL', type.values[2].name
80
- assert_equal [], type.values[2].directives
81
- end
82
-
83
- def test_it_parses_union_types
84
- document = parse(
85
- "union BagOfThings = \n" \
86
- "A |\n" \
87
- "B |\n" \
88
- "C"
89
- )
90
-
91
- union = document.definitions.first
92
-
93
- assert_equal GraphQL::Language::Nodes::UnionTypeDefinition, union.class
94
- assert_equal 'BagOfThings', union.name
95
- assert_equal 3, union.types.length
96
- assert_equal [1, 1], union.position
97
-
98
- assert_equal GraphQL::Language::Nodes::TypeName, union.types[0].class
99
- assert_equal 'A', union.types[0].name
100
- assert_equal [2, 1], union.types[0].position
101
-
102
- assert_equal GraphQL::Language::Nodes::TypeName, union.types[1].class
103
- assert_equal 'B', union.types[1].name
104
- assert_equal [3, 1], union.types[1].position
105
-
106
- assert_equal GraphQL::Language::Nodes::TypeName, union.types[2].class
107
- assert_equal 'C', union.types[2].name
108
- assert_equal [4, 1], union.types[2].position
109
- end
110
-
111
- def test_it_parses_input_types
112
- document = parse('
113
- input EmptyMutationInput {
114
- clientMutationId: String
115
- }
116
- ')
117
-
118
- type = document.definitions.first
119
- assert_equal GraphQL::Language::Nodes::InputObjectTypeDefinition, type.class
120
- assert_equal 'EmptyMutationInput', type.name
121
- assert_equal ['clientMutationId'], type.fields.map(&:name)
122
- assert_equal 'String', type.fields[0].type.name
123
- assert_equal nil, type.fields[0].default_value
124
- end
125
-
126
- def test_it_parses_directives
127
- document = parse('
128
- directive @include(if: Boolean!)
129
- on FIELD
130
- | FRAGMENT_SPREAD
131
- | INLINE_FRAGMENT
132
- ')
133
-
134
- type = document.definitions.first
135
- assert_equal GraphQL::Language::Nodes::DirectiveDefinition, type.class
136
- assert_equal 'include', type.name
137
-
138
- assert_equal 1, type.arguments.length
139
- assert_equal 'if', type.arguments[0].name
140
- assert_equal 'Boolean', type.arguments[0].type.of_type.name
141
-
142
- assert_equal 3, type.locations.length
143
-
144
- assert_instance_of GraphQL::Language::Nodes::DirectiveLocation, type.locations[0]
145
- assert_equal 'FIELD', type.locations[0].name
146
- assert_equal [3, 20], type.locations[0].position
147
-
148
- assert_instance_of GraphQL::Language::Nodes::DirectiveLocation, type.locations[1]
149
- assert_equal 'FRAGMENT_SPREAD', type.locations[1].name
150
- assert_equal [4, 19], type.locations[1].position
151
-
152
- assert_instance_of GraphQL::Language::Nodes::DirectiveLocation, type.locations[2]
153
- assert_equal 'INLINE_FRAGMENT', type.locations[2].name
154
- assert_equal [5, 19], type.locations[2].position
155
- end
156
-
157
- def test_it_parses_field_arguments
158
- document = parse('
159
- type Mutation {
160
- post(
161
- id: ID! @deprecated(reason: "Not used"),
162
- # This is what goes in the post
163
- data: String
164
- ): Post
165
- }
166
- ')
167
-
168
- field = document.definitions.first.fields.first
169
- assert_equal ['id', 'data'], field.arguments.map(&:name)
170
- id_arg = field.arguments[0]
171
-
172
- deprecated_directive = id_arg.directives[0]
173
- assert_equal 'deprecated', deprecated_directive.name
174
- assert_equal 'reason', deprecated_directive.arguments[0].name
175
- assert_equal 'Not used', deprecated_directive.arguments[0].value
176
-
177
- data_arg = field.arguments[1]
178
- assert_equal "data", data_arg.name
179
- assert_equal "This is what goes in the post", data_arg.description
180
- end
181
-
182
- def test_it_parses_schema_definition
183
- document = parse('
184
- schema {
185
- query: QueryRoot
186
- mutation: MutationRoot
187
- subscription: SubscriptionRoot
188
- }
189
- ')
190
-
191
- schema = document.definitions.first
192
- assert_equal 'QueryRoot', schema.query
193
- assert_equal 'MutationRoot', schema.mutation
194
- assert_equal 'SubscriptionRoot', schema.subscription
195
- end
196
-
197
- def test_it_parses_schema_extensions
198
- document = parse('
199
- extend schema {
200
- query: QueryRoot
201
- mutation: MutationRoot
202
- subscription: SubscriptionRoot
203
- }
204
- ')
205
-
206
- schema_extension = document.definitions.first
207
- assert_equal GraphQL::Language::Nodes::SchemaExtension, schema_extension.class
208
- assert_equal [2, 15], schema_extension.position
209
-
210
- assert_equal 'QueryRoot', schema_extension.query
211
- assert_equal 'MutationRoot', schema_extension.mutation
212
- assert_equal 'SubscriptionRoot', schema_extension.subscription
213
- end
214
-
215
- def test_it_parses_schema_extensions_with_directives
216
- document = parse('
217
- extend schema @something {
218
- query: QueryRoot
219
- }
220
- ')
221
-
222
- schema_extension = document.definitions.first
223
- assert_equal GraphQL::Language::Nodes::SchemaExtension, schema_extension.class
224
-
225
- assert_equal 1, schema_extension.directives.length
226
- assert_equal GraphQL::Language::Nodes::Directive, schema_extension.directives.first.class
227
- assert_equal 'something', schema_extension.directives.first.name
228
-
229
- assert_equal 'QueryRoot', schema_extension.query
230
- assert_equal nil, schema_extension.mutation
231
- assert_equal nil, schema_extension.subscription
232
- end
233
-
234
- def test_it_parses_schema_extensions_with_only_directives
235
- document = parse('
236
- extend schema @something
237
- ')
238
-
239
- schema_extension = document.definitions.first
240
- assert_equal GraphQL::Language::Nodes::SchemaExtension, schema_extension.class
241
-
242
- assert_equal 1, schema_extension.directives.length
243
- assert_equal GraphQL::Language::Nodes::Directive, schema_extension.directives.first.class
244
- assert_equal 'something', schema_extension.directives.first.name
245
-
246
- assert_equal nil, schema_extension.query
247
- assert_equal nil, schema_extension.mutation
248
- assert_equal nil, schema_extension.subscription
249
- end
250
-
251
- def test_it_parses_scalar_extensions
252
- document = parse('
253
- extend scalar Date @something @somethingElse
254
- ')
255
-
256
- scalar_extension = document.definitions.first
257
- assert_equal GraphQL::Language::Nodes::ScalarTypeExtension, scalar_extension.class
258
- assert_equal 'Date', scalar_extension.name
259
- assert_equal [2, 15], scalar_extension.position
260
-
261
- assert_equal 2, scalar_extension.directives.length
262
- assert_equal GraphQL::Language::Nodes::Directive, scalar_extension.directives.first.class
263
- assert_equal 'something', scalar_extension.directives.first.name
264
- assert_equal GraphQL::Language::Nodes::Directive, scalar_extension.directives.last.class
265
- assert_equal 'somethingElse', scalar_extension.directives.last.name
266
- end
267
-
268
- def test_it_parses_object_type_extensions_with_field_definitions
269
- document = parse('
270
- extend type User {
271
- login: String!
272
- }
273
- ')
274
-
275
- object_type_extension = document.definitions.first
276
- assert_equal GraphQL::Language::Nodes::ObjectTypeExtension, object_type_extension.class
277
- assert_equal 'User', object_type_extension.name
278
- assert_equal [2, 15], object_type_extension.position
279
-
280
- assert_equal 1, object_type_extension.fields.length
281
- assert_equal GraphQL::Language::Nodes::FieldDefinition, object_type_extension.fields.first.class
282
- end
283
-
284
- def test_it_parses_object_type_extensions_with_field_definitions_and_directives
285
- document = parse('
286
- extend type User @deprecated {
287
- login: String!
288
- }
289
- ')
290
-
291
- object_type_extension = document.definitions.first
292
- assert_equal GraphQL::Language::Nodes::ObjectTypeExtension, object_type_extension.class
293
- assert_equal 'User', object_type_extension.name
294
- assert_equal [2, 15], object_type_extension.position
295
-
296
- assert_equal 1, object_type_extension.fields.length
297
- assert_equal GraphQL::Language::Nodes::FieldDefinition, object_type_extension.fields.first.class
298
-
299
- assert_equal 1, object_type_extension.directives.length
300
- assert_equal GraphQL::Language::Nodes::Directive, object_type_extension.directives.first.class
301
- end
302
-
303
- def test_it_parses_object_type_extensions_with_field_definitions_and_implements
304
- document = parse('
305
- extend type User implements Node {
306
- login: String!
307
- }
308
- ')
309
-
310
- object_type_extension = document.definitions.first
311
- assert_equal GraphQL::Language::Nodes::ObjectTypeExtension, object_type_extension.class
312
- assert_equal 'User', object_type_extension.name
313
- assert_equal [2, 15], object_type_extension.position
314
-
315
- assert_equal 1, object_type_extension.fields.length
316
- assert_equal GraphQL::Language::Nodes::FieldDefinition, object_type_extension.fields.first.class
317
-
318
- assert_equal 1, object_type_extension.interfaces.length
319
- assert_equal GraphQL::Language::Nodes::TypeName, object_type_extension.interfaces.first.class
320
- end
321
-
322
- def test_it_parses_object_type_extensions_with_only_directives
323
- document = parse('
324
- extend type User @deprecated
325
- ')
326
-
327
- object_type_extension = document.definitions.first
328
- assert_equal GraphQL::Language::Nodes::ObjectTypeExtension, object_type_extension.class
329
- assert_equal 'User', object_type_extension.name
330
- assert_equal [2, 15], object_type_extension.position
331
-
332
- assert_equal 1, object_type_extension.directives.length
333
- assert_equal GraphQL::Language::Nodes::Directive, object_type_extension.directives.first.class
334
- assert_equal 'deprecated', object_type_extension.directives.first.name
335
- end
336
-
337
- def test_it_parses_object_type_extensions_with_implements_and_directives
338
- document = parse('
339
- extend type User implements Node @deprecated
340
- ')
341
-
342
- object_type_extension = document.definitions.first
343
- assert_equal GraphQL::Language::Nodes::ObjectTypeExtension, object_type_extension.class
344
- assert_equal 'User', object_type_extension.name
345
- assert_equal [2, 15], object_type_extension.position
346
-
347
- assert_equal 1, object_type_extension.directives.length
348
- assert_equal GraphQL::Language::Nodes::Directive, object_type_extension.directives.first.class
349
- assert_equal 'deprecated', object_type_extension.directives.first.name
350
-
351
- assert_equal 1, object_type_extension.interfaces.length
352
- assert_equal GraphQL::Language::Nodes::TypeName, object_type_extension.interfaces.first.class
353
- assert_equal 'Node', object_type_extension.interfaces.first.name
354
- end
355
-
356
- def test_it_parses_object_type_extensions_with_only_implements
357
- document = parse('
358
- extend type User implements Node
359
- ')
360
-
361
- object_type_extension = document.definitions.first
362
- assert_equal GraphQL::Language::Nodes::ObjectTypeExtension, object_type_extension.class
363
- assert_equal 'User', object_type_extension.name
364
- assert_equal [2, 15], object_type_extension.position
365
-
366
- assert_equal 1, object_type_extension.interfaces.length
367
- assert_equal GraphQL::Language::Nodes::TypeName, object_type_extension.interfaces.first.class
368
- assert_equal 'Node', object_type_extension.interfaces.first.name
369
- end
370
-
371
- def test_it_parses_interface_type_extensions_with_directives_and_fields
372
- document = parse('
373
- extend interface Node @directive {
374
- field: String
375
- }
376
- ')
377
-
378
- interface_type_extension = document.definitions.first
379
- assert_equal GraphQL::Language::Nodes::InterfaceTypeExtension, interface_type_extension.class
380
- assert_equal 'Node', interface_type_extension.name
381
- assert_equal [2, 15], interface_type_extension.position
382
-
383
- assert_equal 1, interface_type_extension.directives.length
384
- assert_equal GraphQL::Language::Nodes::Directive, interface_type_extension.directives.first.class
385
- assert_equal 'directive', interface_type_extension.directives.first.name
386
-
387
- assert_equal 1, interface_type_extension.fields.length
388
- assert_equal GraphQL::Language::Nodes::FieldDefinition, interface_type_extension.fields.first.class
389
- assert_equal 'field', interface_type_extension.fields.first.name
390
- end
391
-
392
- def test_it_parses_interface_type_extensions_with_fields
393
- document = parse('
394
- extend interface Node {
395
- field: String
396
- }
397
- ')
398
-
399
- interface_type_extension = document.definitions.first
400
- assert_equal GraphQL::Language::Nodes::InterfaceTypeExtension, interface_type_extension.class
401
- assert_equal 'Node', interface_type_extension.name
402
- assert_equal [2, 15], interface_type_extension.position
403
-
404
- assert_equal 0, interface_type_extension.directives.length
405
-
406
- assert_equal 1, interface_type_extension.fields.length
407
- assert_equal GraphQL::Language::Nodes::FieldDefinition, interface_type_extension.fields.first.class
408
- assert_equal 'field', interface_type_extension.fields.first.name
409
- end
410
-
411
- def test_it_parses_interface_type_extensions_with_directives
412
- document = parse('
413
- extend interface Node @directive
414
- ')
415
-
416
- interface_type_extension = document.definitions.first
417
- assert_equal GraphQL::Language::Nodes::InterfaceTypeExtension, interface_type_extension.class
418
- assert_equal 'Node', interface_type_extension.name
419
- assert_equal [2, 15], interface_type_extension.position
420
-
421
- assert_equal 1, interface_type_extension.directives.length
422
- assert_equal GraphQL::Language::Nodes::Directive, interface_type_extension.directives.first.class
423
- assert_equal 'directive', interface_type_extension.directives.first.name
424
- end
425
-
426
- def test_it_parses_union_type_extension_with_union_members
427
- document = parse('
428
- extend union BagOfThings = A | B
429
- ')
430
-
431
- union_type_extension = document.definitions.first
432
- assert_equal GraphQL::Language::Nodes::UnionTypeExtension, union_type_extension.class
433
- assert_equal 'BagOfThings', union_type_extension.name
434
- assert_equal [2, 15], union_type_extension.position
435
-
436
- assert_equal 0, union_type_extension.directives.length
437
-
438
- assert_equal 2, union_type_extension.types.length
439
- assert_equal GraphQL::Language::Nodes::TypeName, union_type_extension.types.first.class
440
- assert_equal 'A', union_type_extension.types.first.name
441
- end
442
-
443
- def test_it_parses_union_type_extension_with_directives_and_union_members
444
- document = parse('
445
- extend union BagOfThings @directive = A | B
446
- ')
447
-
448
- union_type_extension = document.definitions.first
449
- assert_equal GraphQL::Language::Nodes::UnionTypeExtension, union_type_extension.class
450
- assert_equal 'BagOfThings', union_type_extension.name
451
- assert_equal [2, 15], union_type_extension.position
452
-
453
- assert_equal 1, union_type_extension.directives.length
454
- assert_equal GraphQL::Language::Nodes::Directive, union_type_extension.directives.first.class
455
- assert_equal 'directive', union_type_extension.directives.first.name
456
-
457
- assert_equal 2, union_type_extension.types.length
458
- assert_equal GraphQL::Language::Nodes::TypeName, union_type_extension.types.first.class
459
- assert_equal 'A', union_type_extension.types.first.name
460
- end
461
-
462
- def test_it_parses_union_type_extension_with_directives
463
- document = parse('
464
- extend union BagOfThings @directive
465
- ')
466
-
467
- union_type_extension = document.definitions.first
468
- assert_equal GraphQL::Language::Nodes::UnionTypeExtension, union_type_extension.class
469
- assert_equal 'BagOfThings', union_type_extension.name
470
- assert_equal [2, 15], union_type_extension.position
471
-
472
- assert_equal 1, union_type_extension.directives.length
473
- assert_equal GraphQL::Language::Nodes::Directive, union_type_extension.directives.first.class
474
- assert_equal 'directive', union_type_extension.directives.first.name
475
-
476
- assert_equal 0, union_type_extension.types.length
477
- end
478
-
479
- def test_it_parses_enum_type_extension_with_values
480
- document = parse('
481
- extend enum Status {
482
- DRAFT
483
- PUBLISHED
484
- }
485
- ')
486
-
487
- enum_type_extension = document.definitions.first
488
- assert_equal GraphQL::Language::Nodes::EnumTypeExtension, enum_type_extension.class
489
- assert_equal 'Status', enum_type_extension.name
490
- assert_equal [2, 15], enum_type_extension.position
491
-
492
- assert_equal 0, enum_type_extension.directives.length
493
-
494
- assert_equal 2, enum_type_extension.values.length
495
- assert_equal GraphQL::Language::Nodes::EnumValueDefinition, enum_type_extension.values.first.class
496
- assert_equal 'DRAFT', enum_type_extension.values.first.name
497
- end
498
-
499
- def test_it_parses_enum_type_extension_with_directives_and_values
500
- document = parse('
501
- extend enum Status @directive {
502
- DRAFT
503
- PUBLISHED
504
- }
505
- ')
506
-
507
- enum_type_extension = document.definitions.first
508
- assert_equal GraphQL::Language::Nodes::EnumTypeExtension, enum_type_extension.class
509
- assert_equal 'Status', enum_type_extension.name
510
- assert_equal [2, 15], enum_type_extension.position
511
-
512
- assert_equal 1, enum_type_extension.directives.length
513
- assert_equal GraphQL::Language::Nodes::Directive, enum_type_extension.directives.first.class
514
- assert_equal 'directive', enum_type_extension.directives.first.name
515
-
516
- assert_equal 2, enum_type_extension.values.length
517
- assert_equal GraphQL::Language::Nodes::EnumValueDefinition, enum_type_extension.values.first.class
518
- assert_equal 'DRAFT', enum_type_extension.values.first.name
519
- end
520
-
521
- def test_it_parses_enum_type_extension_with_directives
522
- document = parse('
523
- extend enum Status @directive
524
- ')
525
-
526
- enum_type_extension = document.definitions.first
527
- assert_equal GraphQL::Language::Nodes::EnumTypeExtension, enum_type_extension.class
528
- assert_equal 'Status', enum_type_extension.name
529
- assert_equal [2, 15], enum_type_extension.position
530
-
531
- assert_equal 1, enum_type_extension.directives.length
532
- assert_equal GraphQL::Language::Nodes::Directive, enum_type_extension.directives.first.class
533
- assert_equal 'directive', enum_type_extension.directives.first.name
534
-
535
- assert_equal 0, enum_type_extension.values.length
536
- end
537
-
538
- def test_it_parses_input_object_type_extension_with_fields
539
- document = parse('
540
- extend input UserInput {
541
- login: String!
542
- }
543
- ')
544
-
545
- input_object_type_extension = document.definitions.first
546
- assert_equal GraphQL::Language::Nodes::InputObjectTypeExtension, input_object_type_extension.class
547
- assert_equal 'UserInput', input_object_type_extension.name
548
- assert_equal [2, 15], input_object_type_extension.position
549
-
550
- assert_equal 1, input_object_type_extension.fields.length
551
- assert_equal GraphQL::Language::Nodes::InputValueDefinition, input_object_type_extension.fields.first.class
552
- assert_equal 'login', input_object_type_extension.fields.first.name
553
-
554
- assert_equal 0, input_object_type_extension.directives.length
555
- end
556
-
557
- def test_it_parses_input_object_type_extension_with_directives_and_fields
558
- document = parse('
559
- extend input UserInput @deprecated {
560
- login: String!
561
- }
562
- ')
563
-
564
- input_object_type_extension = document.definitions.first
565
- assert_equal GraphQL::Language::Nodes::InputObjectTypeExtension, input_object_type_extension.class
566
- assert_equal 'UserInput', input_object_type_extension.name
567
- assert_equal [2, 15], input_object_type_extension.position
568
-
569
- assert_equal 1, input_object_type_extension.fields.length
570
- assert_equal GraphQL::Language::Nodes::InputValueDefinition, input_object_type_extension.fields.first.class
571
- assert_equal 'login', input_object_type_extension.fields.first.name
572
-
573
- assert_equal 1, input_object_type_extension.directives.length
574
- assert_equal GraphQL::Language::Nodes::Directive, input_object_type_extension.directives.first.class
575
- assert_equal 'deprecated', input_object_type_extension.directives.first.name
576
- end
577
-
578
- def test_it_parses_input_object_type_extension_with_directives
579
- document = parse('
580
- extend input UserInput @deprecated
581
- ')
582
-
583
- input_object_type_extension = document.definitions.first
584
- assert_equal GraphQL::Language::Nodes::InputObjectTypeExtension, input_object_type_extension.class
585
- assert_equal 'UserInput', input_object_type_extension.name
586
- assert_equal [2, 15], input_object_type_extension.position
587
-
588
- assert_equal 0, input_object_type_extension.fields.length
589
-
590
- assert_equal 1, input_object_type_extension.directives.length
591
- assert_equal GraphQL::Language::Nodes::Directive, input_object_type_extension.directives.first.class
592
- assert_equal 'deprecated', input_object_type_extension.directives.first.name
593
- end
594
-
595
- def test_it_parses_whole_definition_with_descriptions
596
- document = parse(SCHEMA_DEFINITION_STRING)
597
-
598
- assert_equal 6, document.definitions.size
599
-
600
- schema_definition, directive_definition, enum_type_definition, object_type_definition, input_object_type_definition, interface_type_definition = document.definitions
601
-
602
- assert_equal GraphQL::Language::Nodes::SchemaDefinition, schema_definition.class
603
-
604
- assert_equal GraphQL::Language::Nodes::DirectiveDefinition, directive_definition.class
605
- assert_equal 'This is a directive', directive_definition.description
606
-
607
- assert_equal GraphQL::Language::Nodes::EnumTypeDefinition, enum_type_definition.class
608
- assert_equal "Multiline comment\n\nWith an enum", enum_type_definition.description
609
-
610
- assert_nil enum_type_definition.values[0].description
611
- assert_equal 'Not a creative color', enum_type_definition.values[1].description
612
-
613
- assert_equal GraphQL::Language::Nodes::ObjectTypeDefinition, object_type_definition.class
614
- assert_equal 'Comment without preceding space', object_type_definition.description
615
- assert_equal 'And a field to boot', object_type_definition.fields[0].description
616
-
617
- assert_equal GraphQL::Language::Nodes::InputObjectTypeDefinition, input_object_type_definition.class
618
- assert_equal 'Comment for input object types', input_object_type_definition.description
619
- assert_equal 'Color of the car', input_object_type_definition.fields[0].description
620
-
621
- assert_equal GraphQL::Language::Nodes::InterfaceTypeDefinition, interface_type_definition.class
622
- assert_equal 'Comment for interface definitions', interface_type_definition.description
623
- assert_equal 'Amount of wheels', interface_type_definition.fields[0].description
624
-
625
- brand_field = interface_type_definition.fields[1]
626
- assert_equal 1, brand_field.arguments.length
627
- assert_equal 'argument', brand_field.arguments[0].name
628
- assert_instance_of GraphQL::Language::Nodes::NullValue, brand_field.arguments[0].default_value
629
- end
630
- end
631
- end
632
-
633
- SCHEMA_DEFINITION_STRING = %|
634
- # Schema at beginning of file
635
-
636
- schema {
637
- query: Hello
638
- }
639
-
640
- # Comment between two definitions are omitted
641
-
642
- # This is a directive
643
- directive @foo(
644
- # It has an argument
645
- arg: Int
646
- ) on FIELD
647
-
648
- # Multiline comment
649
- #
650
- # With an enum
651
- enum Color {
652
- RED
653
-
654
- # Not a creative color
655
- GREEN
656
- BLUE
657
- }
658
-
659
- #Comment without preceding space
660
- type Hello {
661
- # And a field to boot
662
- str: String
663
- }
664
-
665
- # Comment for input object types
666
- input Car {
667
- # Color of the car
668
- color: String!
669
- }
670
-
671
- # Comment for interface definitions
672
- interface Vehicle {
673
- # Amount of wheels
674
- wheels: Int!
675
- brand(argument: String = null): String!
676
- }
677
-
678
- # Comment at the end of schema
679
- |
680
- end
681
- end
682
- end
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
- require "graphql/compatibility/execution_specification"
3
- require "graphql/compatibility/lazy_execution_specification"
4
- require "graphql/compatibility/query_parser_specification"
5
- require "graphql/compatibility/schema_parser_specification"