graphql 2.0.31 → 2.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/generators/graphql/detailed_trace_generator.rb +77 -0
- data/lib/generators/graphql/install/mutation_root_generator.rb +2 -2
- data/lib/generators/graphql/install/templates/base_mutation.erb +2 -0
- data/lib/generators/graphql/install/templates/mutation_type.erb +2 -0
- data/lib/generators/graphql/install_generator.rb +49 -0
- data/lib/generators/graphql/orm_mutations_base.rb +1 -1
- data/lib/generators/graphql/templates/base_argument.erb +2 -0
- data/lib/generators/graphql/templates/base_connection.erb +2 -0
- data/lib/generators/graphql/templates/base_edge.erb +2 -0
- data/lib/generators/graphql/templates/base_enum.erb +2 -0
- data/lib/generators/graphql/templates/base_field.erb +2 -0
- data/lib/generators/graphql/templates/base_input_object.erb +2 -0
- data/lib/generators/graphql/templates/base_interface.erb +2 -0
- data/lib/generators/graphql/templates/base_object.erb +2 -0
- data/lib/generators/graphql/templates/base_resolver.erb +8 -0
- data/lib/generators/graphql/templates/base_scalar.erb +2 -0
- data/lib/generators/graphql/templates/base_union.erb +2 -0
- data/lib/generators/graphql/templates/create_graphql_detailed_traces.erb +10 -0
- data/lib/generators/graphql/templates/graphql_controller.erb +2 -0
- data/lib/generators/graphql/templates/loader.erb +2 -0
- data/lib/generators/graphql/templates/mutation.erb +2 -0
- data/lib/generators/graphql/templates/node_type.erb +2 -0
- data/lib/generators/graphql/templates/query_type.erb +2 -0
- data/lib/generators/graphql/templates/schema.erb +5 -0
- data/lib/generators/graphql/type_generator.rb +1 -1
- data/lib/graphql/analysis/analyzer.rb +90 -0
- data/lib/graphql/analysis/field_usage.rb +82 -0
- data/lib/graphql/analysis/max_query_complexity.rb +20 -0
- data/lib/graphql/analysis/max_query_depth.rb +20 -0
- data/lib/graphql/analysis/query_complexity.rb +263 -0
- data/lib/graphql/analysis/query_depth.rb +58 -0
- data/lib/graphql/analysis/visitor.rb +280 -0
- data/lib/graphql/analysis.rb +102 -1
- data/lib/graphql/autoload.rb +38 -0
- data/lib/graphql/backtrace/table.rb +118 -55
- data/lib/graphql/backtrace.rb +1 -19
- data/lib/graphql/coercion_error.rb +1 -9
- data/lib/graphql/current.rb +57 -0
- data/lib/graphql/dashboard/application_controller.rb +41 -0
- data/lib/graphql/dashboard/detailed_traces.rb +47 -0
- data/lib/graphql/dashboard/installable.rb +22 -0
- data/lib/graphql/dashboard/landings_controller.rb +9 -0
- data/lib/graphql/dashboard/limiters.rb +93 -0
- data/lib/graphql/dashboard/operation_store.rb +199 -0
- data/lib/graphql/dashboard/statics/bootstrap-5.3.3.min.css +6 -0
- data/lib/graphql/dashboard/statics/bootstrap-5.3.3.min.js +7 -0
- data/lib/graphql/dashboard/statics/charts.min.css +1 -0
- data/lib/graphql/dashboard/statics/dashboard.css +30 -0
- data/lib/graphql/dashboard/statics/dashboard.js +143 -0
- data/lib/graphql/dashboard/statics/header-icon.png +0 -0
- data/lib/graphql/dashboard/statics/icon.png +0 -0
- data/lib/graphql/dashboard/statics_controller.rb +31 -0
- data/lib/graphql/dashboard/subscriptions.rb +97 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/detailed_traces/traces/index.html.erb +45 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/landings/show.html.erb +18 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/limiters/limiters/show.html.erb +62 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/not_installed.html.erb +18 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/operation_store/clients/_form.html.erb +24 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/operation_store/clients/edit.html.erb +21 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/operation_store/clients/index.html.erb +69 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/operation_store/clients/new.html.erb +7 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/operation_store/index_entries/index.html.erb +39 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/operation_store/index_entries/show.html.erb +32 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/operation_store/operations/index.html.erb +81 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/operation_store/operations/show.html.erb +71 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/subscriptions/subscriptions/show.html.erb +41 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/subscriptions/topics/index.html.erb +55 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/subscriptions/topics/show.html.erb +40 -0
- data/lib/graphql/dashboard/views/layouts/graphql/dashboard/application.html.erb +108 -0
- data/lib/graphql/dashboard.rb +96 -0
- data/lib/graphql/dataloader/active_record_association_source.rb +84 -0
- data/lib/graphql/dataloader/active_record_source.rb +47 -0
- data/lib/graphql/dataloader/async_dataloader.rb +112 -0
- data/lib/graphql/dataloader/null_dataloader.rb +55 -10
- data/lib/graphql/dataloader/request.rb +5 -0
- data/lib/graphql/dataloader/source.rb +35 -12
- data/lib/graphql/dataloader.rb +224 -149
- data/lib/graphql/date_encoding_error.rb +1 -1
- data/lib/graphql/dig.rb +2 -1
- data/lib/graphql/duration_encoding_error.rb +16 -0
- data/lib/graphql/execution/field_resolve_step.rb +631 -0
- data/lib/graphql/execution/finalize.rb +217 -0
- data/lib/graphql/execution/input_values.rb +261 -0
- data/lib/graphql/execution/interpreter/argument_value.rb +5 -1
- data/lib/graphql/execution/interpreter/arguments_cache.rb +5 -10
- data/lib/graphql/execution/interpreter/handles_raw_value.rb +6 -0
- data/lib/graphql/execution/interpreter/resolve.rb +23 -25
- data/lib/graphql/execution/interpreter/runtime/graphql_result.rb +228 -0
- data/lib/graphql/execution/interpreter/runtime.rb +365 -435
- data/lib/graphql/execution/interpreter.rb +87 -163
- data/lib/graphql/execution/lazy.rb +1 -1
- data/lib/graphql/execution/load_argument_step.rb +64 -0
- data/lib/graphql/execution/lookahead.rb +105 -31
- data/lib/graphql/execution/multiplex.rb +7 -6
- data/lib/graphql/execution/next.rb +90 -0
- data/lib/graphql/execution/prepare_object_step.rb +128 -0
- data/lib/graphql/execution/runner.rb +410 -0
- data/lib/graphql/execution/selections_step.rb +91 -0
- data/lib/graphql/execution.rb +8 -4
- data/lib/graphql/execution_error.rb +17 -10
- data/lib/graphql/introspection/directive_location_enum.rb +1 -1
- data/lib/graphql/introspection/directive_type.rb +7 -3
- data/lib/graphql/introspection/dynamic_fields.rb +5 -1
- data/lib/graphql/introspection/entry_points.rb +20 -6
- data/lib/graphql/introspection/enum_value_type.rb +5 -5
- data/lib/graphql/introspection/field_type.rb +13 -5
- data/lib/graphql/introspection/input_value_type.rb +21 -13
- data/lib/graphql/introspection/schema_type.rb +8 -11
- data/lib/graphql/introspection/type_type.rb +64 -28
- data/lib/graphql/invalid_name_error.rb +1 -1
- data/lib/graphql/invalid_null_error.rb +26 -17
- data/lib/graphql/language/block_string.rb +34 -18
- data/lib/graphql/language/cache.rb +13 -0
- data/lib/graphql/language/comment.rb +18 -0
- data/lib/graphql/language/definition_slice.rb +1 -1
- data/lib/graphql/language/document_from_schema_definition.rb +90 -61
- data/lib/graphql/language/lexer.rb +323 -193
- data/lib/graphql/language/nodes.rb +139 -77
- data/lib/graphql/language/parser.rb +807 -1985
- data/lib/graphql/language/printer.rb +324 -151
- data/lib/graphql/language/sanitized_printer.rb +21 -23
- data/lib/graphql/language/static_visitor.rb +171 -0
- data/lib/graphql/language/visitor.rb +62 -119
- data/lib/graphql/language.rb +71 -1
- data/lib/graphql/load_application_object_failed_error.rb +5 -1
- data/lib/graphql/pagination/array_connection.rb +6 -6
- data/lib/graphql/pagination/connection.rb +30 -1
- data/lib/graphql/pagination/connections.rb +32 -0
- data/lib/graphql/pagination/mongoid_relation_connection.rb +1 -2
- data/lib/graphql/query/context/scoped_context.rb +101 -0
- data/lib/graphql/query/context.rb +88 -144
- data/lib/graphql/query/null_context.rb +15 -18
- data/lib/graphql/query/partial.rb +194 -0
- data/lib/graphql/query/validation_pipeline.rb +4 -4
- data/lib/graphql/query/variable_validation_error.rb +1 -1
- data/lib/graphql/query/variables.rb +3 -3
- data/lib/graphql/query.rb +135 -81
- data/lib/graphql/railtie.rb +16 -6
- data/lib/graphql/rake_task.rb +3 -12
- data/lib/graphql/rubocop/graphql/base_cop.rb +1 -1
- data/lib/graphql/rubocop/graphql/field_type_in_block.rb +144 -0
- data/lib/graphql/rubocop/graphql/root_types_in_block.rb +38 -0
- data/lib/graphql/rubocop.rb +2 -0
- data/lib/graphql/runtime_error.rb +6 -0
- data/lib/graphql/schema/addition.rb +26 -13
- data/lib/graphql/schema/always_visible.rb +7 -2
- data/lib/graphql/schema/argument.rb +78 -14
- data/lib/graphql/schema/base_64_encoder.rb +3 -5
- data/lib/graphql/schema/build_from_definition.rb +140 -66
- data/lib/graphql/schema/directive/flagged.rb +4 -2
- data/lib/graphql/schema/directive/one_of.rb +12 -0
- data/lib/graphql/schema/directive/specified_by.rb +14 -0
- data/lib/graphql/schema/directive.rb +78 -12
- data/lib/graphql/schema/enum.rb +110 -27
- data/lib/graphql/schema/enum_value.rb +11 -3
- data/lib/graphql/schema/field/connection_extension.rb +4 -51
- data/lib/graphql/schema/field/scope_extension.rb +19 -7
- data/lib/graphql/schema/field.rb +245 -119
- data/lib/graphql/schema/field_extension.rb +12 -9
- data/lib/graphql/schema/has_single_input_argument.rb +160 -0
- data/lib/graphql/schema/input_object.rb +123 -65
- data/lib/graphql/schema/interface.rb +60 -16
- data/lib/graphql/schema/introspection_system.rb +8 -17
- data/lib/graphql/schema/late_bound_type.rb +4 -0
- data/lib/graphql/schema/list.rb +8 -4
- data/lib/graphql/schema/loader.rb +3 -4
- data/lib/graphql/schema/member/base_dsl_methods.rb +18 -12
- data/lib/graphql/schema/member/has_arguments.rb +132 -100
- data/lib/graphql/schema/member/has_authorization.rb +35 -0
- data/lib/graphql/schema/member/has_dataloader.rb +99 -0
- data/lib/graphql/schema/member/has_deprecation_reason.rb +15 -0
- data/lib/graphql/schema/member/has_directives.rb +5 -5
- data/lib/graphql/schema/member/has_fields.rb +121 -17
- data/lib/graphql/schema/member/has_interfaces.rb +27 -13
- data/lib/graphql/schema/member/has_unresolved_type_error.rb +5 -1
- data/lib/graphql/schema/member/has_validators.rb +1 -1
- data/lib/graphql/schema/member/relay_shortcuts.rb +1 -1
- data/lib/graphql/schema/member/scoped.rb +19 -0
- data/lib/graphql/schema/member/type_system_helpers.rb +18 -5
- data/lib/graphql/schema/member/validates_input.rb +3 -3
- data/lib/graphql/schema/member.rb +6 -0
- data/lib/graphql/schema/mutation.rb +7 -0
- data/lib/graphql/schema/non_null.rb +1 -1
- data/lib/graphql/schema/object.rb +34 -8
- data/lib/graphql/schema/printer.rb +9 -7
- data/lib/graphql/schema/ractor_shareable.rb +79 -0
- data/lib/graphql/schema/relay_classic_mutation.rb +6 -129
- data/lib/graphql/schema/resolver.rb +128 -32
- data/lib/graphql/schema/scalar.rb +4 -9
- data/lib/graphql/schema/subscription.rb +63 -12
- data/lib/graphql/schema/timeout.rb +19 -2
- data/lib/graphql/schema/type_expression.rb +2 -2
- data/lib/graphql/schema/union.rb +2 -2
- data/lib/graphql/schema/unique_within_type.rb +1 -1
- data/lib/graphql/schema/validator/all_validator.rb +62 -0
- data/lib/graphql/schema/validator/required_validator.rb +92 -11
- data/lib/graphql/schema/validator.rb +3 -1
- data/lib/graphql/schema/visibility/migration.rb +188 -0
- data/lib/graphql/schema/visibility/profile.rb +464 -0
- data/lib/graphql/schema/visibility/visit.rb +190 -0
- data/lib/graphql/schema/visibility.rb +311 -0
- data/lib/graphql/schema/warden.rb +275 -103
- data/lib/graphql/schema/wrapper.rb +7 -1
- data/lib/graphql/schema.rb +954 -212
- data/lib/graphql/static_validation/all_rules.rb +3 -3
- data/lib/graphql/static_validation/base_visitor.rb +96 -71
- data/lib/graphql/static_validation/literal_validator.rb +6 -7
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +2 -2
- data/lib/graphql/static_validation/rules/argument_names_are_unique.rb +18 -6
- data/lib/graphql/static_validation/rules/arguments_are_defined.rb +6 -2
- data/lib/graphql/static_validation/rules/directives_are_defined.rb +6 -3
- data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +2 -0
- data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +14 -3
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +59 -15
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +391 -262
- data/lib/graphql/static_validation/rules/fields_will_merge_error.rb +10 -2
- data/lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb +6 -6
- data/lib/graphql/static_validation/rules/fragment_types_exist.rb +15 -2
- data/lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb +1 -1
- data/lib/graphql/static_validation/rules/mutation_root_exists.rb +1 -1
- data/lib/graphql/static_validation/rules/no_definitions_are_present.rb +1 -1
- data/lib/graphql/static_validation/rules/not_single_subscription_error.rb +25 -0
- data/lib/graphql/static_validation/rules/query_root_exists.rb +1 -1
- data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +28 -8
- data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present.rb +5 -5
- data/lib/graphql/static_validation/rules/subscription_root_exists_and_single_subscription_selection.rb +26 -0
- data/lib/graphql/static_validation/rules/unique_directives_per_location.rb +7 -3
- data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +18 -27
- data/lib/graphql/static_validation/rules/variable_names_are_unique.rb +1 -1
- data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +2 -2
- data/lib/graphql/static_validation/rules/variables_are_input_types.rb +14 -2
- data/lib/graphql/static_validation/validation_context.rb +22 -6
- data/lib/graphql/static_validation/validator.rb +9 -1
- data/lib/graphql/static_validation.rb +0 -1
- data/lib/graphql/subscriptions/action_cable_subscriptions.rb +8 -5
- data/lib/graphql/subscriptions/broadcast_analyzer.rb +11 -5
- data/lib/graphql/subscriptions/default_subscription_resolve_extension.rb +45 -19
- data/lib/graphql/subscriptions/event.rb +22 -4
- data/lib/graphql/subscriptions/serialize.rb +3 -1
- data/lib/graphql/subscriptions.rb +56 -17
- data/lib/graphql/testing/helpers.rb +161 -0
- data/lib/graphql/testing/mock_action_cable.rb +111 -0
- data/lib/graphql/testing.rb +3 -0
- data/lib/graphql/tracing/active_support_notifications_trace.rb +14 -3
- data/lib/graphql/tracing/active_support_notifications_tracing.rb +1 -1
- data/lib/graphql/tracing/appoptics_trace.rb +11 -3
- data/lib/graphql/tracing/appoptics_tracing.rb +9 -2
- data/lib/graphql/tracing/appsignal_trace.rb +32 -55
- data/lib/graphql/tracing/appsignal_tracing.rb +2 -0
- data/lib/graphql/tracing/call_legacy_tracers.rb +66 -0
- data/lib/graphql/tracing/data_dog_trace.rb +46 -158
- data/lib/graphql/tracing/data_dog_tracing.rb +2 -0
- data/lib/graphql/tracing/detailed_trace/active_record_backend.rb +74 -0
- data/lib/graphql/tracing/detailed_trace/memory_backend.rb +60 -0
- data/lib/graphql/tracing/detailed_trace/redis_backend.rb +72 -0
- data/lib/graphql/tracing/detailed_trace.rb +156 -0
- data/lib/graphql/tracing/legacy_hooks_trace.rb +75 -0
- data/lib/graphql/tracing/legacy_trace.rb +4 -61
- data/lib/graphql/tracing/monitor_trace.rb +283 -0
- data/lib/graphql/tracing/new_relic_trace.rb +47 -54
- data/lib/graphql/tracing/new_relic_tracing.rb +2 -0
- data/lib/graphql/tracing/notifications_trace.rb +184 -34
- data/lib/graphql/tracing/notifications_tracing.rb +2 -0
- data/lib/graphql/tracing/null_trace.rb +9 -0
- data/lib/graphql/tracing/perfetto_trace/trace.proto +141 -0
- data/lib/graphql/tracing/perfetto_trace/trace_pb.rb +33 -0
- data/lib/graphql/tracing/perfetto_trace.rb +864 -0
- data/lib/graphql/tracing/platform_trace.rb +5 -0
- data/lib/graphql/tracing/platform_tracing.rb +3 -1
- data/lib/graphql/tracing/{prometheus_tracing → prometheus_trace}/graphql_collector.rb +5 -1
- data/lib/graphql/tracing/prometheus_trace.rb +72 -68
- data/lib/graphql/tracing/prometheus_tracing.rb +2 -0
- data/lib/graphql/tracing/scout_trace.rb +32 -55
- data/lib/graphql/tracing/scout_tracing.rb +2 -0
- data/lib/graphql/tracing/sentry_trace.rb +82 -0
- data/lib/graphql/tracing/statsd_trace.rb +33 -41
- data/lib/graphql/tracing/statsd_tracing.rb +2 -0
- data/lib/graphql/tracing/trace.rb +118 -1
- data/lib/graphql/tracing.rb +31 -28
- data/lib/graphql/type_kinds.rb +2 -1
- data/lib/graphql/types/iso_8601_duration.rb +77 -0
- data/lib/graphql/types/relay/connection_behaviors.rb +45 -3
- data/lib/graphql/types/relay/edge_behaviors.rb +19 -1
- data/lib/graphql/types/relay/has_node_field.rb +13 -8
- data/lib/graphql/types/relay/has_nodes_field.rb +13 -8
- data/lib/graphql/types/relay/node_behaviors.rb +13 -2
- data/lib/graphql/types/relay/page_info_behaviors.rb +4 -0
- data/lib/graphql/types.rb +18 -10
- data/lib/graphql/unauthorized_enum_value_error.rb +13 -0
- data/lib/graphql/unauthorized_error.rb +9 -1
- data/lib/graphql/version.rb +1 -1
- data/lib/graphql.rb +69 -54
- data/readme.md +12 -2
- metadata +236 -40
- data/lib/graphql/analysis/ast/analyzer.rb +0 -84
- data/lib/graphql/analysis/ast/field_usage.rb +0 -57
- data/lib/graphql/analysis/ast/max_query_complexity.rb +0 -22
- data/lib/graphql/analysis/ast/max_query_depth.rb +0 -22
- data/lib/graphql/analysis/ast/query_complexity.rb +0 -230
- data/lib/graphql/analysis/ast/query_depth.rb +0 -55
- data/lib/graphql/analysis/ast/visitor.rb +0 -276
- data/lib/graphql/analysis/ast.rb +0 -81
- data/lib/graphql/backtrace/inspect_result.rb +0 -50
- data/lib/graphql/backtrace/trace.rb +0 -96
- data/lib/graphql/backtrace/tracer.rb +0 -80
- data/lib/graphql/deprecation.rb +0 -9
- data/lib/graphql/filter.rb +0 -59
- data/lib/graphql/language/parser.y +0 -560
- data/lib/graphql/language/token.rb +0 -34
- data/lib/graphql/schema/base_64_bp.rb +0 -26
- data/lib/graphql/schema/invalid_type_error.rb +0 -7
- data/lib/graphql/schema/null_mask.rb +0 -11
- data/lib/graphql/static_validation/rules/subscription_root_exists.rb +0 -17
- data/lib/graphql/static_validation/type_stack.rb +0 -216
- data/lib/graphql/subscriptions/instrumentation.rb +0 -28
|
@@ -2,31 +2,40 @@
|
|
|
2
2
|
module GraphQL
|
|
3
3
|
# Raised automatically when a field's resolve function returns `nil`
|
|
4
4
|
# for a non-null field.
|
|
5
|
-
class InvalidNullError < GraphQL::
|
|
5
|
+
class InvalidNullError < GraphQL::RuntimeError
|
|
6
6
|
# @return [GraphQL::BaseType] The owner of {#field}
|
|
7
7
|
attr_reader :parent_type
|
|
8
8
|
|
|
9
9
|
# @return [GraphQL::Field] The field which failed to return a value
|
|
10
10
|
attr_reader :field
|
|
11
11
|
|
|
12
|
-
# @return [
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
def initialize(parent_type, field, value)
|
|
16
|
-
@parent_type = parent_type
|
|
17
|
-
@field = field
|
|
18
|
-
@value = value
|
|
19
|
-
super("Cannot return null for non-nullable field #{@parent_type.graphql_name}.#{@field.graphql_name}")
|
|
12
|
+
# @return [GraphQL::Language::Nodes::Field] the field where the error occurred
|
|
13
|
+
def ast_node
|
|
14
|
+
@ast_nodes.first
|
|
20
15
|
end
|
|
21
16
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
attr_reader :ast_nodes
|
|
18
|
+
|
|
19
|
+
# @return [Boolean] indicates an array result caused the error
|
|
20
|
+
attr_reader :is_from_array
|
|
26
21
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
attr_accessor :path
|
|
23
|
+
|
|
24
|
+
def initialize(parent_type, field, ast_node_or_nodes, is_from_array: false, path: nil)
|
|
25
|
+
@parent_type = parent_type
|
|
26
|
+
@field = field
|
|
27
|
+
@ast_nodes = Array(ast_node_or_nodes)
|
|
28
|
+
@is_from_array = is_from_array
|
|
29
|
+
@path = path
|
|
30
|
+
# For List elements, identify the non-null error is for an
|
|
31
|
+
# element and the required element type so it's not ambiguous
|
|
32
|
+
# whether it was caused by a null instead of the list or a
|
|
33
|
+
# null element.
|
|
34
|
+
if @is_from_array
|
|
35
|
+
super("Cannot return null for non-nullable element of type '#{@field.type.of_type.of_type.to_type_signature}' for #{@parent_type.graphql_name}.#{@field.graphql_name}")
|
|
36
|
+
else
|
|
37
|
+
super("Cannot return null for non-nullable field #{@parent_type.graphql_name}.#{@field.graphql_name}")
|
|
38
|
+
end
|
|
30
39
|
end
|
|
31
40
|
|
|
32
41
|
class << self
|
|
@@ -39,7 +48,7 @@ module GraphQL
|
|
|
39
48
|
end
|
|
40
49
|
|
|
41
50
|
def inspect
|
|
42
|
-
if (name.nil? || parent_class
|
|
51
|
+
if (name.nil? || parent_class&.name.nil?) && parent_class.respond_to?(:mutation) && (mutation = parent_class.mutation)
|
|
43
52
|
"#{mutation.inspect}::#{parent_class.graphql_name}::InvalidNullError"
|
|
44
53
|
else
|
|
45
54
|
super
|
|
@@ -47,10 +47,10 @@ module GraphQL
|
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
# Remove leading & trailing blank lines
|
|
50
|
-
while lines.size > 0 && lines
|
|
50
|
+
while lines.size > 0 && contains_only_whitespace?(lines.first)
|
|
51
51
|
lines.shift
|
|
52
52
|
end
|
|
53
|
-
while lines.size > 0 && lines
|
|
53
|
+
while lines.size > 0 && contains_only_whitespace?(lines.last)
|
|
54
54
|
lines.pop
|
|
55
55
|
end
|
|
56
56
|
|
|
@@ -59,40 +59,56 @@ module GraphQL
|
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
def self.print(str, indent: '')
|
|
62
|
-
|
|
62
|
+
line_length = 120 - indent.length
|
|
63
|
+
block_str = "".dup
|
|
64
|
+
triple_quotes = "\"\"\"\n"
|
|
65
|
+
block_str << indent
|
|
66
|
+
block_str << triple_quotes
|
|
63
67
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
if str.include?("\n")
|
|
69
|
+
str.split("\n") do |line|
|
|
70
|
+
if line == ''
|
|
71
|
+
block_str << "\n"
|
|
72
|
+
else
|
|
73
|
+
break_line(line, line_length) do |subline|
|
|
74
|
+
block_str << indent
|
|
75
|
+
block_str << subline
|
|
76
|
+
block_str << "\n"
|
|
77
|
+
end
|
|
73
78
|
end
|
|
74
79
|
end
|
|
80
|
+
else
|
|
81
|
+
break_line(str, line_length) do |subline|
|
|
82
|
+
block_str << indent
|
|
83
|
+
block_str << subline
|
|
84
|
+
block_str << "\n"
|
|
85
|
+
end
|
|
75
86
|
end
|
|
76
87
|
|
|
77
|
-
block_str <<
|
|
88
|
+
block_str << indent
|
|
89
|
+
block_str << triple_quotes
|
|
78
90
|
end
|
|
79
91
|
|
|
80
92
|
private
|
|
81
93
|
|
|
82
94
|
def self.break_line(line, length)
|
|
83
|
-
return
|
|
95
|
+
return yield(line) if line.length < length + 5
|
|
84
96
|
|
|
85
97
|
parts = line.split(Regexp.new("((?: |^).{15,#{length - 40}}(?= |$))"))
|
|
86
|
-
return
|
|
98
|
+
return yield(line) if parts.length < 4
|
|
87
99
|
|
|
88
|
-
|
|
100
|
+
yield(parts.slice!(0, 3).join)
|
|
89
101
|
|
|
90
102
|
parts.each_with_index do |part, i|
|
|
91
103
|
next if i % 2 == 1
|
|
92
|
-
|
|
104
|
+
yield "#{part[1..-1]}#{parts[i + 1]}"
|
|
93
105
|
end
|
|
94
106
|
|
|
95
|
-
|
|
107
|
+
nil
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def self.contains_only_whitespace?(line)
|
|
111
|
+
line.match?(/^\s*$/)
|
|
96
112
|
end
|
|
97
113
|
end
|
|
98
114
|
end
|
|
@@ -5,12 +5,25 @@ require 'digest/sha2'
|
|
|
5
5
|
|
|
6
6
|
module GraphQL
|
|
7
7
|
module Language
|
|
8
|
+
# This cache is used by {GraphQL::Language::Parser.parse_file} when it's enabled.
|
|
9
|
+
#
|
|
10
|
+
# With Rails, parser caching may enabled by setting `config.graphql.parser_cache = true` in your Rails application.
|
|
11
|
+
#
|
|
12
|
+
# The cache may be manually built by assigning `GraphQL::Language::Parser.cache = GraphQL::Language::Cache.new("some_dir")`.
|
|
13
|
+
# This will create a directory (`tmp/cache/graphql` by default) that stores a cache of parsed files.
|
|
14
|
+
#
|
|
15
|
+
# Much like [bootsnap](https://github.com/Shopify/bootsnap), the parser cache needs to be cleaned up manually.
|
|
16
|
+
# You will need to clear the cache directory for each new deployment of your application.
|
|
17
|
+
# Also note that the parser cache will grow as your schema is loaded, so the cache directory must be writable.
|
|
18
|
+
#
|
|
19
|
+
# @see GraphQL::Railtie for simple Rails integration
|
|
8
20
|
class Cache
|
|
9
21
|
def initialize(path)
|
|
10
22
|
@path = path
|
|
11
23
|
end
|
|
12
24
|
|
|
13
25
|
DIGEST = Digest::SHA256.new << GraphQL::VERSION
|
|
26
|
+
|
|
14
27
|
def fetch(filename)
|
|
15
28
|
hash = DIGEST.dup << filename
|
|
16
29
|
begin
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module GraphQL
|
|
3
|
+
module Language
|
|
4
|
+
module Comment
|
|
5
|
+
def self.print(str, indent: '')
|
|
6
|
+
lines = str.split("\n").map do |line|
|
|
7
|
+
comment_str = "".dup
|
|
8
|
+
comment_str << indent
|
|
9
|
+
comment_str << "# "
|
|
10
|
+
comment_str << line
|
|
11
|
+
comment_str.rstrip
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
lines.join("\n") + "\n"
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -14,35 +14,19 @@ module GraphQL
|
|
|
14
14
|
# @param include_built_in_directives [Boolean] Whether or not to include built in directives in the AST
|
|
15
15
|
class DocumentFromSchemaDefinition
|
|
16
16
|
def initialize(
|
|
17
|
-
schema, context: nil,
|
|
17
|
+
schema, context: nil, include_introspection_types: false,
|
|
18
18
|
include_built_in_directives: false, include_built_in_scalars: false, always_include_schema: false
|
|
19
19
|
)
|
|
20
20
|
@schema = schema
|
|
21
|
+
@context = context
|
|
21
22
|
@always_include_schema = always_include_schema
|
|
22
23
|
@include_introspection_types = include_introspection_types
|
|
23
24
|
@include_built_in_scalars = include_built_in_scalars
|
|
24
25
|
@include_built_in_directives = include_built_in_directives
|
|
25
26
|
@include_one_of = false
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
@warden = if only || except
|
|
30
|
-
filter = GraphQL::Filter
|
|
31
|
-
.new(only: only, except: except)
|
|
32
|
-
.merge(only: @schema.method(:visible?))
|
|
33
|
-
GraphQL::Schema::Warden.new(
|
|
34
|
-
filter,
|
|
35
|
-
schema: @schema,
|
|
36
|
-
context: schema_context,
|
|
37
|
-
)
|
|
38
|
-
else
|
|
39
|
-
@schema.warden_class.new(
|
|
40
|
-
schema: @schema,
|
|
41
|
-
context: schema_context,
|
|
42
|
-
)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
schema_context.warden = @warden
|
|
28
|
+
dummy_query = @schema.query_class.new(@schema, "{ __typename }", validate: false, context: context)
|
|
29
|
+
@types = dummy_query.types # rubocop:disable Development/ContextIsPassedCop
|
|
46
30
|
end
|
|
47
31
|
|
|
48
32
|
def document
|
|
@@ -52,25 +36,33 @@ module GraphQL
|
|
|
52
36
|
end
|
|
53
37
|
|
|
54
38
|
def build_schema_node
|
|
55
|
-
schema_options = {
|
|
56
|
-
# `@schema.directives` is covered by `build_definition_nodes`
|
|
57
|
-
directives: definition_directives(@schema, :schema_directives),
|
|
58
|
-
}
|
|
59
39
|
if !schema_respects_root_name_conventions?(@schema)
|
|
60
|
-
|
|
61
|
-
query:
|
|
62
|
-
mutation:
|
|
63
|
-
subscription:
|
|
64
|
-
|
|
40
|
+
GraphQL::Language::Nodes::SchemaDefinition.new(
|
|
41
|
+
query: @types.query_root&.graphql_name,
|
|
42
|
+
mutation: @types.mutation_root&.graphql_name,
|
|
43
|
+
subscription: @types.subscription_root&.graphql_name,
|
|
44
|
+
directives: definition_directives(@schema, :schema_directives)
|
|
45
|
+
)
|
|
46
|
+
else
|
|
47
|
+
# A plain `schema ...` _must_ include root type definitions.
|
|
48
|
+
# If the only difference is directives, then you have to use `extend schema`
|
|
49
|
+
GraphQL::Language::Nodes::SchemaExtension.new(directives: definition_directives(@schema, :schema_directives))
|
|
65
50
|
end
|
|
66
|
-
GraphQL::Language::Nodes::SchemaDefinition.new(schema_options)
|
|
67
51
|
end
|
|
68
52
|
|
|
69
53
|
def build_object_type_node(object_type)
|
|
54
|
+
ints = @types.interfaces(object_type)
|
|
55
|
+
|
|
56
|
+
if !ints.empty?
|
|
57
|
+
ints = ints.sort_by(&:graphql_name)
|
|
58
|
+
ints.map! { |iface| build_type_name_node(iface) }
|
|
59
|
+
end
|
|
60
|
+
|
|
70
61
|
GraphQL::Language::Nodes::ObjectTypeDefinition.new(
|
|
71
62
|
name: object_type.graphql_name,
|
|
72
|
-
|
|
73
|
-
|
|
63
|
+
comment: object_type.comment,
|
|
64
|
+
interfaces: ints,
|
|
65
|
+
fields: build_field_nodes(@types.fields(object_type)),
|
|
74
66
|
description: object_type.description,
|
|
75
67
|
directives: directives(object_type),
|
|
76
68
|
)
|
|
@@ -79,7 +71,8 @@ module GraphQL
|
|
|
79
71
|
def build_field_node(field)
|
|
80
72
|
GraphQL::Language::Nodes::FieldDefinition.new(
|
|
81
73
|
name: field.graphql_name,
|
|
82
|
-
|
|
74
|
+
comment: field.comment,
|
|
75
|
+
arguments: build_argument_nodes(@types.arguments(field)),
|
|
83
76
|
type: build_type_name_node(field.type),
|
|
84
77
|
description: field.description,
|
|
85
78
|
directives: directives(field),
|
|
@@ -89,8 +82,9 @@ module GraphQL
|
|
|
89
82
|
def build_union_type_node(union_type)
|
|
90
83
|
GraphQL::Language::Nodes::UnionTypeDefinition.new(
|
|
91
84
|
name: union_type.graphql_name,
|
|
85
|
+
comment: union_type.comment,
|
|
92
86
|
description: union_type.description,
|
|
93
|
-
types:
|
|
87
|
+
types: @types.possible_types(union_type).sort_by(&:graphql_name).map { |type| build_type_name_node(type) },
|
|
94
88
|
directives: directives(union_type),
|
|
95
89
|
)
|
|
96
90
|
end
|
|
@@ -98,9 +92,10 @@ module GraphQL
|
|
|
98
92
|
def build_interface_type_node(interface_type)
|
|
99
93
|
GraphQL::Language::Nodes::InterfaceTypeDefinition.new(
|
|
100
94
|
name: interface_type.graphql_name,
|
|
101
|
-
|
|
95
|
+
comment: interface_type.comment,
|
|
96
|
+
interfaces: @types.interfaces(interface_type).sort_by(&:graphql_name).map { |type| build_type_name_node(type) },
|
|
102
97
|
description: interface_type.description,
|
|
103
|
-
fields: build_field_nodes(
|
|
98
|
+
fields: build_field_nodes(@types.fields(interface_type)),
|
|
104
99
|
directives: directives(interface_type),
|
|
105
100
|
)
|
|
106
101
|
end
|
|
@@ -108,7 +103,8 @@ module GraphQL
|
|
|
108
103
|
def build_enum_type_node(enum_type)
|
|
109
104
|
GraphQL::Language::Nodes::EnumTypeDefinition.new(
|
|
110
105
|
name: enum_type.graphql_name,
|
|
111
|
-
|
|
106
|
+
comment: enum_type.comment,
|
|
107
|
+
values: @types.enum_values(enum_type).sort_by(&:graphql_name).map do |enum_value|
|
|
112
108
|
build_enum_value_node(enum_value)
|
|
113
109
|
end,
|
|
114
110
|
description: enum_type.description,
|
|
@@ -119,6 +115,7 @@ module GraphQL
|
|
|
119
115
|
def build_enum_value_node(enum_value)
|
|
120
116
|
GraphQL::Language::Nodes::EnumValueDefinition.new(
|
|
121
117
|
name: enum_value.graphql_name,
|
|
118
|
+
comment: enum_value.comment,
|
|
122
119
|
description: enum_value.description,
|
|
123
120
|
directives: directives(enum_value),
|
|
124
121
|
)
|
|
@@ -127,6 +124,7 @@ module GraphQL
|
|
|
127
124
|
def build_scalar_type_node(scalar_type)
|
|
128
125
|
GraphQL::Language::Nodes::ScalarTypeDefinition.new(
|
|
129
126
|
name: scalar_type.graphql_name,
|
|
127
|
+
comment: scalar_type.comment,
|
|
130
128
|
description: scalar_type.description,
|
|
131
129
|
directives: directives(scalar_type),
|
|
132
130
|
)
|
|
@@ -141,6 +139,7 @@ module GraphQL
|
|
|
141
139
|
|
|
142
140
|
argument_node = GraphQL::Language::Nodes::InputValueDefinition.new(
|
|
143
141
|
name: argument.graphql_name,
|
|
142
|
+
comment: argument.comment,
|
|
144
143
|
description: argument.description,
|
|
145
144
|
type: build_type_name_node(argument.type),
|
|
146
145
|
default_value: default_value,
|
|
@@ -153,7 +152,8 @@ module GraphQL
|
|
|
153
152
|
def build_input_object_node(input_object)
|
|
154
153
|
GraphQL::Language::Nodes::InputObjectTypeDefinition.new(
|
|
155
154
|
name: input_object.graphql_name,
|
|
156
|
-
|
|
155
|
+
comment: input_object.comment,
|
|
156
|
+
fields: build_argument_nodes(@types.arguments(input_object)),
|
|
157
157
|
description: input_object.description,
|
|
158
158
|
directives: directives(input_object),
|
|
159
159
|
)
|
|
@@ -163,7 +163,7 @@ module GraphQL
|
|
|
163
163
|
GraphQL::Language::Nodes::DirectiveDefinition.new(
|
|
164
164
|
name: directive.graphql_name,
|
|
165
165
|
repeatable: directive.repeatable?,
|
|
166
|
-
arguments: build_argument_nodes(
|
|
166
|
+
arguments: build_argument_nodes(@types.arguments(directive)),
|
|
167
167
|
locations: build_directive_location_nodes(directive.locations),
|
|
168
168
|
description: directive.description,
|
|
169
169
|
)
|
|
@@ -190,7 +190,8 @@ module GraphQL
|
|
|
190
190
|
of_type: build_type_name_node(type.of_type)
|
|
191
191
|
)
|
|
192
192
|
else
|
|
193
|
-
|
|
193
|
+
@cached_type_name_nodes ||= {}
|
|
194
|
+
@cached_type_name_nodes[type.graphql_name] ||= GraphQL::Language::Nodes::TypeName.new(name: type.graphql_name)
|
|
194
195
|
end
|
|
195
196
|
end
|
|
196
197
|
|
|
@@ -207,7 +208,7 @@ module GraphQL
|
|
|
207
208
|
when "INPUT_OBJECT"
|
|
208
209
|
GraphQL::Language::Nodes::InputObject.new(
|
|
209
210
|
arguments: default_value.to_h.map do |arg_name, arg_value|
|
|
210
|
-
args = @
|
|
211
|
+
args = @types.arguments(type)
|
|
211
212
|
arg = args.find { |a| a.keyword.to_s == arg_name.to_s }
|
|
212
213
|
if arg.nil?
|
|
213
214
|
raise ArgumentError, "No argument definition on #{type.graphql_name} for argument: #{arg_name.inspect} (expected one of: #{args.map(&:keyword)})"
|
|
@@ -247,9 +248,13 @@ module GraphQL
|
|
|
247
248
|
end
|
|
248
249
|
|
|
249
250
|
def build_argument_nodes(arguments)
|
|
250
|
-
arguments
|
|
251
|
-
.map { |arg| build_argument_node(arg) }
|
|
252
|
-
.sort_by(&:name)
|
|
251
|
+
if !arguments.empty?
|
|
252
|
+
nodes = arguments.map { |arg| build_argument_node(arg) }
|
|
253
|
+
nodes.sort_by!(&:name)
|
|
254
|
+
nodes
|
|
255
|
+
else
|
|
256
|
+
arguments
|
|
257
|
+
end
|
|
253
258
|
end
|
|
254
259
|
|
|
255
260
|
def build_directive_nodes(directives)
|
|
@@ -259,20 +264,45 @@ module GraphQL
|
|
|
259
264
|
end
|
|
260
265
|
|
|
261
266
|
def build_definition_nodes
|
|
262
|
-
dirs_to_build =
|
|
267
|
+
dirs_to_build = @types.directives
|
|
263
268
|
if !include_built_in_directives
|
|
264
269
|
dirs_to_build = dirs_to_build.reject { |directive| directive.default_directive? }
|
|
265
270
|
end
|
|
266
|
-
|
|
271
|
+
definitions = build_directive_nodes(dirs_to_build)
|
|
272
|
+
all_types = @types.all_types
|
|
273
|
+
type_nodes = build_type_definition_nodes(all_types)
|
|
274
|
+
|
|
275
|
+
if !(ex_t = schema.extra_types).empty?
|
|
276
|
+
dummy_query = Class.new(GraphQL::Schema::Object) do
|
|
277
|
+
graphql_name "DummyQuery"
|
|
278
|
+
(all_types + ex_t).each_with_index do |type, idx|
|
|
279
|
+
if !type.kind.input_object? && !type.introspection?
|
|
280
|
+
field "f#{idx}", type
|
|
281
|
+
end
|
|
282
|
+
end
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
extra_types_schema = Class.new(GraphQL::Schema) do
|
|
286
|
+
query(dummy_query)
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
extra_types_types = GraphQL::Query.new(extra_types_schema, "{ __typename }", context: @context).types # rubocop:disable Development/ContextIsPassedCop
|
|
290
|
+
# Temporarily replace `@types` with something from this example schema.
|
|
291
|
+
# It'd be much nicer to pass this in, but that would be a big refactor :S
|
|
292
|
+
prev_types = @types
|
|
293
|
+
@types = extra_types_types
|
|
294
|
+
type_nodes += build_type_definition_nodes(ex_t)
|
|
295
|
+
@types = prev_types
|
|
296
|
+
end
|
|
267
297
|
|
|
268
|
-
type_nodes
|
|
298
|
+
type_nodes.sort_by!(&:name)
|
|
269
299
|
|
|
270
300
|
if @include_one_of
|
|
271
301
|
# This may have been set to true when iterating over all types
|
|
272
|
-
|
|
302
|
+
definitions.concat(build_directive_nodes([GraphQL::Schema::Directive::OneOf]))
|
|
273
303
|
end
|
|
274
304
|
|
|
275
|
-
definitions
|
|
305
|
+
definitions.concat(type_nodes)
|
|
276
306
|
if include_schema_node?
|
|
277
307
|
definitions.unshift(build_schema_node)
|
|
278
308
|
end
|
|
@@ -289,15 +319,13 @@ module GraphQL
|
|
|
289
319
|
types = types.reject { |type| type.kind.scalar? && type.default_scalar? }
|
|
290
320
|
end
|
|
291
321
|
|
|
292
|
-
types
|
|
293
|
-
.map { |type| build_type_definition_node(type) }
|
|
294
|
-
.sort_by(&:name)
|
|
322
|
+
types.map { |type| build_type_definition_node(type) }
|
|
295
323
|
end
|
|
296
324
|
|
|
297
325
|
def build_field_nodes(fields)
|
|
298
|
-
fields
|
|
299
|
-
|
|
300
|
-
|
|
326
|
+
f_nodes = fields.map { |field| build_field_node(field) }
|
|
327
|
+
f_nodes.sort_by!(&:name)
|
|
328
|
+
f_nodes
|
|
301
329
|
end
|
|
302
330
|
|
|
303
331
|
private
|
|
@@ -319,10 +347,11 @@ module GraphQL
|
|
|
319
347
|
end
|
|
320
348
|
|
|
321
349
|
def definition_directives(member, directives_method)
|
|
322
|
-
|
|
323
|
-
|
|
350
|
+
if !member.respond_to?(directives_method) || member.directives.empty?
|
|
351
|
+
EmptyObjects::EMPTY_ARRAY
|
|
324
352
|
else
|
|
325
|
-
member.public_send(directives_method).
|
|
353
|
+
visible_directives = member.public_send(directives_method).select { |dir| @types.directive_exists?(dir.graphql_name) }
|
|
354
|
+
visible_directives.map! do |dir|
|
|
326
355
|
args = []
|
|
327
356
|
dir.arguments.argument_values.each_value do |arg_value| # rubocop:disable Development/ContextIsPassedCop -- directive instance method
|
|
328
357
|
arg_defn = arg_value.definition
|
|
@@ -346,12 +375,12 @@ module GraphQL
|
|
|
346
375
|
arguments: args
|
|
347
376
|
)
|
|
348
377
|
end
|
|
349
|
-
end
|
|
350
378
|
|
|
351
|
-
|
|
379
|
+
visible_directives
|
|
380
|
+
end
|
|
352
381
|
end
|
|
353
382
|
|
|
354
|
-
attr_reader :schema, :
|
|
383
|
+
attr_reader :schema, :always_include_schema,
|
|
355
384
|
:include_introspection_types, :include_built_in_directives, :include_built_in_scalars
|
|
356
385
|
end
|
|
357
386
|
end
|