graphql_rails 0.5.2 → 0.6.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: d31436f40d036cd543c69a2b59e442d2498eb6349d61c4454dc9376e0caf4de0
4
- data.tar.gz: 9b5041b648314fbff349e614e9b1f6be43f94bff32490f8de0dc4a23bb28c6a7
3
+ metadata.gz: cfcbe2a73989218dd084672e7402c553db62d23825096ba28f8a8af615c8ec63
4
+ data.tar.gz: dee48916b9b0ee8c4205c4c69b62dd7a2608fd66c58e720792349f53be9508e9
5
5
  SHA512:
6
- metadata.gz: 72d4881a3aa604c19f38f53e4b77fdea562e7b804d8cec6a125789da32b6b215c298f5dcd1a747680a72c2e65571d0f30ab7b47597758fbb632bf21731f9bf70
7
- data.tar.gz: 0a7ec0c5d6bf383c89b82109a4c120137e470f7e187ab8a3ab791840706abd6b0a49933b1bcead76437603fff546fc66ebd024fad8067bea6558d60499c587b0
6
+ metadata.gz: cd658ca5e90d844b191ef11bbc87f5bd2f1e69cdcc07d4ce56726e3b9c23bc5c7c5056745c69d1fe95a322d67dcea131c9b8c6c14a566ee199b7d835cec508bc
7
+ data.tar.gz: c6637e6f95b4b48e671f5d3a0303bb33a8327cbfec4b93da41f64e7331728578f02ca33240a37b4bc8b7c371965acbd353d9263f36f7bbc9d94062d4b3dc62fc
@@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9
9
 
10
10
  * Added/Changed/Deprecated/Removed/Fixed/Security: YOUR CHANGE HERE
11
11
 
12
+ ## 0.6.0 (2019-04-29)
13
+
14
+ * Breaking change: controller params are always underscored [@povilasjurcys](https://github.com/povilasjurcys).
15
+ * Breaking change: cursor in paginated responses has plain index value by default [@povilasjurcys](https://github.com/povilasjurcys).
16
+ * Fixed: do not crash when testing paginated actions [@povilasjurcys](https://github.com/povilasjurcys).
17
+
12
18
  ## 0.5.2 (2019-04-24)
13
19
 
14
20
  * Fixed: do not crash when using Connection types in non Ruby on Rails project [@povilasjurcys](https://github.com/povilasjurcys).
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- graphql_rails (0.5.2)
4
+ graphql_rails (0.6.0)
5
5
  activesupport (>= 4)
6
6
  graphql (~> 1)
7
7
 
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'active_support/hash_with_indifferent_access'
4
+ require 'active_support/core_ext/hash'
4
5
  require 'graphql_rails/controller/configuration'
5
6
  require 'graphql_rails/controller/request'
6
7
  require 'graphql_rails/controller/format_results'
@@ -68,7 +69,7 @@ module GraphqlRails
68
69
  end
69
70
 
70
71
  def params
71
- @params = HashWithIndifferentAccess.new(graphql_request.params)
72
+ @params ||= graphql_request.params.deep_transform_keys { |key| key.to_s.underscore }.with_indifferent_access
72
73
  end
73
74
 
74
75
  private
@@ -9,6 +9,8 @@ module GraphqlRails
9
9
  class Controller
10
10
  # stores all graphql_rails contoller specific config
11
11
  class Configuration
12
+ attr_reader :action_by_name
13
+
12
14
  def initialize
13
15
  @hooks = {
14
16
  before: {},
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GraphqlRails
4
+ class Router
5
+ # simplest possible cursor encoder which returns element index
6
+ module PlainCursorEncoder
7
+ def self.encode(plain, _nonce)
8
+ plain
9
+ end
10
+
11
+ def self.decode(plain, _nonce)
12
+ plain
13
+ end
14
+ end
15
+ end
16
+ end
@@ -4,6 +4,8 @@ module GraphqlRails
4
4
  class Router
5
5
  # builds GraphQL::Schema based on previously defined grahiti data
6
6
  class SchemaBuilder
7
+ require_relative './plain_cursor_encoder'
8
+
7
9
  attr_reader :queries, :mutations, :raw_actions
8
10
 
9
11
  def initialize(queries:, mutations:, raw_actions:)
@@ -18,6 +20,7 @@ module GraphqlRails
18
20
  raw = raw_actions
19
21
 
20
22
  GraphQL::Schema.define do
23
+ cursor_encoder(Router::PlainCursorEncoder)
21
24
  raw.each { |action| send(action[:name], *action[:args], &action[:block]) }
22
25
 
23
26
  query(query_type)
@@ -55,28 +55,38 @@ module GraphqlRails
55
55
  class FakeContext
56
56
  extend Forwardable
57
57
 
58
+ attr_reader :schema
59
+
58
60
  def_delegators :@provided_values, :[], :[]=, :to_h, :key?, :fetch
59
61
 
60
- def initialize(values:)
62
+ def initialize(values:, schema:)
61
63
  @errors = []
62
64
  @provided_values = values
65
+ @schema = schema
63
66
  end
64
67
 
65
68
  def add_error(error)
66
69
  @errors << error
67
70
  end
71
+ end
72
+
73
+ class SingleControllerSchemaBuilder
74
+ attr_reader :controller
68
75
 
69
- def schema
70
- FakeSchema.new
76
+ def initialize(controller)
77
+ @controller = controller
71
78
  end
72
- end
73
79
 
74
- # instance which has similar behavior as
75
- class FakeSchema
76
- def initialize; end
80
+ def call
81
+ config = controller.controller_configuration
82
+ action_by_name = config.action_by_name
83
+ controller_path = controller.name.underscore.sub(/_controller\Z/, '')
77
84
 
78
- def cursor_encoder
79
- GraphQL::Schema::Base64Encoder
85
+ Router.draw do
86
+ action_by_name.keys.each do |action_name|
87
+ query("#{action_name}_test", to: "#{controller_path}##{action_name}")
88
+ end
89
+ end
80
90
  end
81
91
  end
82
92
 
@@ -88,7 +98,8 @@ module GraphqlRails
88
98
  end
89
99
 
90
100
  def query(query_name, params: {}, context: {})
91
- context_object = FakeContext.new(values: context)
101
+ schema_builder = SingleControllerSchemaBuilder.new(described_class)
102
+ context_object = FakeContext.new(values: context, schema: schema_builder.call)
92
103
  request = Request.new(params, context_object)
93
104
  described_class.new(request).call(query_name)
94
105
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GraphqlRails
4
- VERSION = '0.5.2'
4
+ VERSION = '0.6.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Povilas Jurčys
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-25 00:00:00.000000000 Z
11
+ date: 2019-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphql
@@ -168,6 +168,7 @@ files:
168
168
  - lib/graphql_rails/model/input_attribute.rb
169
169
  - lib/graphql_rails/router.rb
170
170
  - lib/graphql_rails/router/mutation_route.rb
171
+ - lib/graphql_rails/router/plain_cursor_encoder.rb
171
172
  - lib/graphql_rails/router/query_route.rb
172
173
  - lib/graphql_rails/router/resource_routes_builder.rb
173
174
  - lib/graphql_rails/router/route.rb