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

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

Instance Method Summary collapse

Instance Method Details

#authorized?(obj, ctx) ⇒ Boolean

Returns:



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

def authorized?(obj, ctx)
  true
end

#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.



50
51
52
53
54
55
56
# File 'lib/graphql/types/relay/edge_behaviors.rb', line 50

def node_nullable(new_value = nil)
  if new_value.nil?
    defined?(@node_nullable) ? @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) (defaults to: nil)

    A Schema::Object subclass

  • null (Boolean) (defaults to: self.node_nullable)
  • field_options (Hash) (defaults to: nil)

    Any extra arguments to pass to the field :node configuration



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/graphql/types/relay/edge_behaviors.rb', line 21

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

#visible?(ctx) ⇒ Boolean

Returns:



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

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