graphql-errors 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -0
- data/CHANGELOG.md +5 -1
- data/Gemfile +3 -2
- data/README.md +1 -1
- data/graphql-1.7.gemfile +9 -0
- data/graphql-1.8.gemfile +9 -0
- data/lib/graphql/errors.rb +25 -11
- data/lib/graphql/errors/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dab4208b219514517e1f78887dfe928b89f0151b0f44afeea8ecae88e61f61f4
|
4
|
+
data.tar.gz: deea1e3419629c3238b31fe286c67dd84002c1029efd2eb3ff7f2b2208956d28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f219b4cac2aab9ab621e4c84543048a50e494109dc7dcb13067d1eb45f3086110db6fa97962c09da5d53776be4f6e37eb7407cc9f915838bcbad7fe8f9ad9ee4
|
7
|
+
data.tar.gz: a4f1e762e57d2043aa139730487376fdb6938b246522a407162188858df03926982a7bcc937369386691605137873a9cad46a3e0b66b7b8a6068fbde9b019b2b
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -8,10 +8,14 @@ one of the following labels: `Added`, `Changed`, `Deprecated`,
|
|
8
8
|
to manage the versions of this gem so
|
9
9
|
that you can set version constraints properly.
|
10
10
|
|
11
|
-
#### [Unreleased](https://github.com/exAspArk/graphql-errors/compare/v0.
|
11
|
+
#### [Unreleased](https://github.com/exAspArk/graphql-errors/compare/v0.3.0...HEAD)
|
12
12
|
|
13
13
|
* WIP
|
14
14
|
|
15
|
+
#### [v0.3.0](https://github.com/exAspArk/graphql-errors/compare/v0.2.0...v0.3.0) – 2018-12-17
|
16
|
+
|
17
|
+
* `Added`: handle errors from lazy resolvers. [#14](https://github.com/exAspArk/graphql-errors/pull/14)
|
18
|
+
|
15
19
|
#### [v0.2.0](https://github.com/exAspArk/graphql-errors/compare/v0.1.0...v0.2.0) – 2018-03-15
|
16
20
|
|
17
21
|
* `Added`: `object, argument, context` to rescue_from. [#8](https://github.com/exAspArk/graphql-errors/pull/8)
|
data/Gemfile
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
source "https://rubygems.org"
|
2
2
|
|
3
|
-
|
3
|
+
gem 'pry'
|
4
4
|
|
5
|
-
gem '
|
5
|
+
gem 'graphql', '~> 1.8.4'
|
6
|
+
gem 'batch-loader', '~> 1.2'
|
6
7
|
|
7
8
|
# Specify your gem's dependencies in graphql-errors.gemspec
|
8
9
|
gemspec
|
data/README.md
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/exAspArk/graphql-errors.svg?branch=master)](https://travis-ci.org/exAspArk/graphql-errors)
|
4
4
|
[![Coverage Status](https://coveralls.io/repos/github/exAspArk/graphql-errors/badge.svg?branch=master)](https://coveralls.io/github/exAspArk/graphql-errors?branch=master)
|
5
|
-
[![Code Climate](https://img.shields.io/codeclimate/github/exAspArk/graphql-errors.svg)](https://codeclimate.com/github/exAspArk/graphql-errors)
|
6
5
|
[![Downloads](https://img.shields.io/gem/dt/graphql-errors.svg)](https://rubygems.org/gems/graphql-errors)
|
7
6
|
[![Latest Version](https://img.shields.io/gem/v/graphql-errors.svg)](https://rubygems.org/gems/graphql-errors)
|
8
7
|
|
@@ -17,6 +16,7 @@ This gem provides a simple error handling for [graphql-ruby](https://github.com/
|
|
17
16
|
|
18
17
|
* Error handling for each field.
|
19
18
|
* Logic inside the `rescue_from` block, similarly to Rails.
|
19
|
+
* Catching exceptions by ancestors, e.g. `CustomError` with `rescue_from StandardError`.
|
20
20
|
* Per schema configuration.
|
21
21
|
* No dependencies.
|
22
22
|
|
data/graphql-1.7.gemfile
ADDED
data/graphql-1.8.gemfile
ADDED
data/lib/graphql/errors.rb
CHANGED
@@ -23,19 +23,21 @@ module GraphQL
|
|
23
23
|
|
24
24
|
def instrument(_type, field)
|
25
25
|
old_resolve_proc = field.resolve_proc
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end
|
26
|
+
|
27
|
+
new_resolve_proc = lambda do |obj, args, ctx|
|
28
|
+
wrap_proc(obj, args, ctx, old_resolve_proc)
|
29
|
+
end
|
30
|
+
|
31
|
+
old_lazy_resolve_proc = field.lazy_resolve_proc
|
32
|
+
|
33
|
+
new_lazy_resolve_proc = lambda do |obj, args, ctx|
|
34
|
+
wrap_proc(obj, args, ctx, old_lazy_resolve_proc)
|
36
35
|
end
|
37
36
|
|
38
|
-
field.redefine
|
37
|
+
field.redefine do
|
38
|
+
resolve(new_resolve_proc)
|
39
|
+
lazy_resolve(new_lazy_resolve_proc)
|
40
|
+
end
|
39
41
|
end
|
40
42
|
|
41
43
|
def rescue_from(*classes, &block)
|
@@ -49,6 +51,18 @@ module GraphQL
|
|
49
51
|
|
50
52
|
private
|
51
53
|
|
54
|
+
def wrap_proc(object, arguments, context, old_proc)
|
55
|
+
begin
|
56
|
+
old_proc.call(object, arguments, context)
|
57
|
+
rescue => exception
|
58
|
+
if handler = find_handler(exception)
|
59
|
+
handler.call(exception, object, arguments, context)
|
60
|
+
else
|
61
|
+
raise exception
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
52
66
|
def find_handler(exception)
|
53
67
|
@handler_by_class.each do |klass, handler|
|
54
68
|
return handler if exception.is_a?(klass)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphql-errors
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- exAspArk
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|
@@ -105,6 +105,8 @@ files:
|
|
105
105
|
- Rakefile
|
106
106
|
- bin/console
|
107
107
|
- bin/setup
|
108
|
+
- graphql-1.7.gemfile
|
109
|
+
- graphql-1.8.gemfile
|
108
110
|
- graphql-errors.gemspec
|
109
111
|
- images/universe.png
|
110
112
|
- lib/graphql/errors.rb
|