graphql 1.2.6 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/graphql.rb +3 -1
- data/lib/graphql/analysis.rb +1 -0
- data/lib/graphql/analysis/analyze_query.rb +1 -0
- data/lib/graphql/analysis/field_usage.rb +1 -0
- data/lib/graphql/analysis/max_query_complexity.rb +1 -0
- data/lib/graphql/analysis/max_query_depth.rb +1 -0
- data/lib/graphql/analysis/query_complexity.rb +1 -0
- data/lib/graphql/analysis/query_depth.rb +1 -0
- data/lib/graphql/analysis/reducer_state.rb +1 -0
- data/lib/graphql/analysis_error.rb +1 -0
- data/lib/graphql/argument.rb +1 -0
- data/lib/graphql/base_type.rb +16 -7
- data/lib/graphql/boolean_type.rb +1 -0
- data/lib/graphql/compatibility.rb +2 -0
- data/lib/graphql/compatibility/execution_specification.rb +113 -192
- data/lib/graphql/compatibility/execution_specification/counter_schema.rb +53 -0
- data/lib/graphql/compatibility/execution_specification/specification_schema.rb +195 -0
- data/lib/graphql/compatibility/lazy_execution_specification.rb +186 -0
- data/lib/graphql/compatibility/lazy_execution_specification/lazy_schema.rb +97 -0
- data/lib/graphql/compatibility/query_parser_specification.rb +1 -0
- data/lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb +1 -0
- data/lib/graphql/compatibility/query_parser_specification/query_assertions.rb +1 -0
- data/lib/graphql/compatibility/schema_parser_specification.rb +1 -0
- data/lib/graphql/define.rb +1 -0
- data/lib/graphql/define/assign_argument.rb +1 -0
- data/lib/graphql/define/assign_connection.rb +1 -0
- data/lib/graphql/define/assign_enum_value.rb +1 -0
- data/lib/graphql/define/assign_global_id_field.rb +1 -0
- data/lib/graphql/define/assign_object_field.rb +1 -0
- data/lib/graphql/define/defined_object_proxy.rb +1 -0
- data/lib/graphql/define/instance_definable.rb +11 -12
- data/lib/graphql/define/non_null_with_bang.rb +1 -0
- data/lib/graphql/define/type_definer.rb +1 -0
- data/lib/graphql/directive.rb +1 -0
- data/lib/graphql/directive/deprecated_directive.rb +1 -0
- data/lib/graphql/directive/include_directive.rb +1 -0
- data/lib/graphql/directive/skip_directive.rb +1 -0
- data/lib/graphql/enum_type.rb +8 -1
- data/lib/graphql/execution.rb +5 -0
- data/lib/graphql/execution/directive_checks.rb +1 -0
- data/lib/graphql/execution/execute.rb +222 -0
- data/lib/graphql/execution/field_result.rb +52 -0
- data/lib/graphql/execution/lazy.rb +59 -0
- data/lib/graphql/execution/lazy/lazy_method_map.rb +38 -0
- data/lib/graphql/execution/lazy/resolve.rb +68 -0
- data/lib/graphql/execution/selection_result.rb +84 -0
- data/lib/graphql/execution/typecast.rb +4 -4
- data/lib/graphql/execution_error.rb +1 -0
- data/lib/graphql/field.rb +68 -18
- data/lib/graphql/field/resolve.rb +1 -0
- data/lib/graphql/float_type.rb +1 -0
- data/lib/graphql/id_type.rb +1 -0
- data/lib/graphql/input_object_type.rb +6 -0
- data/lib/graphql/int_type.rb +1 -0
- data/lib/graphql/interface_type.rb +6 -0
- data/lib/graphql/internal_representation.rb +2 -1
- data/lib/graphql/internal_representation/node.rb +2 -1
- data/lib/graphql/internal_representation/rewrite.rb +1 -0
- data/lib/graphql/internal_representation/selection.rb +85 -0
- data/lib/graphql/introspection.rb +1 -0
- data/lib/graphql/introspection/arguments_field.rb +1 -0
- data/lib/graphql/introspection/directive_location_enum.rb +1 -0
- data/lib/graphql/introspection/directive_type.rb +1 -0
- data/lib/graphql/introspection/enum_value_type.rb +1 -0
- data/lib/graphql/introspection/enum_values_field.rb +1 -0
- data/lib/graphql/introspection/field_type.rb +1 -0
- data/lib/graphql/introspection/fields_field.rb +1 -0
- data/lib/graphql/introspection/input_fields_field.rb +1 -0
- data/lib/graphql/introspection/input_value_type.rb +2 -1
- data/lib/graphql/introspection/interfaces_field.rb +1 -0
- data/lib/graphql/introspection/introspection_query.rb +1 -0
- data/lib/graphql/introspection/of_type_field.rb +1 -0
- data/lib/graphql/introspection/possible_types_field.rb +1 -0
- data/lib/graphql/introspection/schema_field.rb +1 -0
- data/lib/graphql/introspection/schema_type.rb +1 -0
- data/lib/graphql/introspection/type_by_name_field.rb +1 -0
- data/lib/graphql/introspection/type_kind_enum.rb +1 -0
- data/lib/graphql/introspection/type_type.rb +1 -0
- data/lib/graphql/introspection/typename_field.rb +1 -0
- data/lib/graphql/invalid_null_error.rb +17 -7
- data/lib/graphql/language.rb +10 -0
- data/lib/graphql/language/comments.rb +2 -1
- data/lib/graphql/language/definition_slice.rb +1 -0
- data/lib/graphql/language/generation.rb +25 -24
- data/lib/graphql/language/nodes.rb +1 -0
- data/lib/graphql/language/token.rb +1 -0
- data/lib/graphql/language/visitor.rb +1 -0
- data/lib/graphql/list_type.rb +1 -0
- data/lib/graphql/non_null_type.rb +2 -1
- data/lib/graphql/object_type.rb +12 -0
- data/lib/graphql/query.rb +40 -43
- data/lib/graphql/query/arguments.rb +1 -0
- data/lib/graphql/query/context.rb +31 -7
- data/lib/graphql/query/executor.rb +8 -1
- data/lib/graphql/query/input_validation_result.rb +1 -0
- data/lib/graphql/query/literal_input.rb +1 -0
- data/lib/graphql/query/serial_execution.rb +3 -4
- data/lib/graphql/query/serial_execution/field_resolution.rb +15 -10
- data/lib/graphql/query/serial_execution/operation_resolution.rb +3 -5
- data/lib/graphql/query/serial_execution/selection_resolution.rb +4 -5
- data/lib/graphql/query/serial_execution/value_resolution.rb +26 -11
- data/lib/graphql/query/variable_validation_error.rb +1 -0
- data/lib/graphql/query/variables.rb +1 -0
- data/lib/graphql/relay.rb +1 -0
- data/lib/graphql/relay/array_connection.rb +3 -2
- data/lib/graphql/relay/base_connection.rb +20 -8
- data/lib/graphql/relay/connection_field.rb +1 -0
- data/lib/graphql/relay/connection_resolve.rb +14 -1
- data/lib/graphql/relay/connection_type.rb +1 -0
- data/lib/graphql/relay/edge.rb +1 -0
- data/lib/graphql/relay/edge_type.rb +1 -0
- data/lib/graphql/relay/global_id_resolve.rb +1 -0
- data/lib/graphql/relay/mutation.rb +13 -0
- data/lib/graphql/relay/node.rb +1 -0
- data/lib/graphql/relay/page_info.rb +1 -0
- data/lib/graphql/relay/relation_connection.rb +3 -2
- data/lib/graphql/runtime_type_error.rb +4 -0
- data/lib/graphql/scalar_type.rb +2 -1
- data/lib/graphql/schema.rb +116 -26
- data/lib/graphql/schema/base_64_encoder.rb +14 -0
- data/lib/graphql/schema/build_from_definition.rb +4 -0
- data/lib/graphql/schema/catchall_middleware.rb +1 -0
- data/lib/graphql/schema/default_type_error.rb +15 -0
- data/lib/graphql/schema/instrumented_field_map.rb +1 -0
- data/lib/graphql/schema/invalid_type_error.rb +1 -0
- data/lib/graphql/schema/loader.rb +5 -1
- data/lib/graphql/schema/middleware_chain.rb +1 -0
- data/lib/graphql/schema/possible_types.rb +1 -0
- data/lib/graphql/schema/printer.rb +3 -2
- data/lib/graphql/schema/reduce_types.rb +1 -0
- data/lib/graphql/schema/rescue_middleware.rb +3 -2
- data/lib/graphql/schema/timeout_middleware.rb +1 -0
- data/lib/graphql/schema/type_expression.rb +1 -0
- data/lib/graphql/schema/type_map.rb +1 -0
- data/lib/graphql/schema/unique_within_type.rb +1 -0
- data/lib/graphql/schema/validation.rb +57 -1
- data/lib/graphql/schema/warden.rb +1 -0
- data/lib/graphql/static_validation.rb +1 -0
- data/lib/graphql/static_validation/all_rules.rb +1 -0
- data/lib/graphql/static_validation/arguments_validator.rb +1 -0
- data/lib/graphql/static_validation/literal_validator.rb +1 -0
- data/lib/graphql/static_validation/message.rb +1 -0
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +1 -0
- data/lib/graphql/static_validation/rules/arguments_are_defined.rb +1 -0
- data/lib/graphql/static_validation/rules/directives_are_defined.rb +1 -0
- data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +1 -0
- data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +1 -0
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +1 -0
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +6 -3
- data/lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb +1 -0
- data/lib/graphql/static_validation/rules/fragment_types_exist.rb +1 -0
- data/lib/graphql/static_validation/rules/fragments_are_finite.rb +1 -0
- data/lib/graphql/static_validation/rules/fragments_are_named.rb +1 -0
- data/lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb +1 -0
- data/lib/graphql/static_validation/rules/fragments_are_used.rb +1 -0
- data/lib/graphql/static_validation/rules/mutation_root_exists.rb +1 -0
- data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +1 -0
- data/lib/graphql/static_validation/rules/subscription_root_exists.rb +1 -0
- data/lib/graphql/static_validation/rules/unique_directives_per_location.rb +1 -0
- data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +1 -0
- data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +1 -0
- data/lib/graphql/static_validation/rules/variables_are_input_types.rb +1 -0
- data/lib/graphql/static_validation/rules/variables_are_used_and_defined.rb +1 -0
- data/lib/graphql/static_validation/type_stack.rb +1 -0
- data/lib/graphql/static_validation/validation_context.rb +2 -1
- data/lib/graphql/static_validation/validator.rb +2 -1
- data/lib/graphql/string_type.rb +1 -0
- data/lib/graphql/type_kinds.rb +1 -0
- data/lib/graphql/union_type.rb +13 -0
- data/lib/graphql/unresolved_type_error.rb +26 -5
- data/lib/graphql/version.rb +2 -1
- data/readme.md +1 -5
- data/spec/graphql/analysis/analyze_query_spec.rb +1 -0
- data/spec/graphql/analysis/field_usage_spec.rb +1 -0
- data/spec/graphql/analysis/max_query_complexity_spec.rb +1 -0
- data/spec/graphql/analysis/max_query_depth_spec.rb +1 -0
- data/spec/graphql/analysis/query_complexity_spec.rb +1 -0
- data/spec/graphql/analysis/query_depth_spec.rb +1 -0
- data/spec/graphql/argument_spec.rb +1 -0
- data/spec/graphql/base_type_spec.rb +13 -0
- data/spec/graphql/boolean_type_spec.rb +1 -0
- data/spec/graphql/compatibility/execution_specification_spec.rb +1 -0
- data/spec/graphql/compatibility/lazy_execution_specification_spec.rb +4 -0
- data/spec/graphql/compatibility/query_parser_specification_spec.rb +1 -0
- data/spec/graphql/compatibility/schema_parser_specification_spec.rb +1 -0
- data/spec/graphql/define/assign_argument_spec.rb +1 -0
- data/spec/graphql/define/instance_definable_spec.rb +1 -0
- data/spec/graphql/directive_spec.rb +1 -0
- data/spec/graphql/enum_type_spec.rb +10 -0
- data/spec/graphql/execution/execute_spec.rb +5 -0
- data/spec/graphql/execution/lazy_spec.rb +252 -0
- data/spec/graphql/execution/typecast_spec.rb +1 -0
- data/spec/graphql/execution_error_spec.rb +1 -0
- data/spec/graphql/field_spec.rb +17 -0
- data/spec/graphql/float_type_spec.rb +1 -0
- data/spec/graphql/id_type_spec.rb +1 -0
- data/spec/graphql/input_object_type_spec.rb +10 -0
- data/spec/graphql/int_type_spec.rb +1 -0
- data/spec/graphql/interface_type_spec.rb +10 -0
- data/spec/graphql/internal_representation/rewrite_spec.rb +1 -0
- data/spec/graphql/introspection/directive_type_spec.rb +1 -0
- data/spec/graphql/introspection/input_value_type_spec.rb +1 -0
- data/spec/graphql/introspection/introspection_query_spec.rb +1 -0
- data/spec/graphql/introspection/schema_type_spec.rb +1 -0
- data/spec/graphql/introspection/type_type_spec.rb +1 -0
- data/spec/graphql/language/definition_slice_spec.rb +1 -0
- data/spec/graphql/language/equality_spec.rb +1 -0
- data/spec/graphql/language/generation_spec.rb +1 -0
- data/spec/graphql/language/lexer_spec.rb +1 -0
- data/spec/graphql/language/nodes_spec.rb +1 -0
- data/spec/graphql/language/parser_spec.rb +1 -0
- data/spec/graphql/language/visitor_spec.rb +1 -0
- data/spec/graphql/list_type_spec.rb +1 -0
- data/spec/graphql/non_null_type_spec.rb +17 -0
- data/spec/graphql/object_type_spec.rb +19 -0
- data/spec/graphql/query/arguments_spec.rb +1 -0
- data/spec/graphql/query/context_spec.rb +1 -0
- data/spec/graphql/query/executor_spec.rb +1 -0
- data/spec/graphql/query/serial_execution/value_resolution_spec.rb +1 -0
- data/spec/graphql/query/variables_spec.rb +1 -0
- data/spec/graphql/query_spec.rb +25 -0
- data/spec/graphql/relay/array_connection_spec.rb +1 -0
- data/spec/graphql/relay/base_connection_spec.rb +33 -4
- data/spec/graphql/relay/connection_field_spec.rb +1 -0
- data/spec/graphql/relay/connection_type_spec.rb +1 -0
- data/spec/graphql/relay/mutation_spec.rb +6 -0
- data/spec/graphql/relay/node_spec.rb +1 -0
- data/spec/graphql/relay/page_info_spec.rb +1 -0
- data/spec/graphql/relay/relation_connection_spec.rb +1 -0
- data/spec/graphql/scalar_type_spec.rb +1 -0
- data/spec/graphql/schema/build_from_definition_spec.rb +9 -1
- data/spec/graphql/schema/catchall_middleware_spec.rb +1 -0
- data/spec/graphql/schema/loader_spec.rb +7 -0
- data/spec/graphql/schema/middleware_chain_spec.rb +1 -0
- data/spec/graphql/schema/printer_spec.rb +1 -0
- data/spec/graphql/schema/reduce_types_spec.rb +1 -0
- data/spec/graphql/schema/rescue_middleware_spec.rb +1 -0
- data/spec/graphql/schema/timeout_middleware_spec.rb +1 -0
- data/spec/graphql/schema/type_expression_spec.rb +1 -0
- data/spec/graphql/schema/unique_within_type_spec.rb +1 -0
- data/spec/graphql/schema/validation_spec.rb +55 -0
- data/spec/graphql/schema/warden_spec.rb +1 -0
- data/spec/graphql/schema_spec.rb +39 -0
- data/spec/graphql/static_validation/rules/argument_literals_are_compatible_spec.rb +1 -0
- data/spec/graphql/static_validation/rules/arguments_are_defined_spec.rb +1 -0
- data/spec/graphql/static_validation/rules/directives_are_defined_spec.rb +1 -0
- data/spec/graphql/static_validation/rules/directives_are_in_valid_locations_spec.rb +1 -0
- data/spec/graphql/static_validation/rules/fields_are_defined_on_type_spec.rb +1 -0
- data/spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb +1 -0
- data/spec/graphql/static_validation/rules/fields_will_merge_spec.rb +515 -31
- data/spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb +1 -0
- data/spec/graphql/static_validation/rules/fragment_types_exist_spec.rb +1 -0
- data/spec/graphql/static_validation/rules/fragments_are_finite_spec.rb +1 -0
- data/spec/graphql/static_validation/rules/fragments_are_named_spec.rb +1 -0
- data/spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb +1 -0
- data/spec/graphql/static_validation/rules/fragments_are_used_spec.rb +1 -0
- data/spec/graphql/static_validation/rules/mutation_root_exists_spec.rb +1 -0
- data/spec/graphql/static_validation/rules/required_arguments_are_present_spec.rb +1 -0
- data/spec/graphql/static_validation/rules/subscription_root_exists_spec.rb +1 -0
- data/spec/graphql/static_validation/rules/unique_directives_per_location_spec.rb +1 -0
- data/spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb +1 -0
- data/spec/graphql/static_validation/rules/variable_usages_are_allowed_spec.rb +1 -0
- data/spec/graphql/static_validation/rules/variables_are_input_types_spec.rb +1 -0
- data/spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb +1 -0
- data/spec/graphql/static_validation/type_stack_spec.rb +1 -0
- data/spec/graphql/static_validation/validator_spec.rb +1 -0
- data/spec/graphql/string_type_spec.rb +1 -0
- data/spec/graphql/union_type_spec.rb +11 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/support/dairy_app.rb +1 -0
- data/spec/support/dairy_data.rb +1 -0
- data/spec/support/minimum_input_object.rb +1 -0
- data/spec/support/star_wars_data.rb +1 -0
- data/spec/support/star_wars_schema.rb +30 -7
- data/spec/support/static_validation_helpers.rb +1 -0
- metadata +24 -5
- data/lib/graphql/internal_representation/selections.rb +0 -41
data/spec/graphql/field_spec.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require "spec_helper"
|
2
3
|
|
3
4
|
describe GraphQL::Field do
|
@@ -164,5 +165,21 @@ describe GraphQL::Field do
|
|
164
165
|
assert_equal 1, int_field.arguments.size
|
165
166
|
assert_equal 2, int_field_2.arguments.size
|
166
167
|
end
|
168
|
+
|
169
|
+
it "copies metadata, even out-of-bounds assignments" do
|
170
|
+
int_field = GraphQL::Field.define do
|
171
|
+
metadata(:a, 1)
|
172
|
+
argument :value, types.Int
|
173
|
+
end
|
174
|
+
int_field.metadata[:b] = 2
|
175
|
+
|
176
|
+
int_field_2 = int_field.redefine do
|
177
|
+
metadata(:c, 3)
|
178
|
+
argument :value_2, types.Int
|
179
|
+
end
|
180
|
+
|
181
|
+
assert_equal({a: 1, b: 2}, int_field.metadata)
|
182
|
+
assert_equal({a: 1, b: 2, c: 3}, int_field_2.metadata)
|
183
|
+
end
|
167
184
|
end
|
168
185
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require "spec_helper"
|
2
3
|
|
3
4
|
describe GraphQL::InputObjectType do
|
@@ -252,4 +253,13 @@ describe GraphQL::InputObjectType do
|
|
252
253
|
end
|
253
254
|
end
|
254
255
|
end
|
256
|
+
|
257
|
+
describe "#dup" do
|
258
|
+
it "shallow-copies internal state" do
|
259
|
+
input_object_2 = input_object.dup
|
260
|
+
input_object_2.arguments["nonsense"] = GraphQL::Argument.define(name: "int", type: GraphQL::INT_TYPE)
|
261
|
+
assert_equal 4, input_object.arguments.size
|
262
|
+
assert_equal 5, input_object_2.arguments.size
|
263
|
+
end
|
264
|
+
end
|
255
265
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require "spec_helper"
|
2
3
|
|
3
4
|
describe GraphQL::InterfaceType do
|
@@ -83,4 +84,13 @@ describe GraphQL::InterfaceType do
|
|
83
84
|
end
|
84
85
|
end
|
85
86
|
end
|
87
|
+
|
88
|
+
describe "#dup" do
|
89
|
+
it "copies the fields without altering the original" do
|
90
|
+
interface_2 = interface.dup
|
91
|
+
interface_2.fields["extra"] = GraphQL::Field.define(name: "extra", type: GraphQL::BOOLEAN_TYPE)
|
92
|
+
assert_equal 3, interface.fields.size
|
93
|
+
assert_equal 4, interface_2.fields.size
|
94
|
+
end
|
95
|
+
end
|
86
96
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require "spec_helper"
|
2
3
|
|
3
4
|
describe GraphQL::NonNullType do
|
@@ -27,5 +28,21 @@ describe GraphQL::NonNullType do
|
|
27
28
|
assert_equal(nil, result["data"])
|
28
29
|
assert_equal([{"message"=>"Cannot return null for non-nullable field DeepNonNull.nonNullInt"}], result["errors"])
|
29
30
|
end
|
31
|
+
|
32
|
+
describe "when type_error is configured to raise an error" do
|
33
|
+
it "crashes query execution" do
|
34
|
+
raise_schema = DummySchema.redefine {
|
35
|
+
type_error ->(type_err, ctx) {
|
36
|
+
raise type_err
|
37
|
+
}
|
38
|
+
}
|
39
|
+
query_string = %|{ cow { name cantBeNullButIs } }|
|
40
|
+
err = assert_raises(GraphQL::InvalidNullError) { raise_schema.execute(query_string) }
|
41
|
+
assert_equal("Cannot return null for non-nullable field Cow.cantBeNullButIs", err.message)
|
42
|
+
assert_equal("Cow", err.parent_type.name)
|
43
|
+
assert_equal("cantBeNullButIs", err.field.name)
|
44
|
+
assert_equal(nil, err.value)
|
45
|
+
end
|
46
|
+
end
|
30
47
|
end
|
31
48
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require "spec_helper"
|
2
3
|
|
3
4
|
describe GraphQL::ObjectType do
|
@@ -45,4 +46,22 @@ describe GraphQL::ObjectType do
|
|
45
46
|
assert_equal(field_from_iface.property, nil)
|
46
47
|
end
|
47
48
|
end
|
49
|
+
|
50
|
+
describe "#dup" do
|
51
|
+
it "copies fields and interfaces without altering the original" do
|
52
|
+
type.interfaces # load the internal cache
|
53
|
+
type_2 = type.dup
|
54
|
+
|
55
|
+
# IRL, use `+=`, not this
|
56
|
+
# (this tests the internal cache)
|
57
|
+
type_2.interfaces << type
|
58
|
+
|
59
|
+
type_2.fields["nonsense"] = GraphQL::Field.define(name: "nonsense", type: type)
|
60
|
+
|
61
|
+
assert_equal 3, type.interfaces.size
|
62
|
+
assert_equal 4, type_2.interfaces.size
|
63
|
+
assert_equal 8, type.fields.size
|
64
|
+
assert_equal 9, type_2.fields.size
|
65
|
+
end
|
66
|
+
end
|
48
67
|
end
|
data/spec/graphql/query_spec.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require "spec_helper"
|
2
3
|
|
3
4
|
describe GraphQL::Query do
|
@@ -122,6 +123,24 @@ describe GraphQL::Query do
|
|
122
123
|
assert_equal(expected, result)
|
123
124
|
end
|
124
125
|
end
|
126
|
+
|
127
|
+
describe "after_query hooks" do
|
128
|
+
module Instrumenter
|
129
|
+
ERROR_LOG = []
|
130
|
+
def self.before_query(q); end;
|
131
|
+
def self.after_query(q); ERROR_LOG << q.result["errors"]; end;
|
132
|
+
end
|
133
|
+
|
134
|
+
let(:schema) {
|
135
|
+
DummySchema.redefine {
|
136
|
+
instrument(:query, Instrumenter)
|
137
|
+
}
|
138
|
+
}
|
139
|
+
it "can access #result" do
|
140
|
+
result
|
141
|
+
assert_equal [nil], Instrumenter::ERROR_LOG
|
142
|
+
end
|
143
|
+
end
|
125
144
|
end
|
126
145
|
|
127
146
|
it "fails to execute a query containing a type definition" do
|
@@ -377,4 +396,10 @@ describe GraphQL::Query do
|
|
377
396
|
end
|
378
397
|
end
|
379
398
|
end
|
399
|
+
|
400
|
+
describe "#provided_variables" do
|
401
|
+
it "returns the originally-provided object" do
|
402
|
+
assert_equal({"cheeseId" => 2}, query.provided_variables)
|
403
|
+
end
|
404
|
+
end
|
380
405
|
end
|
@@ -1,9 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe GraphQL::Relay::BaseConnection do
|
4
|
-
|
5
5
|
describe ".connection_for_nodes" do
|
6
|
-
|
7
6
|
it "resolves most specific connection type" do
|
8
7
|
class SpecialArray < Array; end
|
9
8
|
class SpecialArrayConnection < GraphQL::Relay::BaseConnection; end
|
@@ -11,9 +10,39 @@ describe GraphQL::Relay::BaseConnection do
|
|
11
10
|
|
12
11
|
nodes = SpecialArray.new
|
13
12
|
|
14
|
-
GraphQL::Relay::BaseConnection.connection_for_nodes(nodes)
|
15
|
-
|
13
|
+
conn_class = GraphQL::Relay::BaseConnection.connection_for_nodes(nodes)
|
14
|
+
assert_equal conn_class, SpecialArrayConnection
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#encode / #decode" do
|
19
|
+
module ReverseEncoder
|
20
|
+
module_function
|
21
|
+
def encode(str, nonce: false); str.reverse; end
|
22
|
+
def decode(str, nonce: false); str.reverse; end
|
23
|
+
end
|
24
|
+
|
25
|
+
let(:schema) { OpenStruct.new(cursor_encoder: ReverseEncoder) }
|
26
|
+
let(:context) { OpenStruct.new(schema: schema) }
|
27
|
+
|
28
|
+
it "Uses the schema's encoder" do
|
29
|
+
conn = GraphQL::Relay::BaseConnection.new([], {}, context: context)
|
30
|
+
|
31
|
+
assert_equal "1/nosreP", conn.encode("Person/1")
|
32
|
+
assert_equal "Person/1", conn.decode("1/nosreP")
|
16
33
|
end
|
17
34
|
|
35
|
+
it "defaults to base64" do
|
36
|
+
conn = GraphQL::Relay::BaseConnection.new([], {}, context: nil)
|
37
|
+
|
38
|
+
assert_equal "UGVyc29uLzE=", conn.encode("Person/1")
|
39
|
+
assert_equal "Person/1", conn.decode("UGVyc29uLzE=")
|
40
|
+
end
|
41
|
+
|
42
|
+
it "handles trimmed base64" do
|
43
|
+
conn = GraphQL::Relay::BaseConnection.new([], {}, context: nil)
|
44
|
+
|
45
|
+
assert_equal "Person/1", conn.decode("UGVyc29uLzE")
|
46
|
+
end
|
18
47
|
end
|
19
48
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe GraphQL::Relay::Mutation do
|
@@ -43,6 +44,11 @@ describe GraphQL::Relay::Mutation do
|
|
43
44
|
assert_equal(expected, result)
|
44
45
|
end
|
45
46
|
|
47
|
+
it "supports lazy resolution" do
|
48
|
+
result = star_wars_query(query_string, "clientMutationId" => "1234", "shipName" => "Slave II")
|
49
|
+
assert_equal "Slave II", result["data"]["introduceShip"]["shipEdge"]["node"]["name"]
|
50
|
+
end
|
51
|
+
|
46
52
|
it "returns the result & clientMutationId" do
|
47
53
|
result = star_wars_query(query_string, "clientMutationId" => "1234")
|
48
54
|
expected = {"data" => {
|
@@ -1,9 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require "spec_helper"
|
2
3
|
|
3
4
|
describe GraphQL::Schema::BuildFromDefinition do
|
5
|
+
# Build a schema from `definition` and assert that it
|
6
|
+
# prints out the same string.
|
7
|
+
# Then return the built schema.
|
4
8
|
def build_schema_and_compare_output(definition)
|
5
9
|
built_schema = GraphQL::Schema.from_definition(definition)
|
6
10
|
assert_equal definition, GraphQL::Schema::Printer.print_schema(built_schema)
|
11
|
+
built_schema
|
7
12
|
end
|
8
13
|
|
9
14
|
describe '.build' do
|
@@ -345,7 +350,10 @@ type Root {
|
|
345
350
|
}
|
346
351
|
SCHEMA
|
347
352
|
|
348
|
-
build_schema_and_compare_output(schema.chop)
|
353
|
+
built_schema = build_schema_and_compare_output(schema.chop)
|
354
|
+
custom_scalar = built_schema.types["CustomScalar"]
|
355
|
+
assert_equal true, custom_scalar.valid_input?("anything", PermissiveWarden)
|
356
|
+
assert_equal true, custom_scalar.valid_input?(12345, PermissiveWarden)
|
349
357
|
end
|
350
358
|
|
351
359
|
it 'supports input object' do
|