Class: GraphQL::Schema::Field
- Inherits:
-
Object
- Object
- GraphQL::Schema::Field
- Extended by:
- FindInheritedValue
- Includes:
- GraphQL::Schema::FindInheritedValue::EmptyObjects, Member::AcceptsDefinition, Member::CachedGraphQLDefinition, Member::HasArguments, Member::HasAstNode, Member::HasDeprecationReason, Member::HasDirectives, Member::HasPath, Member::HasValidators
- Defined in:
- lib/graphql/schema/field.rb,
lib/graphql/schema/field/scope_extension.rb,
lib/graphql/schema/field/connection_extension.rb
Defined Under Namespace
Classes: ConnectionExtension, ScopeExtension
Constant Summary
Constants included from Member::HasDirectives
Member::HasDirectives::NO_DIRECTIVES
Constants included from GraphQL::Schema::FindInheritedValue::EmptyObjects
GraphQL::Schema::FindInheritedValue::EmptyObjects::EMPTY_ARRAY, GraphQL::Schema::FindInheritedValue::EmptyObjects::EMPTY_HASH
Constants included from Member::HasArguments
Member::HasArguments::NO_ARGUMENTS
Instance Attribute Summary collapse
-
#description(text = nil) ⇒ String
-
#max_page_size ⇒ Integer?
readonly
Applied to connections if #has_max_page_size?.
-
#method_str ⇒ String
readonly
Method or hash key on the underlying object to look up.
-
#method_sym ⇒ Symbol
readonly
Method or hash key on the underlying object to look up.
-
#name ⇒ String
(also: #graphql_name)
readonly
The GraphQL name for this field, camelized unless
camelize: false
is provided. -
#original_name ⇒ Symbol
readonly
The original name of the field, passed in by the user.
-
#owner ⇒ Class
The thing this field was defined on (type, mutation, resolver).
-
#relay_node_field ⇒ Object
readonly
Boolean.
-
#resolver_method ⇒ Symbol
readonly
The method on the type to look up.
-
#subscription_scope ⇒ String?
-
#trace ⇒ Boolean
readonly
Apply tracing to this field? (Default: skip scalars, this is the override value).
-
#type ⇒ Object
Class Method Summary collapse
-
.connection_extension(new_extension_class = nil) ⇒ Class
This extension is applied to fields when #connection? is true.
-
.from_options(name = nil, type = nil, desc = nil, resolver: nil, mutation: nil, subscription: nil, **kwargs, &block) ⇒ GraphQL::Schema:Field
Create a field instance from a list of arguments, keyword arguments, and a block.
Instance Method Summary collapse
-
#accessible?(context) ⇒ Boolean
-
#authorized?(object, args, context) ⇒ Boolean
-
#broadcastable? ⇒ Boolean?
If true, subscription updates with this field can be shared between viewers.
-
#complexity(new_complexity = nil) ⇒ Object
-
#connection? ⇒ Boolean
Can be set with
connection: true|false
or inferred from a type name ending in*Connection
. -
#extension(extension, options = nil) ⇒ Object
Add
extension
to this field, initialized withoptions
if provided. -
#extensions(new_extensions = nil) ⇒ Array<GraphQL::Schema::FieldExtension>
Read extension instances from this field, or add new classes/options to be initialized on this field.
-
#extras(new_extras = nil) ⇒ Array<Symbol>
Read extras (as symbols) from this field, or add new extras to be opted into by this field’s resolver.
-
#fetch_extra(extra_name, ctx) ⇒ Object
-
#has_max_page_size? ⇒ Boolean
True if this field’s #max_page_size should override the schema default.
-
#initialize(type: nil, name: nil, owner: nil, null: nil, field: nil, function: nil, description: nil, deprecation_reason: nil, method: nil, hash_key: nil, resolver_method: nil, resolve: nil, connection: nil, max_page_size: :not_given, scope: nil, introspection: false, camelize: true, trace: nil, complexity: 1, ast_node: nil, extras: EMPTY_ARRAY, extensions: EMPTY_ARRAY, connection_extension: self.class.connection_extension, resolver_class: nil, subscription_scope: nil, relay_node_field: false, relay_nodes_field: false, method_conflict_warning: true, broadcastable: nil, arguments: EMPTY_HASH, directives: EMPTY_HASH, validates: EMPTY_ARRAY, legacy_edge_class: nil, &definition_block) ⇒ Field
constructor
A new instance of Field.
-
#inspect ⇒ Object
-
#introspection? ⇒ Boolean
Is this field a predefined introspection field?.
-
#method_conflict_warning? ⇒ Boolean
Should we warn if this field’s name conflicts with a built-in method?.
-
#owner_type ⇒ Class
The GraphQL type this field belongs to.
-
#resolve(object, args, ctx) ⇒ Object
This method is called by the interpreter for each field.
-
#resolve_field(obj, args, ctx) ⇒ Object
Implement Field’s resolve API.
-
#resolver ⇒ Class?
(also: #mutation)
The Resolver this field was derived from, if there is one.
-
#scoped? ⇒ Boolean
If true, the return type’s
.scope_items
method will be applied to this field’s return value. -
#to_graphql ⇒ GraphQL::Field
-
#visible?(context) ⇒ Boolean
Methods included from Member::HasDeprecationReason
#deprecation_reason, #deprecation_reason=
Methods included from Member::HasDirectives
#directive, #directives, #remove_directive
Methods included from Member::HasValidators
Methods included from Member::HasPath
Methods included from Member::HasAstNode
Methods included from Member::HasArguments
#add_argument, #argument, #argument_class, #arguments, #arguments_statically_coercible?, #coerce_arguments, #get_argument, #own_arguments, #validate_directive_argument
Methods included from Member::CachedGraphQLDefinition
#graphql_definition, #initialize_copy, #type_class
Constructor Details
#initialize(type: nil, name: nil, owner: nil, null: nil, field: nil, function: nil, description: nil, deprecation_reason: nil, method: nil, hash_key: nil, resolver_method: nil, resolve: nil, connection: nil, max_page_size: :not_given, scope: nil, introspection: false, camelize: true, trace: nil, complexity: 1, ast_node: nil, extras: EMPTY_ARRAY, extensions: EMPTY_ARRAY, connection_extension: self.class.connection_extension, resolver_class: nil, subscription_scope: nil, relay_node_field: false, relay_nodes_field: false, method_conflict_warning: true, broadcastable: nil, arguments: EMPTY_HASH, directives: EMPTY_HASH, validates: EMPTY_ARRAY, legacy_edge_class: nil, &definition_block) ⇒ Field
Returns a new instance of Field.
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
# File 'lib/graphql/schema/field.rb', line 212 def initialize(type: nil, name: nil, owner: nil, null: nil, field: nil, function: nil, description: nil, deprecation_reason: nil, method: nil, hash_key: nil, resolver_method: nil, resolve: nil, connection: nil, max_page_size: :not_given, scope: nil, introspection: false, camelize: true, trace: nil, complexity: 1, ast_node: nil, extras: EMPTY_ARRAY, extensions: EMPTY_ARRAY, connection_extension: self.class.connection_extension, resolver_class: nil, subscription_scope: nil, relay_node_field: false, relay_nodes_field: false, method_conflict_warning: true, broadcastable: nil, arguments: EMPTY_HASH, directives: EMPTY_HASH, validates: EMPTY_ARRAY, legacy_edge_class: nil, &definition_block) if name.nil? raise ArgumentError, "missing first `name` argument or keyword `name:`" end if !(field || function || resolver_class) if type.nil? raise ArgumentError, "missing second `type` argument or keyword `type:`" end if null.nil? raise ArgumentError, "missing keyword argument null:" end end if (field || function || resolve) && extras.any? raise ArgumentError, "keyword `extras:` may only be used with method-based resolve and class-based field such as mutation class, please remove `field:`, `function:` or `resolve:`" end @original_name = name name_s = -name.to_s @underscored_name = -Member::BuildType.underscore(name_s) @name = -(camelize ? Member::BuildType.camelize(name_s) : name_s) @description = description if field.is_a?(GraphQL::Schema::Field) raise ArgumentError, "Instead of passing a field as `field:`, use `add_field(field)` to add an already-defined field." else @field = field end @function = function @resolve = resolve self.deprecation_reason = deprecation_reason if method && hash_key raise ArgumentError, "Provide `method:` _or_ `hash_key:`, not both. (called with: `method: #{method.inspect}, hash_key: #{hash_key.inspect}`)" end if resolver_method if method raise ArgumentError, "Provide `method:` _or_ `resolver_method:`, not both. (called with: `method: #{method.inspect}, resolver_method: #{resolver_method.inspect}`)" end if hash_key raise ArgumentError, "Provide `hash_key:` _or_ `resolver_method:`, not both. (called with: `hash_key: #{hash_key.inspect}, resolver_method: #{resolver_method.inspect}`)" end end # TODO: I think non-string/symbol hash keys are wrongly normalized (eg `1` will not work) method_name = method || hash_key || name_s resolver_method ||= name_s.to_sym @method_str = -method_name.to_s @method_sym = method_name.to_sym @resolver_method = resolver_method @complexity = complexity @return_type_expr = type @return_type_null = null @connection = connection @has_max_page_size = max_page_size != :not_given @max_page_size = max_page_size == :not_given ? nil : max_page_size @introspection = introspection @extras = extras @broadcastable = broadcastable @resolver_class = resolver_class @scope = scope @trace = trace @relay_node_field = relay_node_field @relay_nodes_field = relay_nodes_field @ast_node = ast_node @method_conflict_warning = method_conflict_warning @legacy_edge_class = legacy_edge_class arguments.each do |name, arg| if arg.is_a?(Hash) argument(name: name, **arg) else add_argument(arg) end end @owner = owner @subscription_scope = subscription_scope @extensions = EMPTY_ARRAY # This should run before connection extension, # but should it run after the definition block? if scoped? self.extension(ScopeExtension) end # The problem with putting this after the definition_block # is that it would override arguments if connection? && connection_extension self.extension(connection_extension) end # Do this last so we have as much context as possible when initializing them: if extensions.any? self.extensions(extensions) end if directives.any? directives.each do |(dir_class, )| self.directive(dir_class, **) end end self.validates(validates) if definition_block if definition_block.arity == 1 yield self else instance_eval(&definition_block) end end end |
Instance Attribute Details
#description(text = nil) ⇒ String
335 336 337 338 339 340 341 |
# File 'lib/graphql/schema/field.rb', line 335 def description(text = nil) if text @description = text else @description end end |
#max_page_size ⇒ Integer? (readonly)
Returns Applied to connections if #has_max_page_size?.
437 438 439 |
# File 'lib/graphql/schema/field.rb', line 437 def max_page_size @max_page_size end |
#method_str ⇒ String (readonly)
Returns Method or hash key on the underlying object to look up.
33 34 35 |
# File 'lib/graphql/schema/field.rb', line 33 def method_str @method_str end |
#method_sym ⇒ Symbol (readonly)
Returns Method or hash key on the underlying object to look up.
30 31 32 |
# File 'lib/graphql/schema/field.rb', line 30 def method_sym @method_sym end |
#name ⇒ String (readonly) Also known as: graphql_name
Returns the GraphQL name for this field, camelized unless camelize: false
is provided.
24 25 26 |
# File 'lib/graphql/schema/field.rb', line 24 def name @name end |
#original_name ⇒ Symbol (readonly)
Returns the original name of the field, passed in by the user.
51 52 53 |
# File 'lib/graphql/schema/field.rb', line 51 def original_name @original_name end |
#owner ⇒ Class
Returns The thing this field was defined on (type, mutation, resolver).
39 40 41 |
# File 'lib/graphql/schema/field.rb', line 39 def owner @owner end |
#relay_node_field ⇒ Object (readonly)
Returns Boolean.
175 176 177 |
# File 'lib/graphql/schema/field.rb', line 175 def relay_node_field @relay_node_field end |
#resolver_method ⇒ Symbol (readonly)
Returns The method on the type to look up.
36 37 38 |
# File 'lib/graphql/schema/field.rb', line 36 def resolver_method @resolver_method end |
#subscription_scope ⇒ String?
73 74 75 |
# File 'lib/graphql/schema/field.rb', line 73 def subscription_scope @subscription_scope end |
#trace ⇒ Boolean (readonly)
Returns Apply tracing to this field? (Default: skip scalars, this is the override value).
70 71 72 |
# File 'lib/graphql/schema/field.rb', line 70 def trace @trace end |
#type ⇒ Object
515 516 517 518 519 520 521 522 523 524 525 526 527 528 |
# File 'lib/graphql/schema/field.rb', line 515 def type @type ||= if @function Member::BuildType.parse_type(@function.type, null: false) elsif @field Member::BuildType.parse_type(@field.type, null: false) else Member::BuildType.parse_type(@return_type_expr, null: @return_type_null) end rescue GraphQL::Schema::InvalidDocumentError => err # Let this propagate up raise err rescue StandardError => err raise ArgumentError, "Failed to build return type for #{@owner.graphql_name}.#{name} from #{@return_type_expr.inspect}: (#{err.class}) #{err.}", err.backtrace end |
Class Method Details
.connection_extension(new_extension_class = nil) ⇒ Class
This extension is applied to fields when #connection? is true.
You can override it in your base field definition.
166 167 168 169 170 171 172 |
# File 'lib/graphql/schema/field.rb', line 166 def self.connection_extension(new_extension_class = nil) if new_extension_class @connection_extension = new_extension_class else @connection_extension ||= find_inherited_value(:connection_extension, ConnectionExtension) end end |
.from_options(name = nil, type = nil, desc = nil, resolver: nil, mutation: nil, subscription: nil, **kwargs, &block) ⇒ GraphQL::Schema:Field
Create a field instance from a list of arguments, keyword arguments, and a block.
This method implements prioritization between the resolver
or mutation
defaults
and the local overrides via other keywords.
It also normalizes positional arguments into keywords for #initialize.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/graphql/schema/field.rb', line 86 def self.(name = nil, type = nil, desc = nil, resolver: nil, mutation: nil, subscription: nil,**kwargs, &block) if kwargs[:field] if kwargs[:field].is_a?(GraphQL::Field) && kwargs[:field] == GraphQL::Types::Relay::NodeField.graphql_definition GraphQL::Deprecation.warn("Legacy-style `GraphQL::Relay::Node.field` is being added to a class-based type. See `GraphQL::Types::Relay::NodeField` for a replacement.") return GraphQL::Types::Relay::NodeField elsif kwargs[:field].is_a?(GraphQL::Field) && kwargs[:field] == GraphQL::Types::Relay::NodesField.graphql_definition GraphQL::Deprecation.warn("Legacy-style `GraphQL::Relay::Node.plural_field` is being added to a class-based type. See `GraphQL::Types::Relay::NodesField` for a replacement.") return GraphQL::Types::Relay::NodesField end end if (parent_config = resolver || mutation || subscription) # Get the parent config, merge in local overrides kwargs = parent_config..merge(kwargs) # Add a reference to that parent class kwargs[:resolver_class] = parent_config end if name kwargs[:name] = name end if !type.nil? if type.is_a?(GraphQL::Field) raise ArgumentError, "A GraphQL::Field was passed as the second argument, use the `field:` keyword for this instead." end if desc if kwargs[:description] raise ArgumentError, "Provide description as a positional argument or `description:` keyword, but not both (#{desc.inspect}, #{kwargs[:description].inspect})" end kwargs[:description] = desc kwargs[:type] = type elsif (kwargs[:field] || kwargs[:function] || resolver || mutation) && type.is_a?(String) # The return type should be copied from `field` or `function`, and the second positional argument is the description kwargs[:description] = type else kwargs[:type] = type end end new(**kwargs, &block) end |
Instance Method Details
#accessible?(context) ⇒ Boolean
538 539 540 541 542 543 544 |
# File 'lib/graphql/schema/field.rb', line 538 def accessible?(context) if @resolver_class @resolver_class.accessible?(context) else true end end |
#authorized?(object, args, context) ⇒ Boolean
546 547 548 549 550 551 552 553 554 555 556 557 558 559 |
# File 'lib/graphql/schema/field.rb', line 546 def (object, args, context) if @resolver_class # The resolver will check itself during `resolve()` @resolver_class.(object, context) else # Faster than `.any?` arguments.each_value do |arg| if args.key?(arg.keyword) && !arg.(object, args[arg.keyword], context) return false end end true end end |
#broadcastable? ⇒ Boolean?
If true, subscription updates with this field can be shared between viewers
329 330 331 |
# File 'lib/graphql/schema/field.rb', line 329 def broadcastable? @broadcastable end |
#complexity(new_complexity = nil) ⇒ Object
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 |
# File 'lib/graphql/schema/field.rb', line 411 def complexity(new_complexity = nil) case new_complexity when Proc if new_complexity.parameters.size != 3 fail( "A complexity proc should always accept 3 parameters: ctx, args, child_complexity. "\ "E.g.: complexity ->(ctx, args, child_complexity) { child_complexity * args[:limit] }" ) else @complexity = new_complexity end when Numeric @complexity = new_complexity when nil @complexity else raise("Invalid complexity: #{new_complexity.inspect} on #{@name}") end end |
#connection? ⇒ Boolean
Can be set with connection: true|false
or inferred from a type name ending in *Connection
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/graphql/schema/field.rb', line 131 def connection? if @connection.nil? # Provide default based on type name return_type_name = if (contains_type = @field || @function) Member::BuildType.to_type_name(contains_type.type) elsif @return_type_expr Member::BuildType.to_type_name(@return_type_expr) else # As a last ditch, try to force loading the return type: type.unwrap.name end @connection = return_type_name.end_with?("Connection") else @connection end end |
#extension(extension, options = nil) ⇒ Object
Add extension
to this field, initialized with options
if provided.
389 390 391 |
# File 'lib/graphql/schema/field.rb', line 389 def extension(extension, = nil) extensions([{extension => }]) end |
#extensions(new_extensions = nil) ⇒ Array<GraphQL::Schema::FieldExtension>
Read extension instances from this field, or add new classes/options to be initialized on this field. Extensions are executed in the order they are added.
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
# File 'lib/graphql/schema/field.rb', line 358 def extensions(new_extensions = nil) if new_extensions.nil? # Read the value @extensions else if @extensions.frozen? @extensions = @extensions.dup end new_extensions.each do |extension| if extension.is_a?(Hash) extension = extension.to_a[0] extension_class, = *extension @extensions << extension_class.new(field: self, options: ) else extension_class = extension @extensions << extension_class.new(field: self, options: nil) end end end end |
#extras(new_extras = nil) ⇒ Array<Symbol>
Read extras (as symbols) from this field, or add new extras to be opted into by this field’s resolver.
398 399 400 401 402 403 404 405 406 407 408 409 |
# File 'lib/graphql/schema/field.rb', line 398 def extras(new_extras = nil) if new_extras.nil? # Read the value @extras else if @extras.frozen? @extras = @extras.dup end # Append to the set of extras on this field @extras.concat(new_extras) end end |
#fetch_extra(extra_name, ctx) ⇒ Object
626 627 628 629 630 631 632 633 634 |
# File 'lib/graphql/schema/field.rb', line 626 def fetch_extra(extra_name, ctx) if extra_name != :path && extra_name != :ast_node && respond_to?(extra_name) self.public_send(extra_name) elsif ctx.respond_to?(extra_name) ctx.public_send(extra_name) else raise GraphQL::RequiredImplementationMissingError, "Unknown field extra for #{self.path}: #{extra_name.inspect}" end end |
#has_max_page_size? ⇒ Boolean
Returns True if this field’s #max_page_size should override the schema default.
432 433 434 |
# File 'lib/graphql/schema/field.rb', line 432 def has_max_page_size? @has_max_page_size end |
#inspect ⇒ Object
63 64 65 |
# File 'lib/graphql/schema/field.rb', line 63 def inspect "#<#{self.class} #{path}#{arguments.any? ? "(...)" : ""}: #{type.to_type_signature}>" end |
#introspection? ⇒ Boolean
Returns Is this field a predefined introspection field?.
59 60 61 |
# File 'lib/graphql/schema/field.rb', line 59 def introspection? @introspection end |
#method_conflict_warning? ⇒ Boolean
Returns Should we warn if this field’s name conflicts with a built-in method?.
178 179 180 |
# File 'lib/graphql/schema/field.rb', line 178 def method_conflict_warning? @method_conflict_warning end |
#owner_type ⇒ Class
Returns The GraphQL type this field belongs to. (For fields defined on mutations, it’s the payload type).
42 43 44 45 46 47 48 |
# File 'lib/graphql/schema/field.rb', line 42 def owner_type @owner_type ||= if owner < GraphQL::Schema::Mutation owner.payload_type else owner end end |
#resolve(object, args, ctx) ⇒ Object
This method is called by the interpreter for each field. You can extend it in your base field classes.
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 |
# File 'lib/graphql/schema/field.rb', line 597 def resolve(object, args, ctx) if @resolve_proc raise "Can't run resolve proc for #{path} when using GraphQL::Execution::Interpreter" end begin # Unwrap the GraphQL object to get the application object. application_object = object.object Schema::Validator.validate!(validators, application_object, ctx, args) ctx.schema.after_lazy(self.(application_object, args, ctx)) do || if public_send_field(object, args, ctx) else err = GraphQL::UnauthorizedFieldError.new(object: application_object, type: object.class, context: ctx, field: self) ctx.schema.(err) end end rescue GraphQL::UnauthorizedFieldError => err err.field ||= self ctx.schema.(err) rescue GraphQL::UnauthorizedError => err ctx.schema.(err) end rescue GraphQL::ExecutionError => err err end |
#resolve_field(obj, args, ctx) ⇒ Object
Implement Field’s resolve API.
Eventually, we might hook up field instances to execution in another way. TBD.
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 |
# File 'lib/graphql/schema/field.rb', line 565 def resolve_field(obj, args, ctx) ctx.schema.after_lazy(obj) do |after_obj| # First, apply auth ... query_ctx = ctx.query.context # Some legacy fields can have `nil` here, not exactly sure why. # @see https://github.com/rmosolgo/graphql-ruby/issues/1990 before removing inner_obj = after_obj && after_obj.object ctx.schema.after_lazy(to_ruby_args(after_obj, args, ctx)) do |ruby_args| if (inner_obj, ruby_args, query_ctx) # Then if it passed, resolve the field if @resolve_proc # Might be nil, still want to call the func in that case with_extensions(inner_obj, ruby_args, query_ctx) do |extended_obj, extended_args| # Pass the GraphQL args here for compatibility: @resolve_proc.call(extended_obj, args, ctx) end else public_send_field(after_obj, ruby_args, query_ctx) end else err = GraphQL::UnauthorizedFieldError.new(object: inner_obj, type: obj.class, context: ctx, field: self) query_ctx.schema.(err) end end end end |
#resolver ⇒ Class? Also known as: mutation
Returns The Resolver this field was derived from, if there is one.
54 55 56 |
# File 'lib/graphql/schema/field.rb', line 54 def resolver @resolver_class end |
#scoped? ⇒ Boolean
Returns if true, the return type’s .scope_items
method will be applied to this field’s return value.
149 150 151 152 153 154 155 156 |
# File 'lib/graphql/schema/field.rb', line 149 def scoped? if !@scope.nil? # The default was overridden @scope else @return_type_expr && (@return_type_expr.is_a?(Array) || (@return_type_expr.is_a?(String) && @return_type_expr.include?("[")) || connection?) end end |
#to_graphql ⇒ GraphQL::Field
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 |
# File 'lib/graphql/schema/field.rb', line 440 def to_graphql field_defn = if @field @field.dup elsif @function GraphQL::Function.build_field(@function) else GraphQL::Field.new end field_defn.name = @name if @return_type_expr field_defn.type = -> { type } end if @description field_defn.description = @description end if self.deprecation_reason field_defn.deprecation_reason = self.deprecation_reason end if @resolver_class if @resolver_class < GraphQL::Schema::Mutation field_defn.mutation = @resolver_class end field_defn.[:resolver] = @resolver_class end if !@trace.nil? field_defn.trace = @trace end if @relay_node_field field_defn.relay_node_field = @relay_node_field end if @relay_nodes_field field_defn.relay_nodes_field = @relay_nodes_field end if @legacy_edge_class field_defn.edge_class = @legacy_edge_class end field_defn.resolve = self.method(:resolve_field) field_defn.connection = connection? field_defn.connection_max_page_size = max_page_size field_defn.introspection = @introspection field_defn.complexity = @complexity field_defn.subscription_scope = @subscription_scope field_defn.ast_node = ast_node arguments.each do |name, defn| arg_graphql = defn.to_graphql field_defn.arguments[arg_graphql.name] = arg_graphql end # Support a passed-in proc, one way or another @resolve_proc = if @resolve @resolve elsif @function @function elsif @field @field.resolve_proc end # Ok, `self` isn't a class, but this is for consistency with the classes field_defn.[:type_class] = self field_defn.arguments_class = GraphQL::Query::Arguments.construct_arguments_class(field_defn) field_defn end |
#visible?(context) ⇒ Boolean
530 531 532 533 534 535 536 |
# File 'lib/graphql/schema/field.rb', line 530 def visible?(context) if @resolver_class @resolver_class.visible?(context) else true end end |