Class: GraphQLActiveRecordResolvers::GraphQLAssociation

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql_activerecord_resolvers/graphql_association.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema:, klass:, field:, selections:, root:) ⇒ GraphQLAssociation

Returns a new instance of GraphQLAssociation.



5
6
7
8
9
10
11
# File 'lib/graphql_activerecord_resolvers/graphql_association.rb', line 5

def initialize(schema:, klass:, field:, selections:, root:)
  @klass = klass
  @schema = schema
  @field = field
  @selections = selections
  @root = root
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



3
4
5
# File 'lib/graphql_activerecord_resolvers/graphql_association.rb', line 3

def field
  @field
end

#klassObject (readonly)

Returns the value of attribute klass.



3
4
5
# File 'lib/graphql_activerecord_resolvers/graphql_association.rb', line 3

def klass
  @klass
end

#rootObject (readonly)

Returns the value of attribute root.



3
4
5
# File 'lib/graphql_activerecord_resolvers/graphql_association.rb', line 3

def root
  @root
end

#schemaObject (readonly)

Returns the value of attribute schema.



3
4
5
# File 'lib/graphql_activerecord_resolvers/graphql_association.rb', line 3

def schema
  @schema
end

#selectionsObject (readonly)

Returns the value of attribute selections.



3
4
5
# File 'lib/graphql_activerecord_resolvers/graphql_association.rb', line 3

def selections
  @selections
end

Instance Method Details

#build_includes_treeObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/graphql_activerecord_resolvers/graphql_association.rb', line 13

def build_includes_tree
  if root
    child_associations.map(&:build_includes_tree)
  elsif child_associations.any?
    {
      field.name => child_associations.map(&:build_includes_tree),
    }
  else
    field.name
  end
end