Class: GraphQL::ObjectType
- Defined in:
- lib/graphql/object_type.rb
Overview
This type exposes fields on an object.
@example defining a type for your IMDB clone
MovieType = GraphQL::ObjectType.define do
name "Movie"
description "A full-length film or a short film"
interfaces [ProductionInterface, DurationInterface]
field :runtimeMinutes, !types.Int, property: :runtime_minutes
field :director, PersonType
field :cast, CastType
field :starring, types[PersonType] do
arguments :limit, types.Int
resolve -> (object, args, ctx) {
stars = object.cast.stars
args[:limit] && stars = stars.limit(args[:limit])
stars
}
end
end
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#fields ⇒ Object
Returns the value of attribute fields.
-
#interfaces ⇒ Object
Returns the value of attribute interfaces.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#all_fields ⇒ Array<GraphQL::Field>
All fields, including ones inherited from interfaces.
-
#get_field(field_name) ⇒ GraphQL::Field
The field definition for ‘field_name` (may be inherited from interfaces).
- #kind ⇒ Object
Methods inherited from BaseType
#==, #coerce_input, #resolve_type, #to_list_type, #to_non_null_type, #to_s, #unwrap, #valid_input?, #validate_input
Methods included from DefinitionHelpers::DefinedByConfig
Methods included from DefinitionHelpers::NonNullWithBang
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
24 25 26 |
# File 'lib/graphql/object_type.rb', line 24 def description @description end |
#fields ⇒ Object
Returns the value of attribute fields.
24 25 26 |
# File 'lib/graphql/object_type.rb', line 24 def fields @fields end |
#interfaces ⇒ Object
Returns the value of attribute interfaces.
24 25 26 |
# File 'lib/graphql/object_type.rb', line 24 def interfaces @interfaces end |
#name ⇒ Object
Returns the value of attribute name.
24 25 26 |
# File 'lib/graphql/object_type.rb', line 24 def name @name end |
Instance Method Details
#all_fields ⇒ Array<GraphQL::Field>
Returns All fields, including ones inherited from interfaces.
52 53 54 |
# File 'lib/graphql/object_type.rb', line 52 def all_fields interface_fields.merge(self.fields).values end |
#get_field(field_name) ⇒ GraphQL::Field
Returns The field definition for ‘field_name` (may be inherited from interfaces).
47 48 49 |
# File 'lib/graphql/object_type.rb', line 47 def get_field(field_name) fields[field_name] || interface_fields[field_name] end |