module GraphQL::Types::Relay::HasNodeField
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.
Public Class Methods
field_block()
click to toggle source
# File lib/graphql/types/relay/has_node_field.rb, line 23 def field_block Proc.new { argument :id, "ID!", description: "ID of the object." def resolve(obj, args, ctx) ctx.schema.object_from_id(args[:id], ctx) end def resolve_field(obj, args, ctx) resolve(obj, args, ctx) end } end
field_options()
click to toggle source
# File lib/graphql/types/relay/has_node_field.rb, line 13 def field_options { name: "node", type: GraphQL::Types::Relay::Node, null: true, description: "Fetches an object given its ID.", relay_node_field: true, } end
included(child_class)
click to toggle source
# File lib/graphql/types/relay/has_node_field.rb, line 8 def self.included(child_class) child_class.field(**field_options, &field_block) end
resolve(obj, args, ctx)
click to toggle source
# File lib/graphql/types/relay/has_node_field.rb, line 28 def resolve(obj, args, ctx) ctx.schema.object_from_id(args[:id], ctx) end
resolve_field(obj, args, ctx)
click to toggle source
# File lib/graphql/types/relay/has_node_field.rb, line 32 def resolve_field(obj, args, ctx) resolve(obj, args, ctx) end