Skip to content

Commit

Permalink
Add keyword support
Browse files Browse the repository at this point in the history
  • Loading branch information
povilasjurcys committed Nov 19, 2024
1 parent e6827cf commit 66cb9be
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
25 changes: 25 additions & 0 deletions lib/active_graphql/model/attribute.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

module ActiveGraphql
module Model
# stores attribute information for how to handle graphql requests for model
class Attribute
attr_reader :name, :nesting, :decorate_with

def initialize(name, nesting: nil, decorate_with: nil, keyword: false)
@name = name.to_sym
@nesting = nesting
@decorate_with = decorate_with
@keyword = keyword || false
end

def keyword?
@keyword
end

def to_graphql_output
nesting ? { name => nesting } : name
end
end
end
end
23 changes: 7 additions & 16 deletions lib/active_graphql/model/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
# frozen_string_literal: true

require_relative 'attribute'

module ActiveGraphql
module Model
# stores all information for how to handle graphql requets for model
class Configuration
# stores attribute information for how to handle graphql requets for model
class Attribute
attr_reader :name, :nesting, :decorate_with

def initialize(name, nesting: nil, decorate_with: nil)
@name = name.to_sym
@nesting = nesting
@decorate_with = decorate_with
end

def to_graphql_output
nesting ? { name => nesting } : name
end
end

def initialize
@attributes = []
@primary_key = :id
Expand Down Expand Up @@ -50,7 +37,11 @@ def attributes(*list, **detailed_attributes)
end

def attributes_graphql_output
attributes.map(&:to_graphql_output)
outputs = attributes.map(&:to_graphql_output)
keywords = outputs.select(&:keyword?).map(&:to_graphql_output)
keyword_output = keywords.any? ? { __keyword_attributes: keywords } : nil

outputs + [keyword_output].compact
end

def attribute(name, nesting = nil, decorate_with: nil)
Expand Down

0 comments on commit 66cb9be

Please sign in to comment.