Module: GraphQL::Types::Relay::EdgeBehaviors::ClassMethods

Defined in:
lib/graphql/types/relay/edge_behaviors.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#node_nullable(new_value = nil) ⇒ Object

Set the default node_nullable for this class and its child classes. (Defaults to true.) Use node_nullable(false) in your base class to make non-null node field.



90
91
92
93
94
95
96
# File 'lib/graphql/types/relay/edge_behaviors.rb', line 90

def node_nullable(new_value = nil)
  if new_value.nil?
    @node_nullable != nil ? @node_nullable : superclass.node_nullable
  else
    @node_nullable = new_value
  end
end

#node_type(node_type = nil, null: self.node_nullable, field_options: nil) ⇒ Object

Get or set the Object type that this edge wraps.

Parameters

  • node_type (Class) — A Schema::Object subclass
  • null (Boolean)
  • field_options (Hash) — Any extra arguments to pass to the field :node configuration

:call-seq:

node_type(Class node_type, bool null:, Hash field_options:)


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/graphql/types/relay/edge_behaviors.rb', line 61

def node_type(node_type = nil, null: self.node_nullable, field_options: nil)
  if node_type
    @node_type = node_type
    # Add a default `node` field
    base_field_options = {
      name: :node,
      type: node_type,
      null: null,
      description: "The item at the end of the edge.",
      connection: false,
    }
    if field_options
      base_field_options.merge!(field_options)
    end
    field(**base_field_options)
  end
  @node_type
end

Instance Method Details

#authorized?(obj, ctx) ⇒ Boolean

Returns:



80
81
82
# File 'lib/graphql/types/relay/edge_behaviors.rb', line 80

def authorized?(obj, ctx)
  true
end

#default_broadcastable(new_value) ⇒ Object



47
48
49
# File 'lib/graphql/types/relay/edge_behaviors.rb', line 47

def default_broadcastable(new_value)
  @default_broadcastable = new_value
end

#default_broadcastable? ⇒ Boolean

Returns:



43
44
45
# File 'lib/graphql/types/relay/edge_behaviors.rb', line 43

def default_broadcastable?
  @default_broadcastable
end

#default_relay? ⇒ Boolean

Returns:



39
40
41
# File 'lib/graphql/types/relay/edge_behaviors.rb', line 39

def default_relay?
  true
end

#inherited(child_class) ⇒ Object



32
33
34
35
36
37
# File 'lib/graphql/types/relay/edge_behaviors.rb', line 32

def inherited(child_class)
  super
  child_class.node_type = nil
  child_class.node_nullable = nil
  child_class.default_broadcastable(default_broadcastable?)
end

#visible?(ctx) ⇒ Boolean

Returns:



84
85
86
# File 'lib/graphql/types/relay/edge_behaviors.rb', line 84

def visible?(ctx)
  node_type.visible?(ctx)
end