Class: GraphqlRails::Router::Route

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql_rails/router/route.rb

Overview

Generic class for any type graphql action. Should not be used directly

Direct Known Subclasses

MutationRoute, QueryRoute

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, on:, to: '', groups: nil, scope_names: [], **options) ⇒ Route

rubocop:disable Metrics/ParameterLists



12
13
14
15
16
17
18
19
20
# File 'lib/graphql_rails/router/route.rb', line 12

def initialize(name, on:, to: '', groups: nil, scope_names: [], **options) # rubocop:disable Metrics/ParameterLists
  @name = name.to_s.camelize(:lower)
  @module_name = options[:module].to_s
  @function = options[:function]
  @groups = groups
  @relative_path = to
  @on = on.to_sym
  @scope_names = scope_names
end

Instance Attribute Details

#groupsObject (readonly)

Returns the value of attribute groups.



10
11
12
# File 'lib/graphql_rails/router/route.rb', line 10

def groups
  @groups
end

#module_nameObject (readonly)

Returns the value of attribute module_name.



10
11
12
# File 'lib/graphql_rails/router/route.rb', line 10

def module_name
  @module_name
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/graphql_rails/router/route.rb', line 10

def name
  @name
end

#onObject (readonly)

Returns the value of attribute on.



10
11
12
# File 'lib/graphql_rails/router/route.rb', line 10

def on
  @on
end

#relative_pathObject (readonly)

Returns the value of attribute relative_path.



10
11
12
# File 'lib/graphql_rails/router/route.rb', line 10

def relative_path
  @relative_path
end

#scope_namesObject (readonly)

Returns the value of attribute scope_names.



10
11
12
# File 'lib/graphql_rails/router/route.rb', line 10

def scope_names
  @scope_names
end

Instance Method Details

#collection?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/graphql_rails/router/route.rb', line 28

def collection?
  on == :collection
end

#field_optionsObject



38
39
40
41
42
43
44
# File 'lib/graphql_rails/router/route.rb', line 38

def field_options
  if function
    { function: function }
  else
    { resolver: resolver, extras: [:lookahead], **resolver_options }
  end
end

#pathObject



22
23
24
25
26
# File 'lib/graphql_rails/router/route.rb', line 22

def path
  return relative_path if module_name.empty?

  [module_name, relative_path].join('/')
end

#show_in_group?(group_name) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
# File 'lib/graphql_rails/router/route.rb', line 32

def show_in_group?(group_name)
  return true if groups.nil? || groups.empty?

  groups.include?(group_name&.to_sym)
end