graphiti_gql 0.2.32 → 0.2.34

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: e8d0cda6314cfd3485283ae277bdaa56494a4b8eae9c62f9037b5b78f17b2825
4
- data.tar.gz: 28fcbab36f65c81bb8a673aefaefe7bd54888f02ca741fcf5a889f2f858e094a
3
+ metadata.gz: 389d9a348fca14259146eef09736c6a7358ff7ad824282fe6c838ee61ebf1ca0
4
+ data.tar.gz: 50dc70797c83ae98540c902df942487c3a3b4f183243331a51b44adc19064baf
5
5
  SHA512:
6
- metadata.gz: 864e7b0fbd88fb01f3aa8bc0490ce144a4d62e02c9d9ce30dc032f6209b91cf9e5766b06bf85113cbdb9d4603dd397b8b831fcbc8f76ff123ff12307e82a4815
7
- data.tar.gz: 61304ca30da99696a76c625c3737037429182df25ca6271c9f779bbbfa96740e2d1b3c792cbaaea560a31b52edc90f342b49a8aab12d607ece04804415e3d1e1
6
+ metadata.gz: c58333b9a7bbd43a68e27974d6a6cfdfdb9087e97ed5ca42d37be102995c15470f4279cd6499eef3ef7157f648dd8749e3df7d8921277139cbef39cd4bbaa34a
7
+ data.tar.gz: 378e41e41e6c1aa19b65274f29233aec4371e9cf44fd3dcf9dbf17404029230454ca8042bde7341177fe6349b9cc7233332546f4c10cae7b4ff4563176a9697d
@@ -2,10 +2,7 @@ module GraphitiGql
2
2
  class Engine < ::Rails::Engine
3
3
  isolate_namespace GraphitiGql
4
4
 
5
- config.to_prepare do
6
- Dir.glob("#{Rails.root}/app/resources/**/*").each { |f| require(f) }
7
- GraphitiGql.schema!
8
-
5
+ config.after_initialize do
9
6
  log_level = ENV.fetch('GRAPHITI_LOG_LEVEL', '1').to_i
10
7
  log_activerecord = false
11
8
  if log_level == -1 && defined?(ActiveRecord)
@@ -128,13 +128,21 @@ module GraphitiGql
128
128
  super
129
129
  # default behavior is to force single: true
130
130
  filters[name][:single] = false if boolean_array
131
-
131
+
132
132
  opts = args.extract_options!
133
133
  if opts[:if]
134
134
  attributes[name][:filterable] = opts[:if]
135
135
  end
136
136
  end
137
137
 
138
+ def sort(name, *args, &blk)
139
+ super
140
+ opts = args.extract_options!
141
+ if opts[:schema] == false
142
+ config[:sorts][name][:schema] = false
143
+ end
144
+ end
145
+
138
146
  def filter_group(filter_names, *args)
139
147
  if filter_names.blank?
140
148
  config[:grouped_filters] = {}
@@ -143,6 +151,14 @@ module GraphitiGql
143
151
  end
144
152
  end
145
153
 
154
+ def paginatable=(val)
155
+ config[:paginatable] = val
156
+ end
157
+
158
+ def paginatable
159
+ config[:paginatable] == false ? false : true
160
+ end
161
+
146
162
  def value_object?
147
163
  !!config[:is_value_object]
148
164
  end
@@ -289,7 +305,7 @@ module GraphitiGql
289
305
  attr_reader :join_table_alias, :edge_magic, :edge_resource
290
306
  end
291
307
  end
292
-
308
+
293
309
  def initialize(name, opts = {})
294
310
  @join_table_alias = opts[:join_table_alias]
295
311
  @edge_magic = opts[:edge_magic] == false ? false : true
@@ -431,7 +447,7 @@ module GraphitiGql
431
447
  clause = {attribute => value}
432
448
  is_not ? scope.where.not(clause) : scope.where(clause)
433
449
  end
434
-
450
+
435
451
  def sanitized_like_for(scope, attribute, value, &block)
436
452
  escape_char = "\\"
437
453
  column = column_for(scope, attribute)
@@ -493,7 +509,7 @@ module GraphitiGql
493
509
  hash
494
510
  end
495
511
  end
496
-
512
+
497
513
  Graphiti::Query.send(:prepend, QueryExtras)
498
514
  module ScopeExtras
499
515
  def initialize(object, resource, query, opts = {})
@@ -599,4 +615,4 @@ module Graphiti
599
615
  level ||= :debug
600
616
  logger.send(level, colored)
601
617
  end
602
- end
618
+ end
@@ -12,8 +12,8 @@ module GraphitiGql
12
12
  @registered[:type].connection_type,
13
13
  null: false,
14
14
  connection: false,
15
- extensions: [RelayConnectionExtension],
16
15
  extras: [:lookahead]
16
+ field.extension(RelayConnectionExtension, resource: resource)
17
17
  ListArguments.new(resource).apply(field)
18
18
  query.define_method name do |**arguments|
19
19
  params = Util.params_from_args(arguments)
@@ -14,11 +14,13 @@ module GraphitiGql
14
14
  connection: false,
15
15
  extras: [:lookahead]
16
16
  }
17
- opts[:extensions] = [RelayConnectionExtension] unless has_one?
18
17
  field_type = has_one? ? @sideload_type : @connection_type
19
18
  field = type.field @sideload.name,
20
19
  field_type,
21
20
  **opts
21
+ unless has_one?
22
+ field.extension(RelayConnectionExtension, resource: @sideload.resource.class)
23
+ end
22
24
  ListArguments.new(@sideload.resource.class, @sideload).apply(field)
23
25
  _sideload = @sideload
24
26
  type.define_method(@sideload.name) do |**arguments|
@@ -14,7 +14,7 @@ module GraphitiGql
14
14
 
15
15
  def apply(field)
16
16
  define_filters(field) unless @resource.filters.empty?
17
- define_sorts(field) unless @resource.sorts.empty?
17
+ define_sorts(field) unless sorts.empty?
18
18
  end
19
19
 
20
20
  private
@@ -39,7 +39,7 @@ module GraphitiGql
39
39
  required = true if @resource.grouped_filters.any? && !@sideload
40
40
  field.argument :filter, filter_type, required: required
41
41
  end
42
-
42
+
43
43
  def generate_filter_type(field)
44
44
  type_name = "#{registry.key_for(@resource)}Filter"
45
45
  if (registered = registry[type_name])
@@ -65,7 +65,7 @@ module GraphitiGql
65
65
  registry[type_name] = { type: klass }
66
66
  klass
67
67
  end
68
-
68
+
69
69
  def generate_filter_attribute_type(type_name, filter_name, filter_config)
70
70
  klass = Class.new(GraphQL::Schema::InputObject)
71
71
  filter_graphql_name = "#{type_name}Filter#{filter_name.to_s.camelize(:lower)}"
@@ -82,13 +82,13 @@ module GraphitiGql
82
82
  if (allowlist = filter_config[:allow])
83
83
  type = define_allowlist_type(filter_graphql_name, allowlist)
84
84
  end
85
-
85
+
86
86
  type = [type] unless !!filter_config[:single]
87
87
  klass.argument operator, type, required: false
88
88
  end
89
89
  klass
90
90
  end
91
-
91
+
92
92
  def define_allowlist_type(filter_graphql_name, allowlist)
93
93
  name = "#{filter_graphql_name}Allow"
94
94
  if (registered = registry[name])
@@ -103,6 +103,12 @@ module GraphitiGql
103
103
  klass
104
104
  end
105
105
 
106
+ def sorts
107
+ @resource.sorts.reject do |key, value|
108
+ value[:schema] == false
109
+ end
110
+ end
111
+
106
112
  def define_sorts(field)
107
113
  sort_type = generate_sort_type
108
114
  field.argument :sort, [sort_type], required: false
@@ -116,13 +122,13 @@ module GraphitiGql
116
122
  klass = Class.new(GraphQL::Schema::Enum) {
117
123
  graphql_name(type_name)
118
124
  }
119
- @resource.sorts.each_pair do |name, config|
125
+ sorts.each_pair do |name, config|
120
126
  klass.value name.to_s.camelize(:lower), "Sort by #{name}"
121
127
  end
122
128
  registry[type_name] = { type: klass }
123
129
  klass
124
130
  end
125
-
131
+
126
132
  def generate_sort_type
127
133
  type_name = "#{registry.key_for(@resource)}Sort"
128
134
  if (registered = registry[type_name])
@@ -139,4 +145,4 @@ module GraphitiGql
139
145
  end
140
146
  end
141
147
  end
142
- end
148
+ end
@@ -62,6 +62,10 @@ module GraphitiGql
62
62
  }
63
63
 
64
64
  class RelayConnectionExtension < GraphQL::Schema::Field::ConnectionExtension
65
+ def apply
66
+ super if options[:resource].paginatable
67
+ end
68
+
65
69
  def resolve(object:, arguments:, context:)
66
70
  next_args = arguments.dup
67
71
  yield(object, next_args, arguments)
@@ -98,8 +102,24 @@ module GraphitiGql
98
102
  @resources = resources
99
103
  end
100
104
 
105
+ def self.resource_types!
106
+ resources = Graphiti.resources.reject(&:abstract_class?)
107
+ resources.each { |resource| ResourceType.new(resource).build }
108
+ # add relationships
109
+ registry.resource_types.each do |registered|
110
+ resource, type = registered[:resource], registered[:type]
111
+ ResourceType.add_relationships(resource, type)
112
+ end
113
+ # add_value_objects
114
+ registry.resource_types(value_objects: false).each do |registered|
115
+ resource, type = registered[:resource], registered[:type]
116
+ ResourceType.add_value_objects(resource, type)
117
+ end
118
+ end
119
+
101
120
  def generate
102
- klass = Class.new(::GraphQL::Schema)
121
+ klass = Class.new(::GraphitiGql.config.base_schema || ::GraphQL::Schema)
122
+ # TODO inherit from klass.query if exists
103
123
  klass.query(Query.new(@resources).build)
104
124
  klass.use(GraphQL::Batch)
105
125
  klass.connections.add(ResponseShim, Connection)
@@ -1,3 +1,3 @@
1
1
  module GraphitiGql
2
- VERSION = "0.2.32"
2
+ VERSION = "0.2.34"
3
3
  end
data/lib/graphiti_gql.rb CHANGED
@@ -35,7 +35,10 @@ module GraphitiGql
35
35
  class Error < StandardError; end
36
36
 
37
37
  class Configuration
38
- attr_accessor :exception_handler, :error_handling, :logging
38
+ attr_accessor :base_schema,
39
+ :exception_handler,
40
+ :error_handling,
41
+ :logging
39
42
 
40
43
  def exception_handler
41
44
  @exception_handler ||= ExceptionHandler
@@ -57,7 +60,7 @@ module GraphitiGql
57
60
  end
58
61
 
59
62
  def self.schema
60
- @schema
63
+ @schema ||= schema!
61
64
  end
62
65
 
63
66
  def self.config
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphiti_gql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.32
4
+ version: 0.2.34
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Richmond
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-02 00:00:00.000000000 Z
11
+ date: 2022-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphql