graphiti_gql 0.2.33 → 0.2.35
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/fields/to_many.rb +3 -2
- data/lib/graphiti_gql/schema/list_arguments.rb +14 -8
- data/lib/graphiti_gql/schema/query.rb +0 -17
- data/lib/graphiti_gql/schema.rb +18 -1
- data/lib/graphiti_gql/version.rb +1 -1
- data/lib/graphiti_gql.rb +5 -3
- 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: 5e404a080bb36a50e41942d18eadaa0813c92eef0c965adf07dcddb80218b151
|
4
|
+
data.tar.gz: 20f073ab99227e37bdf357511b58e96172994682d5d3dcd881abdb8d4f1a2bca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba6307b54c651e5367555290ee756db75c3c0a9f6504167f16968d564b88bdd6fb5c7d7e8cc73982d321157ad59039688d107f834ab61078b350783e16259a5d
|
7
|
+
data.tar.gz: 1c3e2611f9fd313097b807b0b09082d037c34a9ffc87ce749b36b3283a9d98c428374fa64d1e4eca4d0c47b9918b2f9738b4e1054177c55e9e881ff6eda9c457
|
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
|
@@ -4,6 +4,7 @@ module GraphitiGql
|
|
4
4
|
class ToMany
|
5
5
|
def initialize(sideload, sideload_type)
|
6
6
|
@sideload = sideload
|
7
|
+
@sideload_resource = Schema.registry.get(sideload.resource.class)[:resource]
|
7
8
|
@sideload_type = sideload_type
|
8
9
|
@connection_type = find_or_build_connection
|
9
10
|
end
|
@@ -19,9 +20,9 @@ module GraphitiGql
|
|
19
20
|
field_type,
|
20
21
|
**opts
|
21
22
|
unless has_one?
|
22
|
-
field.extension(RelayConnectionExtension, resource: @
|
23
|
+
field.extension(RelayConnectionExtension, resource: @sideload_resource)
|
23
24
|
end
|
24
|
-
ListArguments.new(@
|
25
|
+
ListArguments.new(@sideload_resource, @sideload).apply(field)
|
25
26
|
_sideload = @sideload
|
26
27
|
type.define_method(@sideload.name) do |**arguments|
|
27
28
|
Util.is_readable_sideload!(_sideload)
|
@@ -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
|
@@ -8,10 +8,7 @@ module GraphitiGql
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def build
|
11
|
-
@resources.each { |resource| ResourceType.new(resource).build }
|
12
11
|
define_entrypoints
|
13
|
-
add_value_objects
|
14
|
-
add_relationships
|
15
12
|
@query_class
|
16
13
|
end
|
17
14
|
|
@@ -29,20 +26,6 @@ module GraphitiGql
|
|
29
26
|
end
|
30
27
|
end
|
31
28
|
end
|
32
|
-
|
33
|
-
def add_relationships
|
34
|
-
registry.resource_types.each do |registered|
|
35
|
-
resource, type = registered[:resource], registered[:type]
|
36
|
-
ResourceType.add_relationships(resource, type)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def add_value_objects
|
41
|
-
registry.resource_types(value_objects: false).each do |registered|
|
42
|
-
resource, type = registered[:resource], registered[:type]
|
43
|
-
ResourceType.add_value_objects(resource, type)
|
44
|
-
end
|
45
|
-
end
|
46
29
|
end
|
47
30
|
end
|
48
31
|
end
|
data/lib/graphiti_gql/schema.rb
CHANGED
@@ -102,8 +102,25 @@ 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
|
+
return if klass.query
|
123
|
+
# TODO inherit from klass.query if exists
|
107
124
|
klass.query(Query.new(@resources).build)
|
108
125
|
klass.use(GraphQL::Batch)
|
109
126
|
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
|
@@ -51,13 +54,12 @@ module GraphitiGql
|
|
51
54
|
end
|
52
55
|
|
53
56
|
def self.schema!
|
54
|
-
Schema::Registry.instance.clear
|
55
57
|
resources ||= Graphiti.resources.reject(&:abstract_class?)
|
56
58
|
@schema = Schema.new(resources).generate
|
57
59
|
end
|
58
60
|
|
59
61
|
def self.schema
|
60
|
-
@schema
|
62
|
+
@schema ||= schema!
|
61
63
|
end
|
62
64
|
|
63
65
|
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.35
|
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-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|