graphiti_gql 0.2.33 → 0.2.34
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/graphiti_gql/engine.rb +1 -4
- data/lib/graphiti_gql/graphiti_hax.rb +13 -5
- data/lib/graphiti_gql/schema/list_arguments.rb +14 -8
- data/lib/graphiti_gql/schema.rb +17 -1
- data/lib/graphiti_gql/version.rb +1 -1
- data/lib/graphiti_gql.rb +5 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 389d9a348fca14259146eef09736c6a7358ff7ad824282fe6c838ee61ebf1ca0
|
4
|
+
data.tar.gz: 50dc70797c83ae98540c902df942487c3a3b4f183243331a51b44adc19064baf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c58333b9a7bbd43a68e27974d6a6cfdfdb9087e97ed5ca42d37be102995c15470f4279cd6499eef3ef7157f648dd8749e3df7d8921277139cbef39cd4bbaa34a
|
7
|
+
data.tar.gz: 378e41e41e6c1aa19b65274f29233aec4371e9cf44fd3dcf9dbf17404029230454ca8042bde7341177fe6349b9cc7233332546f4c10cae7b4ff4563176a9697d
|
data/lib/graphiti_gql/engine.rb
CHANGED
@@ -2,10 +2,7 @@ module GraphitiGql
|
|
2
2
|
class Engine < ::Rails::Engine
|
3
3
|
isolate_namespace GraphitiGql
|
4
4
|
|
5
|
-
config.
|
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] = {}
|
@@ -297,7 +305,7 @@ module GraphitiGql
|
|
297
305
|
attr_reader :join_table_alias, :edge_magic, :edge_resource
|
298
306
|
end
|
299
307
|
end
|
300
|
-
|
308
|
+
|
301
309
|
def initialize(name, opts = {})
|
302
310
|
@join_table_alias = opts[:join_table_alias]
|
303
311
|
@edge_magic = opts[:edge_magic] == false ? false : true
|
@@ -439,7 +447,7 @@ module GraphitiGql
|
|
439
447
|
clause = {attribute => value}
|
440
448
|
is_not ? scope.where.not(clause) : scope.where(clause)
|
441
449
|
end
|
442
|
-
|
450
|
+
|
443
451
|
def sanitized_like_for(scope, attribute, value, &block)
|
444
452
|
escape_char = "\\"
|
445
453
|
column = column_for(scope, attribute)
|
@@ -501,7 +509,7 @@ module GraphitiGql
|
|
501
509
|
hash
|
502
510
|
end
|
503
511
|
end
|
504
|
-
|
512
|
+
|
505
513
|
Graphiti::Query.send(:prepend, QueryExtras)
|
506
514
|
module ScopeExtras
|
507
515
|
def initialize(object, resource, query, opts = {})
|
@@ -607,4 +615,4 @@ module Graphiti
|
|
607
615
|
level ||= :debug
|
608
616
|
logger.send(level, colored)
|
609
617
|
end
|
610
|
-
end
|
618
|
+
end
|
@@ -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
|
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
|
-
|
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
|
data/lib/graphiti_gql/schema.rb
CHANGED
@@ -102,8 +102,24 @@ module GraphitiGql
|
|
102
102
|
@resources = resources
|
103
103
|
end
|
104
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
|
+
|
105
120
|
def generate
|
106
|
-
klass = Class.new(::GraphQL::Schema)
|
121
|
+
klass = Class.new(::GraphitiGql.config.base_schema || ::GraphQL::Schema)
|
122
|
+
# TODO inherit from klass.query if exists
|
107
123
|
klass.query(Query.new(@resources).build)
|
108
124
|
klass.use(GraphQL::Batch)
|
109
125
|
klass.connections.add(ResponseShim, Connection)
|
data/lib/graphiti_gql/version.rb
CHANGED
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 :
|
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.
|
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-
|
11
|
+
date: 2022-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|