Module: GraphQL::Types::Relay::HasNodeField
- Defined in:
- lib/graphql/types/relay/has_node_field.rb
Overview
Include this module to your root Query type to get a Relay-compliant node(id: ID!): Node field that uses the schema's object_from_id hook.
@requires_ancestor: GraphQL::Schema::Object
Defined Under Namespace
Modules: ExecutionMethods
Class Method Summary collapse
-
.field_block ⇒ Object
: -> untyped.
-
.field_options ⇒ Object
: -> Hash[Symbol, untyped].
-
.included(child_class) ⇒ Object
: (singleton(GraphQL::Schema::Object) child_class) -> void.
Instance Method Summary collapse
-
#get_relay_node(id:) ⇒ Object
: (id: String) -> untyped.
Class Method Details
.field_block ⇒ Object
: -> untyped
46 47 48 49 50 51 52 |
# File 'lib/graphql/types/relay/has_node_field.rb', line 46 def field_block Proc.new { #: self as GraphQL::Schema::Field argument :id, "ID!", description: "ID of the object." } end |
.field_options ⇒ Object
: -> Hash[Symbol, untyped]
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/graphql/types/relay/has_node_field.rb', line 33 def { name: "node", type: GraphQL::Types::Relay::Node, null: true, description: "Fetches an object given its ID.", relay_node_field: true, resolver_method: :get_relay_node, resolve_static: :get_relay_node, } end |
.included(child_class) ⇒ Object
: (singleton(GraphQL::Schema::Object) child_class) -> void
13 14 15 16 |
# File 'lib/graphql/types/relay/has_node_field.rb', line 13 def self.included(child_class) child_class.field(**, &field_block) child_class.extend(ExecutionMethods) end |
Instance Method Details
#get_relay_node(id:) ⇒ Object
: (id: String) -> untyped
26 27 28 29 |
# File 'lib/graphql/types/relay/has_node_field.rb', line 26 def get_relay_node(id:) query_class = self.class #: as GraphQL::Types::Relay::HasNodeField::ExecutionMethods query_class.get_relay_node(context, id: id) end |