hq-graphql 2.1.3 → 2.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 50ee2af7af4309a1fb549c15b88abdb8bda3454eacfdce5136f1997b814c52fb
4
- data.tar.gz: 9dc0b893d4ad8bf8a999cba996224488be9c394e55f83ef979460ac19f96c381
3
+ metadata.gz: 2b3620be84fad5d620dfb18c0f51bd0cf726671b49320ec1910bd534ef31d569
4
+ data.tar.gz: 8974a6d0e3aa4dd0ad5e1dd37b0802c8b70d428365abfdb3342da4fffe66a0cb
5
5
  SHA512:
6
- metadata.gz: f4940761bdccfd01c867e21f69ab66a5459d8b151024ebd79679906ea62fa6c5d2208ce311a339ed720021c2b43221e51ebb092de8f4bff87a15bc3e3f07f376
7
- data.tar.gz: 00a7683630411f065d954132918b3449ef6aec9419de30702dd43bf99ad34fb8dbaf5ee1ae248759f3029006db3863257fe86a99d7b89a7456123c82d52ef7b3
6
+ metadata.gz: c67704e43e662552da1818d5f53fcd5acd3bb38da62fb556fac427d590bf002906e58a4a39d7141bc33f22c689c76c9fb1b33cf7b155f9590df0ea9ba8f056b6
7
+ data.tar.gz: f82c433ab64e9e5d34cb62f51464811621242de62220294766107fe96ad75cbaa665b69a4c99042f5a063c9f22106c1a980dbeee037de3c3e7353c4dd2cd41d0
@@ -77,6 +77,7 @@ require "hq/graphql/input_object"
77
77
  require "hq/graphql/mutation"
78
78
  require "hq/graphql/object"
79
79
  require "hq/graphql/paginated_association_loader"
80
+ require "hq/graphql/record_loader"
80
81
  require "hq/graphql/resource"
81
82
  require "hq/graphql/root_mutation"
82
83
  require "hq/graphql/root_query"
@@ -34,6 +34,7 @@ module HQ::GraphQL
34
34
  prefix: nil,
35
35
  register: true,
36
36
  scope: nil,
37
+ strip: /(^[^_a-zA-Z])|([^_a-zA-Z0-9]*)/,
37
38
  value_method: :name
38
39
  )
39
40
  raise ArgumentError.new(<<~ERROR) if !klass
@@ -49,7 +50,7 @@ module HQ::GraphQL
49
50
  lazy_load do
50
51
  records = scope ? klass.instance_exec(&scope) : klass.all
51
52
  records.each do |record|
52
- value "#{prefix}#{record.send(value_method).delete(" ")}", value: record
53
+ value "#{prefix}#{record.send(value_method).gsub(strip, "")}", value: record
53
54
  end
54
55
  end
55
56
  end
@@ -64,9 +64,11 @@ module HQ
64
64
 
65
65
  def field_from_association(association, auto_nil:, internal_association: false, &block)
66
66
  association_klass = association.klass
67
- name = association.name
68
- klass = model_klass
69
- type = Types[association_klass]
67
+ name = association.name.to_s
68
+ return if fields[name]
69
+
70
+ klass = model_klass
71
+ type = Types[association_klass]
70
72
  case association.macro
71
73
  when :has_many
72
74
  field name, [type], null: false, klass: model_name do
@@ -88,7 +90,10 @@ module HQ
88
90
  end
89
91
 
90
92
  def field_from_column(column, auto_nil:)
91
- field column.name, Types.type_from_column(column), null: !auto_nil || column.null
93
+ name = column.name
94
+ return if fields[name]
95
+
96
+ field name, Types.type_from_column(column), null: !auto_nil || column.null
92
97
  end
93
98
 
94
99
  def association_required?(association)
@@ -23,7 +23,7 @@ module HQ
23
23
  @limit = [0, limit].max if limit
24
24
  @offset = [0, offset].max if offset
25
25
  @scope = scope
26
- @sort_by = sort_by || :updated_at
26
+ @sort_by = sort_by || :created_at
27
27
  @sort_order = normalize_sort_order(sort_order)
28
28
 
29
29
  validate!
@@ -64,7 +64,6 @@ module HQ
64
64
 
65
65
  inside_scope = default_scope.
66
66
  select(inner_table[::Arel.star]).
67
- from(inner_table).
68
67
  where(lateral_join_table[target_join_key].eq(from_table[target_join_key])).
69
68
  reorder(arel_order(inner_table)).
70
69
  limit(@limit).
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HQ
4
+ module GraphQL
5
+ class RecordLoader < ::GraphQL::Batch::Loader
6
+ def initialize(model, column: model.primary_key, where: nil)
7
+ @model = model
8
+ @column = column.to_s
9
+ @column_type = model.type_for_attribute(@column)
10
+ @where = where
11
+ end
12
+
13
+ def load(key)
14
+ super(@column_type.cast(key))
15
+ end
16
+
17
+ def perform(keys)
18
+ query(keys).each { |record| fulfill(record.public_send(@column), record) }
19
+ keys.each { |key| fulfill(key, nil) unless fulfilled?(key) }
20
+ end
21
+
22
+ private
23
+
24
+ def query(keys)
25
+ scope = @model
26
+ scope = scope.where(@where) if @where
27
+ scope.where(@column => keys)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module HQ
4
4
  module GraphQL
5
- VERSION = "2.1.3"
5
+ VERSION = "2.1.8"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hq-graphql
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.3
4
+ version: 2.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Jones
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-25 00:00:00.000000000 Z
11
+ date: 2020-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -264,6 +264,7 @@ files:
264
264
  - lib/hq/graphql/object.rb
265
265
  - lib/hq/graphql/object_association.rb
266
266
  - lib/hq/graphql/paginated_association_loader.rb
267
+ - lib/hq/graphql/record_loader.rb
267
268
  - lib/hq/graphql/resource.rb
268
269
  - lib/hq/graphql/resource/auto_mutation.rb
269
270
  - lib/hq/graphql/root_mutation.rb