graphql 2.3.19 → 2.3.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/graphql/schema/enum.rb +2 -0
- data/lib/graphql/schema/input_object.rb +20 -7
- data/lib/graphql/schema.rb +115 -10
- data/lib/graphql/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 271275308827280721c8a7d93c7a06cdb086c21a3d3ddb1443c27e20567ceba1
|
4
|
+
data.tar.gz: 4a6e8749d13c45572b86cee56eb8078afc6e70a62caff64d3abcf57d42b0fbfe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e438382adc6974ff9cc323a076d94675422d8ec5ad5ca0d869421e5b278c9ffa55eb86f07074fa9479552ea17c50c4fc7fac27d630ad99f72977caad5b3adf39
|
7
|
+
data.tar.gz: d035be86b6070cee2aa2559a2567660a4b0847c93f1ab714691deec6f0a8d0eb468ebe1e89eefe33bb64d86ed2ad9fe769ef5b9e7d5fb1f2c9120f1047769fbe
|
data/lib/graphql/schema/enum.rb
CHANGED
@@ -133,12 +133,14 @@ module GraphQL
|
|
133
133
|
end
|
134
134
|
# Add a method access
|
135
135
|
method_name = argument_defn.keyword
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
136
|
+
suppress_redefinition_warning do
|
137
|
+
class_eval <<-RUBY, __FILE__, __LINE__
|
138
|
+
def #{method_name}
|
139
|
+
self[#{method_name.inspect}]
|
140
|
+
end
|
141
|
+
alias_method :#{method_name}, :#{method_name}
|
142
|
+
RUBY
|
143
|
+
end
|
142
144
|
argument_defn
|
143
145
|
end
|
144
146
|
|
@@ -163,7 +165,7 @@ module GraphQL
|
|
163
165
|
|
164
166
|
# Inject missing required arguments
|
165
167
|
missing_required_inputs = ctx.types.arguments(self).reduce({}) do |m, (argument)|
|
166
|
-
if !input.key?(argument.graphql_name) && argument.type.non_null? && types.argument(self, argument.graphql_name)
|
168
|
+
if !input.key?(argument.graphql_name) && argument.type.non_null? && !argument.default_value? && types.argument(self, argument.graphql_name)
|
167
169
|
m[argument.graphql_name] = nil
|
168
170
|
end
|
169
171
|
|
@@ -243,6 +245,17 @@ module GraphQL
|
|
243
245
|
|
244
246
|
result
|
245
247
|
end
|
248
|
+
|
249
|
+
private
|
250
|
+
|
251
|
+
# Suppress redefinition warning for objectId arguments
|
252
|
+
def suppress_redefinition_warning
|
253
|
+
verbose = $VERBOSE
|
254
|
+
$VERBOSE = nil
|
255
|
+
yield
|
256
|
+
ensure
|
257
|
+
$VERBOSE = verbose
|
258
|
+
end
|
246
259
|
end
|
247
260
|
|
248
261
|
private
|
data/lib/graphql/schema.rb
CHANGED
@@ -431,6 +431,14 @@ module GraphQL
|
|
431
431
|
end
|
432
432
|
end
|
433
433
|
|
434
|
+
# Get or set the root `query { ... }` object for this schema.
|
435
|
+
#
|
436
|
+
# @example Using `Types::Query` as the entry-point
|
437
|
+
# query { Types::Query }
|
438
|
+
#
|
439
|
+
# @param new_query_object [Class<GraphQL::Schema::Object>] The root type to use for queries
|
440
|
+
# @param lazy_load_block If a block is given, then it will be called when GraphQL-Ruby needs the root query type.
|
441
|
+
# @return [Class<GraphQL::Schema::Object>, nil] The configured query root type, if there is one.
|
434
442
|
def query(new_query_object = nil, &lazy_load_block)
|
435
443
|
if new_query_object || block_given?
|
436
444
|
if @query_object
|
@@ -450,6 +458,14 @@ module GraphQL
|
|
450
458
|
end
|
451
459
|
end
|
452
460
|
|
461
|
+
# Get or set the root `mutation { ... }` object for this schema.
|
462
|
+
#
|
463
|
+
# @example Using `Types::Mutation` as the entry-point
|
464
|
+
# mutation { Types::Mutation }
|
465
|
+
#
|
466
|
+
# @param new_mutation_object [Class<GraphQL::Schema::Object>] The root type to use for mutations
|
467
|
+
# @param lazy_load_block If a block is given, then it will be called when GraphQL-Ruby needs the root mutation type.
|
468
|
+
# @return [Class<GraphQL::Schema::Object>, nil] The configured mutation root type, if there is one.
|
453
469
|
def mutation(new_mutation_object = nil, &lazy_load_block)
|
454
470
|
if new_mutation_object || block_given?
|
455
471
|
if @mutation_object
|
@@ -469,6 +485,14 @@ module GraphQL
|
|
469
485
|
end
|
470
486
|
end
|
471
487
|
|
488
|
+
# Get or set the root `subscription { ... }` object for this schema.
|
489
|
+
#
|
490
|
+
# @example Using `Types::Subscription` as the entry-point
|
491
|
+
# subscription { Types::Subscription }
|
492
|
+
#
|
493
|
+
# @param new_subscription_object [Class<GraphQL::Schema::Object>] The root type to use for subscriptions
|
494
|
+
# @param lazy_load_block If a block is given, then it will be called when GraphQL-Ruby needs the root subscription type.
|
495
|
+
# @return [Class<GraphQL::Schema::Object>, nil] The configured subscription root type, if there is one.
|
472
496
|
def subscription(new_subscription_object = nil, &lazy_load_block)
|
473
497
|
if new_subscription_object || block_given?
|
474
498
|
if @subscription_object
|
@@ -492,8 +516,7 @@ module GraphQL
|
|
492
516
|
end
|
493
517
|
end
|
494
518
|
|
495
|
-
# @
|
496
|
-
# @return [GraphQL::ObjectType, nil]
|
519
|
+
# @api private
|
497
520
|
def root_type_for_operation(operation)
|
498
521
|
case operation
|
499
522
|
when "query"
|
@@ -507,6 +530,7 @@ module GraphQL
|
|
507
530
|
end
|
508
531
|
end
|
509
532
|
|
533
|
+
# @return [Array<Class>] The root types (query, mutation, subscription) defined for this schema
|
510
534
|
def root_types
|
511
535
|
if use_visibility_profile?
|
512
536
|
[query, mutation, subscription].compact
|
@@ -515,6 +539,7 @@ module GraphQL
|
|
515
539
|
end
|
516
540
|
end
|
517
541
|
|
542
|
+
# @api private
|
518
543
|
def warden_class
|
519
544
|
if defined?(@warden_class)
|
520
545
|
@warden_class
|
@@ -525,6 +550,7 @@ module GraphQL
|
|
525
550
|
end
|
526
551
|
end
|
527
552
|
|
553
|
+
# @api private
|
528
554
|
attr_writer :warden_class
|
529
555
|
|
530
556
|
# @api private
|
@@ -786,6 +812,7 @@ module GraphQL
|
|
786
812
|
res[:errors]
|
787
813
|
end
|
788
814
|
|
815
|
+
# @param new_query_class [Class<GraphQL::Query>] A subclass to use when executing queries
|
789
816
|
def query_class(new_query_class = NOT_CONFIGURED)
|
790
817
|
if NOT_CONFIGURED.equal?(new_query_class)
|
791
818
|
@query_class || (superclass.respond_to?(:query_class) ? superclass.query_class : GraphQL::Query)
|
@@ -971,6 +998,8 @@ module GraphQL
|
|
971
998
|
end
|
972
999
|
end
|
973
1000
|
|
1001
|
+
|
1002
|
+
# @param new_default_logger [#log] Something to use for logging messages
|
974
1003
|
def default_logger(new_default_logger = NOT_CONFIGURED)
|
975
1004
|
if NOT_CONFIGURED.equal?(new_default_logger)
|
976
1005
|
if defined?(@default_logger)
|
@@ -991,6 +1020,7 @@ module GraphQL
|
|
991
1020
|
end
|
992
1021
|
end
|
993
1022
|
|
1023
|
+
# @param new_context_class [Class<GraphQL::Query::Context>] A subclass to use when executing queries
|
994
1024
|
def context_class(new_context_class = nil)
|
995
1025
|
if new_context_class
|
996
1026
|
@context_class = new_context_class
|
@@ -999,6 +1029,20 @@ module GraphQL
|
|
999
1029
|
end
|
1000
1030
|
end
|
1001
1031
|
|
1032
|
+
# Register a handler for errors raised during execution. The handlers can return a new value or raise a new error.
|
1033
|
+
#
|
1034
|
+
# @example Handling "not found" with a client-facing error
|
1035
|
+
# rescue_from(ActiveRecord::NotFound) { raise GraphQL::ExecutionError, "An object could not be found" }
|
1036
|
+
#
|
1037
|
+
# @param err_classes [Array<StandardError>] Classes which should be rescued by `handler_block`
|
1038
|
+
# @param handler_block The code to run when one of those errors is raised during execution
|
1039
|
+
# @yieldparam error [StandardError] An instance of one of the configured `err_classes`
|
1040
|
+
# @yieldparam object [Object] The current application object in the query when the error was raised
|
1041
|
+
# @yieldparam arguments [GraphQL::Query::Arguments] The current field arguments when the error was raised
|
1042
|
+
# @yieldparam context [GraphQL::Query::Context] The context for the currently-running operation
|
1043
|
+
# @yieldreturn [Object] Some object to use in the place where this error was raised
|
1044
|
+
# @raise [GraphQL::ExecutionError] In the handler, raise to add a client-facing error to the response
|
1045
|
+
# @raise [StandardError] In the handler, raise to crash the query with a developer-facing error
|
1002
1046
|
def rescue_from(*err_classes, &handler_block)
|
1003
1047
|
err_classes.each do |err_class|
|
1004
1048
|
Execution::Errors.register_rescue_from(err_class, error_handlers[:subclass_handlers], handler_block)
|
@@ -1065,8 +1109,24 @@ module GraphQL
|
|
1065
1109
|
end
|
1066
1110
|
end
|
1067
1111
|
|
1068
|
-
|
1069
|
-
|
1112
|
+
# GraphQL-Ruby calls this method during execution when it needs the application to determine the type to use for an object.
|
1113
|
+
#
|
1114
|
+
# Usually, this object was returned from a field whose return type is an {GraphQL::Schema::Interface} or a {GraphQL::Schema::Union}.
|
1115
|
+
# But this method is called in other cases, too -- for example, when {GraphQL::Schema::Argument.loads} cases an object to be directly loaded from the database.
|
1116
|
+
#
|
1117
|
+
# @example Returning a GraphQL type based on the object's class name
|
1118
|
+
# class MySchema < GraphQL::Schema
|
1119
|
+
# def resolve_type(_abs_type, object, _context)
|
1120
|
+
# graphql_type_name = "Types::#{object.class.name}Type"
|
1121
|
+
# graphql_type_name.constantize # If this raises a NameError, then come implement special cases in this method
|
1122
|
+
# end
|
1123
|
+
# end
|
1124
|
+
# @param abstract_type [Class, Module, nil] The Interface or Union type which is being resolved, if there is one
|
1125
|
+
# @param application_object [Object] The object returned from a field whose type must be determined
|
1126
|
+
# @param context [GraphQL::Query::Context] The query context for the currently-executing query
|
1127
|
+
# @return [Class<GraphQL::Schema::Object] The Object type definition to use for `obj`
|
1128
|
+
def resolve_type(abstract_type, application_object, context)
|
1129
|
+
raise GraphQL::RequiredImplementationMissingError, "#{self.name}.resolve_type(abstract_type, application_object, context) must be implemented to use Union types, Interface types, or `loads:` (tried to resolve: #{abstract_type.name})"
|
1070
1130
|
end
|
1071
1131
|
# rubocop:enable Lint/DuplicateMethods
|
1072
1132
|
|
@@ -1089,12 +1149,37 @@ module GraphQL
|
|
1089
1149
|
super
|
1090
1150
|
end
|
1091
1151
|
|
1092
|
-
|
1093
|
-
|
1094
|
-
|
1095
|
-
|
1096
|
-
def
|
1097
|
-
|
1152
|
+
# Fetch an object based on an incoming ID and the current context. This method should return an object
|
1153
|
+
# from your application, or return `nil` if there is no object or the object shouldn't be available to this operation.
|
1154
|
+
#
|
1155
|
+
# @example Fetching an object with Rails's GlobalID
|
1156
|
+
# def self.object_from_id(object_id, _context)
|
1157
|
+
# GlobalID.find(global_id)
|
1158
|
+
# # TODO: use `context[:current_user]` to determine if this object is authorized.
|
1159
|
+
# end
|
1160
|
+
# @param object_id [String] The ID to fetch an object for. This may be client-provided (as in `node(id: ...)` or `loads:`) or previously stored by the schema (eg, by the `ObjectCache`)
|
1161
|
+
# @param context [GraphQL::Query::Context] The context for the currently-executing operation
|
1162
|
+
# @return [Object, nil] The application which `object_id` references, or `nil` if there is no object or the current operation shouldn't have access to the object
|
1163
|
+
# @see id_from_object which produces these IDs
|
1164
|
+
def object_from_id(object_id, context)
|
1165
|
+
raise GraphQL::RequiredImplementationMissingError, "#{self.name}.object_from_id(object_id, context) must be implemented to load by ID (tried to load from id `#{node_id}`)"
|
1166
|
+
end
|
1167
|
+
|
1168
|
+
# Return a stable ID string for `object` so that it can be refetched later, using {.object_from_id}.
|
1169
|
+
#
|
1170
|
+
# {GlobalID}(https://github.com/rails/globalid) and {SQIDs}(https://sqids.org/ruby) can both be used to create IDs.
|
1171
|
+
#
|
1172
|
+
# @example Using Rails's GlobalID to generate IDs
|
1173
|
+
# def self.id_from_object(application_object, graphql_type, context)
|
1174
|
+
# application_object.to_gid_param
|
1175
|
+
# end
|
1176
|
+
#
|
1177
|
+
# @param application_object [Object] Some object encountered by GraphQL-Ruby while running a query
|
1178
|
+
# @param graphql_type [Class, Module] The type that GraphQL-Ruby is using for `application_object` during this query
|
1179
|
+
# @param context [GraphQL::Query::Context] The context for the operation that is currently running
|
1180
|
+
# @return [String] A stable identifier which can be passed to {.object_from_id} later to re-fetch `application_object`
|
1181
|
+
def id_from_object(application_object, graphql_type, context)
|
1182
|
+
raise GraphQL::RequiredImplementationMissingError, "#{self.name}.id_from_object(application_object, graphql_type, context) must be implemented to create global ids (tried to create an id for `#{application_object.inspect}`)"
|
1098
1183
|
end
|
1099
1184
|
|
1100
1185
|
def visible?(member, ctx)
|
@@ -1149,6 +1234,16 @@ module GraphQL
|
|
1149
1234
|
unauthorized_object(unauthorized_error)
|
1150
1235
|
end
|
1151
1236
|
|
1237
|
+
# Called at runtime when GraphQL-Ruby encounters a mismatch between the application behavior
|
1238
|
+
# and the GraphQL type system.
|
1239
|
+
#
|
1240
|
+
# The default implementation of this method is to follow the GraphQL specification,
|
1241
|
+
# but you can override this to report errors to your bug tracker or customize error handling.
|
1242
|
+
# @param type_error [GraphQL::Error] several specific error classes are passed here, see the default implementation for details
|
1243
|
+
# @param context [GraphQL::Query::Context] the context for the currently-running operation
|
1244
|
+
# @return [void]
|
1245
|
+
# @raise [GraphQL::ExecutionError] to return this error to the client
|
1246
|
+
# @raise [GraphQL::Error] to crash the query and raise a developer-facing error
|
1152
1247
|
def type_error(type_error, ctx)
|
1153
1248
|
case type_error
|
1154
1249
|
when GraphQL::InvalidNullError
|
@@ -1244,6 +1339,7 @@ module GraphQL
|
|
1244
1339
|
# @param mode [Symbol] Trace module will only be used for this trade mode
|
1245
1340
|
# @param options [Hash] Keywords that will be passed to the tracing class during `#initialize`
|
1246
1341
|
# @return [void]
|
1342
|
+
# @see GraphQL::Tracing::Trace for available tracing methods
|
1247
1343
|
def trace_with(trace_mod, mode: :default, **options)
|
1248
1344
|
if mode.is_a?(Array)
|
1249
1345
|
mode.each { |m| trace_with(trace_mod, mode: m, **options) }
|
@@ -1321,6 +1417,8 @@ module GraphQL
|
|
1321
1417
|
trace_class_for_mode.new(**trace_options)
|
1322
1418
|
end
|
1323
1419
|
|
1420
|
+
# @param new_analyzer [Class<GraphQL::Analysis::Analyzer>] An analyzer to run on queries to this schema
|
1421
|
+
# @see GraphQL::Analysis the analysis system
|
1324
1422
|
def query_analyzer(new_analyzer)
|
1325
1423
|
own_query_analyzers << new_analyzer
|
1326
1424
|
end
|
@@ -1329,6 +1427,8 @@ module GraphQL
|
|
1329
1427
|
find_inherited_value(:query_analyzers, EMPTY_ARRAY) + own_query_analyzers
|
1330
1428
|
end
|
1331
1429
|
|
1430
|
+
# @param new_analyzer [Class<GraphQL::Analysis::Analyzer>] An analyzer to run on multiplexes to this schema
|
1431
|
+
# @see GraphQL::Analysis the analysis system
|
1332
1432
|
def multiplex_analyzer(new_analyzer)
|
1333
1433
|
own_multiplex_analyzers << new_analyzer
|
1334
1434
|
end
|
@@ -1412,6 +1512,11 @@ module GraphQL
|
|
1412
1512
|
end
|
1413
1513
|
end
|
1414
1514
|
|
1515
|
+
# Called when execution encounters a `SystemStackError`. By default, it adds a client-facing error to the response.
|
1516
|
+
# You could modify this method to report this error to your bug tracker.
|
1517
|
+
# @param query [GraphQL::Query]
|
1518
|
+
# @param err [SystemStackError]
|
1519
|
+
# @return [void]
|
1415
1520
|
def query_stack_error(query, err)
|
1416
1521
|
query.context.errors.push(GraphQL::ExecutionError.new("This query is too large to execute."))
|
1417
1522
|
end
|
data/lib/graphql/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.3.
|
4
|
+
version: 2.3.20
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Mosolgo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: base64
|