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
@@ -0,0 +1,14 @@
|
|
1
|
+
module GraphQL
|
2
|
+
class Schema
|
3
|
+
# @api private
|
4
|
+
module Base64Encoder
|
5
|
+
def self.encode(plaintext, nonce: false)
|
6
|
+
Base64.strict_encode64(plaintext)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.decode(ciphertext, nonce: false)
|
10
|
+
Base64.decode64(ciphertext)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module GraphQL
|
2
3
|
class Schema
|
3
4
|
module BuildFromDefinition
|
@@ -84,6 +85,8 @@ module GraphQL
|
|
84
85
|
raise(NotImplementedError, "Generated Schema cannot use Interface or Union types for execution.")
|
85
86
|
}
|
86
87
|
|
88
|
+
NullScalarCoerce = ->(val) { val }
|
89
|
+
|
87
90
|
def build_enum_type(enum_type_definition, type_resolver)
|
88
91
|
GraphQL::EnumType.define(
|
89
92
|
name: enum_type_definition.name,
|
@@ -113,6 +116,7 @@ module GraphQL
|
|
113
116
|
GraphQL::ScalarType.define(
|
114
117
|
name: scalar_type_definition.name,
|
115
118
|
description: scalar_type_definition.description,
|
119
|
+
coerce: NullScalarCoerce,
|
116
120
|
)
|
117
121
|
end
|
118
122
|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
class Schema
|
4
|
+
module DefaultTypeError
|
5
|
+
def self.call(type_error, ctx)
|
6
|
+
case type_error
|
7
|
+
when GraphQL::InvalidNullError
|
8
|
+
ctx.errors << type_error
|
9
|
+
when GraphQL::UnresolvedTypeError
|
10
|
+
raise type_error
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module GraphQL
|
2
3
|
class Schema
|
3
4
|
# You can use the result of {GraphQL::Introspection::INTROSPECTION_QUERY}
|
@@ -36,6 +37,8 @@ module GraphQL
|
|
36
37
|
raise(NotImplementedError, "This schema was loaded from string, so it can't resolve types for objects")
|
37
38
|
}
|
38
39
|
|
40
|
+
NullScalarCoerce = ->(val) { val }
|
41
|
+
|
39
42
|
class << self
|
40
43
|
private
|
41
44
|
|
@@ -119,7 +122,8 @@ module GraphQL
|
|
119
122
|
else
|
120
123
|
ScalarType.define(
|
121
124
|
name: type["name"],
|
122
|
-
description: type["description"]
|
125
|
+
description: type["description"],
|
126
|
+
coerce: NullScalarCoerce,
|
123
127
|
)
|
124
128
|
end
|
125
129
|
when "UNION"
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module GraphQL
|
2
3
|
class Schema
|
3
4
|
# Used to convert your {GraphQL::Schema} to a GraphQL schema string
|
@@ -95,7 +96,7 @@ module GraphQL
|
|
95
96
|
def print_description(definition, indentation='', first_in_block=true)
|
96
97
|
return '' unless definition.description
|
97
98
|
|
98
|
-
description = indentation != '' && !first_in_block ? "\n" : ""
|
99
|
+
description = indentation != '' && !first_in_block ? "\n".dup : "".dup
|
99
100
|
description << GraphQL::Language::Comments.commentize(definition.description, indent: indentation)
|
100
101
|
end
|
101
102
|
end
|
@@ -111,7 +112,7 @@ module GraphQL
|
|
111
112
|
return "(#{field_arguments.map{ |arg| print_input_value(arg) }.join(", ")})"
|
112
113
|
end
|
113
114
|
|
114
|
-
out = "(\n"
|
115
|
+
out = "(\n".dup
|
115
116
|
out << field_arguments.map.with_index{ |arg, i|
|
116
117
|
"#{print_description(arg, " #{indentation}", i == 0)} #{indentation}"\
|
117
118
|
"#{print_input_value(arg)}"
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module GraphQL
|
2
3
|
class Schema
|
3
4
|
# - Store a table of errors & handlers
|
@@ -14,7 +15,7 @@ module GraphQL
|
|
14
15
|
# @example Rescue from not-found by telling the user
|
15
16
|
# MySchema.rescue_from(ActiveRecord::RecordNotFound) { "An item could not be found" }
|
16
17
|
#
|
17
|
-
# @param [Class] a class of error to rescue from
|
18
|
+
# @param error_class [Class] a class of error to rescue from
|
18
19
|
# @yield [err] A handler to return a message for this error instance
|
19
20
|
# @yieldparam [Exception] an error that was rescued
|
20
21
|
# @yieldreturn [String] message to put in GraphQL response
|
@@ -23,7 +24,7 @@ module GraphQL
|
|
23
24
|
end
|
24
25
|
|
25
26
|
# Remove the handler for `error_class`
|
26
|
-
# @param [Class] the error class whose handler should be removed
|
27
|
+
# @param error_class [Class] the error class whose handler should be removed
|
27
28
|
def remove_handler(error_class)
|
28
29
|
rescue_table.delete(error_class)
|
29
30
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module GraphQL
|
2
3
|
class Schema
|
3
4
|
# This module provides a function for validating GraphQL types.
|
@@ -86,7 +87,6 @@ module GraphQL
|
|
86
87
|
}
|
87
88
|
end
|
88
89
|
|
89
|
-
|
90
90
|
FIELDS_ARE_VALID = Rules.assert_named_items_are_valid("field", ->(type) { type.all_fields })
|
91
91
|
|
92
92
|
HAS_ONE_OR_MORE_POSSIBLE_TYPES = ->(type) {
|
@@ -155,6 +155,47 @@ module GraphQL
|
|
155
155
|
# :ok_hand:
|
156
156
|
end
|
157
157
|
}
|
158
|
+
|
159
|
+
SCHEMA_INSTRUMENTERS_ARE_VALID = ->(schema) {
|
160
|
+
errs = []
|
161
|
+
schema.instrumenters[:query].each do |inst|
|
162
|
+
if !inst.respond_to?(:before_query) || !inst.respond_to?(:after_query)
|
163
|
+
errs << "`instrument(:query, #{inst})` is invalid: must respond to `before_query(query)` and `after_query(query)` "
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
schema.instrumenters[:field].each do |inst|
|
168
|
+
if !inst.respond_to?(:instrument)
|
169
|
+
errs << "`instrument(:field, #{inst})` is invalid: must respond to `instrument(type, field)`"
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
if errs.any?
|
174
|
+
errs.join("Invalid instrumenters:\n" + errs.join("\n"))
|
175
|
+
else
|
176
|
+
nil
|
177
|
+
end
|
178
|
+
}
|
179
|
+
|
180
|
+
RESERVED_TYPE_NAME = ->(type) {
|
181
|
+
if type.name.start_with?('__') && INTROSPECTION_TYPES[type.name] != type
|
182
|
+
# TODO: make this a hard failure in a later version
|
183
|
+
warn("Name #{type.name.inspect} must not begin with \"__\", which is reserved by GraphQL introspection.")
|
184
|
+
nil
|
185
|
+
else
|
186
|
+
# ok name
|
187
|
+
end
|
188
|
+
}
|
189
|
+
|
190
|
+
RESERVED_NAME = ->(named_thing) {
|
191
|
+
if named_thing.name.start_with?('__')
|
192
|
+
# TODO: make this a hard failure in a later version
|
193
|
+
warn("Name #{named_thing.name.inspect} must not begin with \"__\", which is reserved by GraphQL introspection.")
|
194
|
+
nil
|
195
|
+
else
|
196
|
+
# no worries
|
197
|
+
end
|
198
|
+
}
|
158
199
|
end
|
159
200
|
|
160
201
|
# A mapping of `{Class => [Proc, Proc...]}` pairs.
|
@@ -163,6 +204,7 @@ module GraphQL
|
|
163
204
|
RULES = {
|
164
205
|
GraphQL::Field => [
|
165
206
|
Rules::NAME_IS_STRING,
|
207
|
+
Rules::RESERVED_NAME,
|
166
208
|
Rules::DESCRIPTION_IS_STRING_OR_NIL,
|
167
209
|
Rules.assert_property(:deprecation_reason, String, NilClass),
|
168
210
|
Rules.assert_property(:type, GraphQL::BaseType),
|
@@ -172,12 +214,14 @@ module GraphQL
|
|
172
214
|
],
|
173
215
|
GraphQL::Argument => [
|
174
216
|
Rules::NAME_IS_STRING,
|
217
|
+
Rules::RESERVED_NAME,
|
175
218
|
Rules::DESCRIPTION_IS_STRING_OR_NIL,
|
176
219
|
Rules::TYPE_IS_VALID_INPUT_TYPE,
|
177
220
|
Rules::DEFAULT_VALUE_IS_VALID_FOR_TYPE,
|
178
221
|
],
|
179
222
|
GraphQL::BaseType => [
|
180
223
|
Rules::NAME_IS_STRING,
|
224
|
+
Rules::RESERVED_TYPE_NAME,
|
181
225
|
Rules::DESCRIPTION_IS_STRING_OR_NIL,
|
182
226
|
],
|
183
227
|
GraphQL::ObjectType => [
|
@@ -199,8 +243,20 @@ module GraphQL
|
|
199
243
|
Rules::SCHEMA_CAN_RESOLVE_TYPES,
|
200
244
|
Rules::SCHEMA_CAN_FETCH_IDS,
|
201
245
|
Rules::SCHEMA_CAN_GENERATE_IDS,
|
246
|
+
Rules::SCHEMA_INSTRUMENTERS_ARE_VALID,
|
202
247
|
],
|
203
248
|
}
|
249
|
+
|
250
|
+
INTROSPECTION_TYPES = Hash[[
|
251
|
+
GraphQL::Introspection::TypeType,
|
252
|
+
GraphQL::Introspection::TypeKindEnum,
|
253
|
+
GraphQL::Introspection::FieldType,
|
254
|
+
GraphQL::Introspection::InputValueType,
|
255
|
+
GraphQL::Introspection::EnumValueType,
|
256
|
+
GraphQL::Introspection::DirectiveType,
|
257
|
+
GraphQL::Introspection::DirectiveLocationEnum,
|
258
|
+
GraphQL::Introspection::SchemaType,
|
259
|
+
].map{ |type| [type.name, type] }]
|
204
260
|
end
|
205
261
|
end
|
206
262
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module GraphQL
|
2
3
|
module StaticValidation
|
3
4
|
class FieldsWillMerge
|
@@ -76,7 +77,7 @@ module GraphQL
|
|
76
77
|
|
77
78
|
args = defs.map { |defn| reduce_list(defn.arguments)}.uniq
|
78
79
|
if args.length != 1
|
79
|
-
errors << message("Field '#{name}' has an argument conflict: #{args.map
|
80
|
+
errors << message("Field '#{name}' has an argument conflict: #{args.map{ |arg| GraphQL::Language.serialize(arg) }.join(" or ")}?", defs.first, context: context)
|
80
81
|
end
|
81
82
|
|
82
83
|
@errors = errors
|
@@ -88,8 +89,10 @@ module GraphQL
|
|
88
89
|
case arg
|
89
90
|
when GraphQL::Language::Nodes::VariableIdentifier
|
90
91
|
"$#{arg.name}"
|
92
|
+
when GraphQL::Language::Nodes::Enum
|
93
|
+
"#{arg.name}"
|
91
94
|
else
|
92
|
-
|
95
|
+
GraphQL::Language.serialize(arg)
|
93
96
|
end
|
94
97
|
end
|
95
98
|
|
@@ -97,7 +100,7 @@ module GraphQL
|
|
97
100
|
# can't look up args, the names just have to match
|
98
101
|
def reduce_list(args)
|
99
102
|
args.reduce({}) do |memo, a|
|
100
|
-
memo[a.name] =
|
103
|
+
memo[a.name] = print_arg(a.value)
|
101
104
|
memo
|
102
105
|
end
|
103
106
|
end
|