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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d5ee73a9e584baf90ba0f71fae3e818708232268f87eb5042e10890d3f261dc5
4
- data.tar.gz: 7f0341ca0b3af1f912f57fae80db5a9f2023a59efc781fd6f028b9e8e973c19e
3
+ metadata.gz: dab4208b219514517e1f78887dfe928b89f0151b0f44afeea8ecae88e61f61f4
4
+ data.tar.gz: deea1e3419629c3238b31fe286c67dd84002c1029efd2eb3ff7f2b2208956d28
5
5
  SHA512:
6
- metadata.gz: 61a1a30582caccc372d2a4aafd0c17cc81012f77d3ad147665726320cea121f457f6ff9fa5866c806940b68f922c1a3ee376777c330fa2ad817a7c31efd1df6e
7
- data.tar.gz: e0d49d3a319fae588deb6dfb6069b34bf2d23b9b0f2c431ebe23876a346fda2fd017ff53b97f10923130c5e7397835276fbb0746cab47c8094db5c055c86eeea
6
+ metadata.gz: f219b4cac2aab9ab621e4c84543048a50e494109dc7dcb13067d1eb45f3086110db6fa97962c09da5d53776be4f6e37eb7407cc9f915838bcbad7fe8f9ad9ee4
7
+ data.tar.gz: a4f1e762e57d2043aa139730487376fdb6938b246522a407162188858df03926982a7bcc937369386691605137873a9cad46a3e0b66b7b8a6068fbde9b019b2b
@@ -5,3 +5,9 @@ rvm:
5
5
  env:
6
6
  - COVERALLS_RUN_LOCALLY=true
7
7
  before_install: gem install bundler -v 1.15.3
8
+ matrix:
9
+ include:
10
+ - gemfile: graphql-1.7.gemfile
11
+ env: GRAPHQL_RUBY_VERSION=1_7
12
+ - gemfile: graphql-1.8.gemfile
13
+ env: GRAPHQL_RUBY_VERSION=1_8
@@ -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.2.0...HEAD)
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
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+ gem 'pry'
4
4
 
5
- gem 'coveralls', require: false
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
 
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "pry"
4
+ gem 'coveralls'
5
+ gem 'batch-loader', '~> 1.2'
6
+
7
+ gem "graphql", "~> 1.7.14"
8
+
9
+ gemspec
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "pry"
4
+ gem 'coveralls'
5
+ gem 'batch-loader', '~> 1.2'
6
+
7
+ gem "graphql", "~> 1.8.4"
8
+
9
+ gemspec
@@ -23,19 +23,21 @@ module GraphQL
23
23
 
24
24
  def instrument(_type, field)
25
25
  old_resolve_proc = field.resolve_proc
26
- new_resolve_proc = ->(object, arguments, context) do
27
- begin
28
- old_resolve_proc.call(object, arguments, context)
29
- rescue => exception
30
- if handler = find_handler(exception)
31
- handler.call(exception, object, arguments, context)
32
- else
33
- raise exception
34
- end
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 { resolve(new_resolve_proc) }
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)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module GraphQL
4
4
  class Errors
5
- VERSION = "0.2.0"
5
+ VERSION = "0.3.0"
6
6
  end
7
7
  end
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.2.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-03-15 00:00:00.000000000 Z
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