graphiti_gql 0.2.24 → 0.2.27
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 +4 -4
- data/Gemfile.lock +3 -3
- data/lib/graphiti_gql/exception_handler.rb +52 -0
- data/lib/graphiti_gql/graphiti_hax.rb +27 -1
- data/lib/graphiti_gql/schema/list_arguments.rb +2 -0
- data/lib/graphiti_gql/schema/resource_type.rb +6 -4
- data/lib/graphiti_gql/schema.rb +9 -1
- data/lib/graphiti_gql/version.rb +1 -1
- data/lib/graphiti_gql.rb +10 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f6c4549cfff9295d8c6736efb65d443c8f189ca8c333b70ba24a764fa689b53
|
4
|
+
data.tar.gz: 71f1989c21eb48dde565f6523f798c8bd66080b572a51a00579768d29a1e87b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3879d099e79a23726bf32320d45a999dbfc4b6a7b2fe00982e330a6fc0ffb5cbe0c1940ae03dd18ef542eb26cf47ae9e14684a647dc21529a971e1986aef1184
|
7
|
+
data.tar.gz: d985550be802a4206905cd4980fb5f6c434fb6aad517915602d67c6b7eb6efdab70ee8f699fe7b8dde6e97bc9bee36b5a081525505ae0c6a09aa9bbf84e97129
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
graphiti_gql (0.2.
|
4
|
+
graphiti_gql (0.2.27)
|
5
5
|
activemodel (> 6.0, < 8.0)
|
6
6
|
graphiti (~> 1.3.9)
|
7
7
|
graphql (~> 2.0)
|
@@ -21,9 +21,9 @@ GEM
|
|
21
21
|
coderay (1.1.3)
|
22
22
|
concurrent-ruby (1.1.10)
|
23
23
|
diff-lcs (1.5.0)
|
24
|
-
dry-container (0.10.
|
24
|
+
dry-container (0.10.1)
|
25
25
|
concurrent-ruby (~> 1.0)
|
26
|
-
dry-core (0.8.
|
26
|
+
dry-core (0.8.1)
|
27
27
|
concurrent-ruby (~> 1.0)
|
28
28
|
dry-inflector (0.3.0)
|
29
29
|
dry-logic (1.2.0)
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module GraphitiGql
|
2
|
+
class ExceptionHandler
|
3
|
+
attr_reader :error, :context, :field
|
4
|
+
class_attribute :registry, :log, :notify, :default_message, :default_code
|
5
|
+
|
6
|
+
self.registry = {}
|
7
|
+
self.default_message = "We're sorry, something went wrong."
|
8
|
+
self.default_code = 500
|
9
|
+
|
10
|
+
def self.register_exception(err, opts)
|
11
|
+
registry[err] = opts
|
12
|
+
end
|
13
|
+
|
14
|
+
register_exception Graphiti::Errors::RecordNotFound, code: 404
|
15
|
+
register_exception Graphiti::Errors::SingularSideload, code: 400
|
16
|
+
register_exception Graphiti::Errors::InvalidAttributeAccess, code: 403
|
17
|
+
register_exception GraphitiGql::Errors::UnsupportedLast, code: 400
|
18
|
+
|
19
|
+
def initialize(err, obj, args, ctx, field)
|
20
|
+
@error = err
|
21
|
+
@obj = obj
|
22
|
+
@args = args
|
23
|
+
@context = ctx
|
24
|
+
@field = field
|
25
|
+
@config = get_config(err)
|
26
|
+
end
|
27
|
+
|
28
|
+
def notify
|
29
|
+
# noop
|
30
|
+
end
|
31
|
+
|
32
|
+
def log
|
33
|
+
# noop
|
34
|
+
end
|
35
|
+
|
36
|
+
def handle
|
37
|
+
notify if @config[:notify] != false
|
38
|
+
log if @config[:log] != false
|
39
|
+
|
40
|
+
message = @config[:message] ? err.message : default_message
|
41
|
+
code = @config[:code] || default_code
|
42
|
+
raise GraphQL::ExecutionError.new(message, extensions: { code: code })
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def get_config(error)
|
48
|
+
registered = registry.find { |e, _| error.is_a?(e) }
|
49
|
+
registered ? registered[1] : {}
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -88,7 +88,14 @@ module GraphitiGql
|
|
88
88
|
end
|
89
89
|
|
90
90
|
def filter(name, *args, &blk)
|
91
|
+
is_bool = (filters[name] && filters[name][:type] == :boolean) ||
|
92
|
+
args[0] == :boolean
|
93
|
+
opts = args.length == 1 ? args[0] : args[1]
|
94
|
+
boolean_array = is_bool && opts[:single] == false
|
91
95
|
super
|
96
|
+
# default behavior is to force single: true
|
97
|
+
filters[name][:single] = false if boolean_array
|
98
|
+
|
92
99
|
opts = args.extract_options!
|
93
100
|
if opts[:if]
|
94
101
|
attributes[name][:filterable] = opts[:if]
|
@@ -124,7 +131,7 @@ module GraphitiGql
|
|
124
131
|
|
125
132
|
def value_object(name, opts = {})
|
126
133
|
opts[:array] ||= false
|
127
|
-
opts[:null]
|
134
|
+
opts[:null] = true if opts[:null] != false
|
128
135
|
config[:value_objects][name] = Graphiti::ValueObjectAssociation.new(
|
129
136
|
name,
|
130
137
|
parent_resource_class: self,
|
@@ -431,6 +438,7 @@ module GraphitiGql
|
|
431
438
|
|
432
439
|
def resolve(*args)
|
433
440
|
results = super
|
441
|
+
raise Graphiti::Errors::InvalidResolve unless results.is_a?(Array)
|
434
442
|
results.reverse! if @query.hash[:reverse]
|
435
443
|
results
|
436
444
|
end
|
@@ -451,6 +459,24 @@ module GraphitiGql
|
|
451
459
|
end
|
452
460
|
end
|
453
461
|
|
462
|
+
class Graphiti::Errors::InvalidResolve < Graphiti::Errors::Base
|
463
|
+
def message
|
464
|
+
"Resource#resolve must always return an array"
|
465
|
+
end
|
466
|
+
end
|
467
|
+
|
468
|
+
class Graphiti::Errors::InvalidValueObject < Graphiti::Errors::Base
|
469
|
+
def initialize(resource, name, value)
|
470
|
+
@resource = resource
|
471
|
+
@name = name
|
472
|
+
@value = value
|
473
|
+
end
|
474
|
+
|
475
|
+
def message
|
476
|
+
"#{@resource} - value object '#{@name}' configured with array: true but returned non-array: #{@value.inspect}"
|
477
|
+
end
|
478
|
+
end
|
479
|
+
|
454
480
|
class Graphiti::ValueObjectAssociation
|
455
481
|
attr_reader :name,
|
456
482
|
:parent_resource_class,
|
@@ -54,6 +54,8 @@ module GraphitiGql
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
@resource.filters.each_pair do |name, config|
|
57
|
+
next if config[:schema] == false
|
58
|
+
|
57
59
|
attr_type = generate_filter_attribute_type(type_name, name, config)
|
58
60
|
required = !!config[:required] || required_via_group.include?(name)
|
59
61
|
klass.argument name.to_s.camelize(:lower),
|
@@ -44,12 +44,14 @@ module GraphitiGql
|
|
44
44
|
end
|
45
45
|
|
46
46
|
result = vo_resource_class.all({ parent: object }).to_a
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
if result == object || result == [object]
|
47
|
+
default_behavior = result == [object]
|
48
|
+
result = result.first if !_array
|
49
|
+
if default_behavior
|
51
50
|
method_name = vo_association.alias.presence || name
|
52
51
|
result = object.send(method_name)
|
52
|
+
if _array && !result.is_a?(Array)
|
53
|
+
raise Graphiti::Errors::InvalidValueObject.new(resource, name, result)
|
54
|
+
end
|
53
55
|
end
|
54
56
|
result
|
55
57
|
end
|
data/lib/graphiti_gql/schema.rb
CHANGED
@@ -36,7 +36,7 @@ module GraphitiGql
|
|
36
36
|
integer: Integer,
|
37
37
|
big_integer: GraphQL::Types::BigInt,
|
38
38
|
float: Float,
|
39
|
-
boolean: GraphQL::
|
39
|
+
boolean: GraphQL::Types::Boolean,
|
40
40
|
date: GraphQL::Types::ISO8601Date,
|
41
41
|
datetime: GraphQL::Types::ISO8601DateTime,
|
42
42
|
precise_datetime: PreciseDatetime,
|
@@ -101,6 +101,14 @@ module GraphitiGql
|
|
101
101
|
klass.connections.add(ResponseShim, Connection)
|
102
102
|
klass.connections.add(Array, ToManyConnection)
|
103
103
|
klass.orphan_types [GraphQL::Types::JSON]
|
104
|
+
klass.rescue_from(Exception) do |err, obj, args, ctx, field|
|
105
|
+
if GraphitiGql.config.error_handling
|
106
|
+
handler = GraphitiGql.config.exception_handler
|
107
|
+
handler.new(err, obj, args, ctx, field).handle
|
108
|
+
else
|
109
|
+
raise err
|
110
|
+
end
|
111
|
+
end
|
104
112
|
klass
|
105
113
|
end
|
106
114
|
end
|
data/lib/graphiti_gql/version.rb
CHANGED
data/lib/graphiti_gql.rb
CHANGED
@@ -27,13 +27,22 @@ require "graphiti_gql/schema/fields/to_one"
|
|
27
27
|
require "graphiti_gql/schema/fields/attribute"
|
28
28
|
require "graphiti_gql/schema/fields/stats"
|
29
29
|
require "graphiti_gql/active_resource"
|
30
|
+
require "graphiti_gql/exception_handler"
|
30
31
|
require "graphiti_gql/engine" if defined?(Rails)
|
31
32
|
|
32
33
|
module GraphitiGql
|
33
34
|
class Error < StandardError; end
|
34
35
|
|
35
36
|
class Configuration
|
36
|
-
attr_accessor :
|
37
|
+
attr_accessor :exception_handler, :error_handling
|
38
|
+
|
39
|
+
def exception_handler
|
40
|
+
@exception_handler ||= ExceptionHandler
|
41
|
+
end
|
42
|
+
|
43
|
+
def error_handling
|
44
|
+
@error_handling != false
|
45
|
+
end
|
37
46
|
end
|
38
47
|
|
39
48
|
def self.schema!
|
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.27
|
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-08-
|
11
|
+
date: 2022-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|
@@ -146,6 +146,7 @@ files:
|
|
146
146
|
- lib/graphiti_gql/active_resource.rb
|
147
147
|
- lib/graphiti_gql/engine.rb
|
148
148
|
- lib/graphiti_gql/errors.rb
|
149
|
+
- lib/graphiti_gql/exception_handler.rb
|
149
150
|
- lib/graphiti_gql/graphiti_hax.rb
|
150
151
|
- lib/graphiti_gql/loaders/belongs_to.rb
|
151
152
|
- lib/graphiti_gql/loaders/has_many.rb
|