graphiform 0.2.12 → 0.2.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 68647a1e2a4781554b98f3e34e4b8d517bdee49c76459aa8445dffb13dd59f07
4
- data.tar.gz: b66dcc28e233bf23a4468a1af531d1c650c50bf3d3054687e43831ee6fd3826f
3
+ metadata.gz: 24d0d05956c47d3c131958d9b273951c53d313f28dd622a5f841724ce18e1a4a
4
+ data.tar.gz: 82bd9b1ba24f07a5abc4cb164bd64ea8d217409d434613b543a2441edf5ba202
5
5
  SHA512:
6
- metadata.gz: 9d87c2c3723f8e643a3370bce93a86231466aa6f8d90ef264b308942cc6b7d832e1c4db4e9ab3a503d6f13804f3beedaef70106fd253c7fb67f9ad4863af01b4
7
- data.tar.gz: 6f4c3e3784b7c70aea0044fff3bda3dd9c79780e5835ee2ea2593025be264da83798a6379ea0f9acbbe807e08fb237946f7e04910c746f17a480ad083247bc2b
6
+ metadata.gz: b5480858bde4de83a235a691ee1e7ec05f49f7348d44e0e8b3fd6e739ab17211f1f4ea7e0e651cd43edbe7b34b4227c429c7c87d542bea668a406cd679fff9b5
7
+ data.tar.gz: 96d29abd576caf4dfe334f10df9eddf89a32055c9677bcb600dccb07529a24d7531c5a2fb9e5a25595626164e9398bc900a0211b07537269a09472240480416a
data/lib/graphiform.rb CHANGED
@@ -21,7 +21,29 @@ module Graphiform
21
21
  end
22
22
 
23
23
  def self.configuration
24
- @configuration ||= {}
24
+ @configuration ||= {
25
+ scalar_mappings: {
26
+ string: GraphQL::Types::String,
27
+ text: GraphQL::Types::String,
28
+ # nchar: GraphQL::Types::String,
29
+
30
+ date: GraphQL::Types::ISO8601Date,
31
+
32
+ time: GraphQL::Types::ISO8601DateTime,
33
+ datetime: GraphQL::Types::ISO8601DateTime,
34
+ timestamp: GraphQL::Types::ISO8601DateTime,
35
+
36
+ integer: GraphQL::Types::Int,
37
+
38
+ float: GraphQL::Types::Float,
39
+ decimal: GraphQL::Types::Float,
40
+
41
+ boolean: GraphQL::Types::Boolean,
42
+
43
+ json: GraphQL::Types::JSON,
44
+ jsonb: GraphQL::Types::JSON,
45
+ },
46
+ }
25
47
  end
26
48
 
27
49
  def self.configure
@@ -17,7 +17,9 @@ module Graphiform
17
17
  end
18
18
 
19
19
  def query(values)
20
- query = @model.where(@attribute => values)
20
+ query = @model
21
+ query = query.merge(@model.instance_exec(&@options[:scope])) if @options[:scope].present?
22
+ query = query.where(@attribute => values)
21
23
 
22
24
  query = query.includes(@options[:includes]) if @options[:includes].present? && query.respond_to?(:includes)
23
25
  query = query.apply_filters(@options[:where].to_h) if @options[:where].present? && query.respond_to?(:apply_filters)
@@ -204,6 +204,7 @@ module Graphiform
204
204
  AssociationSource,
205
205
  association_def.klass,
206
206
  join_keys.key,
207
+ scope: association_def.scope,
207
208
  where: args[:where],
208
209
  sort: args[:sort],
209
210
  multi: true,
@@ -229,7 +230,7 @@ module Graphiform
229
230
  return object.public_send(association_def.name) if skip_dataloader
230
231
 
231
232
  value = object.public_send(join_keys.foreign_key)
232
- dataloader.with(AssociationSource, association_def.klass, join_keys.key, case_sensitive: case_sensitive).load(value)
233
+ dataloader.with(AssociationSource, association_def.klass, join_keys.key, scope: association_def.scope, case_sensitive: case_sensitive).load(value)
233
234
  end
234
235
  end
235
236
  end
@@ -19,24 +19,7 @@ module Graphiform
19
19
  def self.graphql_type_single(active_record_type)
20
20
  return active_record_type unless active_record_type.respond_to?(:to_sym)
21
21
 
22
- case active_record_type.to_sym
23
- when :string, :text
24
- GraphQL::Types::String
25
- when :date
26
- GraphQL::Types::ISO8601Date
27
- when :time, :datetime, :timestamp
28
- GraphQL::Types::ISO8601DateTime
29
- when :integer
30
- GraphQL::Types::Int
31
- when :float, :decimal
32
- GraphQL::Types::Float
33
- when :boolean
34
- GraphQL::Types::Boolean
35
- when :json, :jsonb
36
- GraphQL::Types::JSON
37
- else
38
- active_record_type
39
- end
22
+ Graphiform.configuration[:scalar_mappings][active_record_type.to_sym] || active_record_type
40
23
  end
41
24
 
42
25
  def self.resolver?(val)
@@ -78,6 +61,10 @@ module Graphiform
78
61
  association_def.present? &&
79
62
  !association_def.polymorphic? &&
80
63
  !association_def.through_reflection? &&
64
+ (
65
+ !association_def.scope ||
66
+ association_def.scope.arity.zero?
67
+ ) &&
81
68
  !keys.is_a?(Array) &&
82
69
  !dataloader.is_a?(GraphQL::Dataloader::NullDataloader)
83
70
  )
@@ -1,3 +1,3 @@
1
1
  module Graphiform
2
- VERSION = '0.2.12'.freeze
2
+ VERSION = '0.2.13'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphiform
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.12
4
+ version: 0.2.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - jayce.pulsipher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-19 00:00:00.000000000 Z
11
+ date: 2021-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord