graphiti_gql 0.2.26 → 0.2.27

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: 00d26d5be2b1e9f1f277e0d0922faec91599f72a28fabe77ff16fb1f2ae6870f
4
- data.tar.gz: a868703b6bf2a2fbf88464396f0fe17ba836ffc183cee22e2aad06b5bd6a1223
3
+ metadata.gz: 8f6c4549cfff9295d8c6736efb65d443c8f189ca8c333b70ba24a764fa689b53
4
+ data.tar.gz: 71f1989c21eb48dde565f6523f798c8bd66080b572a51a00579768d29a1e87b9
5
5
  SHA512:
6
- metadata.gz: 02f91817b443a31d0eaa280316ddd1ab18691936e401c431a38354370f8a6a1b435076fa022df6d37041f35e08d06fb99fc8104aa957cca4e3b9507bba828117
7
- data.tar.gz: 94ca96b977800303c54ecf61fabfeeca65c4b839fc1ae501e6192fdbb30af86181a1aada59d64a47339c28ff3ca4e5469d071a27db9280a59e8c0b339b0f70f6
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.26)
4
+ graphiti_gql (0.2.27)
5
5
  activemodel (> 6.0, < 8.0)
6
6
  graphiti (~> 1.3.9)
7
7
  graphql (~> 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
@@ -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),
@@ -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
@@ -1,3 +1,3 @@
1
1
  module GraphitiGql
2
- VERSION = "0.2.26"
2
+ VERSION = "0.2.27"
3
3
  end
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 :application_controller
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.26
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-15 00:00:00.000000000 Z
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