Class: GraphQL::Language::Field
- Inherits:
-
Struct
- Object
- Struct
- GraphQL::Language::Field
- Defined in:
- lib/graphql/language/field.rb
Instance Attribute Summary collapse
-
#alias ⇒ Object
Returns the value of attribute alias.
-
#arguments ⇒ Object
Returns the value of attribute arguments.
-
#directives ⇒ Object
Returns the value of attribute directives.
-
#name ⇒ Object
Returns the value of attribute name.
-
#selection_set ⇒ Object
Returns the value of attribute selection_set.
Instance Method Summary collapse
-
#key ⇒ Object
GraphQL Specification 6.3 Evaluate selection sets CollectFields responseKey implementation.
- #materialize_arguments(object_type, variables) ⇒ Object
-
#resolve(context, object_type, object) ⇒ Object
GraphQL Specification 6.4.1 Field entries ResolveFieldOnObject implementation objectType, object, firstField = self + context[document, schema, root].
- #schema_field(object_type) ⇒ Object
Instance Attribute Details
#alias ⇒ Object
Returns the value of attribute alias
3 4 5 |
# File 'lib/graphql/language/field.rb', line 3 def alias @alias end |
#arguments ⇒ Object
Returns the value of attribute arguments
3 4 5 |
# File 'lib/graphql/language/field.rb', line 3 def arguments @arguments end |
#directives ⇒ Object
Returns the value of attribute directives
3 4 5 |
# File 'lib/graphql/language/field.rb', line 3 def directives @directives end |
#name ⇒ Object
Returns the value of attribute name
3 4 5 |
# File 'lib/graphql/language/field.rb', line 3 def name @name end |
#selection_set ⇒ Object
Returns the value of attribute selection_set
3 4 5 |
# File 'lib/graphql/language/field.rb', line 3 def selection_set @selection_set end |
Instance Method Details
#key ⇒ Object
GraphQL Specification
6.3 Evaluate selection sets
CollectFields
responseKey implementation
10 11 12 |
# File 'lib/graphql/language/field.rb', line 10 def key self.alias || self.name end |
#materialize_arguments(object_type, variables) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/graphql/language/field.rb', line 36 def materialize_arguments(object_type, variables) schema_field(object_type).args.reduce({}) do |memo, field_argument| argument = arguments.find { |argument| argument.name == field_argument.name } memo[argument.name.to_sym] = argument.materialize(field_argument.type, variables) unless argument.nil? memo end end |
#resolve(context, object_type, object) ⇒ Object
GraphQL Specification
6.4.1 Field entries
ResolveFieldOnObject implementation
objectType, object, firstField = self
+ context[document, schema, root]
TODO: think of should or shouldn’t we pass self as fourth parameter
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/graphql/language/field.rb', line 22 def resolve(context, object_type, object) arguments = [ object, materialize_arguments(object_type, context[:variables]), context ] resolve = schema_field(object_type).resolve arguments = arguments.slice(0, resolve.arity) if resolve.arity >= 0 resolve.call(*arguments) end |
#schema_field(object_type) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/graphql/language/field.rb', line 44 def schema_field(object_type) case when GraphQL::Introspection.(name) GraphQL::Introspection.(name) else object_type.field(name) end end |