graphql_rails 0.5.2 → 0.6.0
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/CHANGELOG.md +6 -0
- data/Gemfile.lock +1 -1
- data/lib/graphql_rails/controller.rb +2 -1
- data/lib/graphql_rails/controller/configuration.rb +2 -0
- data/lib/graphql_rails/router/plain_cursor_encoder.rb +16 -0
- data/lib/graphql_rails/router/schema_builder.rb +3 -0
- data/lib/graphql_rails/rspec_controller_helpers.rb +21 -10
- data/lib/graphql_rails/version.rb +1 -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: cfcbe2a73989218dd084672e7402c553db62d23825096ba28f8a8af615c8ec63
|
4
|
+
data.tar.gz: dee48916b9b0ee8c4205c4c69b62dd7a2608fd66c58e720792349f53be9508e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd658ca5e90d844b191ef11bbc87f5bd2f1e69cdcc07d4ce56726e3b9c23bc5c7c5056745c69d1fe95a322d67dcea131c9b8c6c14a566ee199b7d835cec508bc
|
7
|
+
data.tar.gz: c6637e6f95b4b48e671f5d3a0303bb33a8327cbfec4b93da41f64e7331728578f02ca33240a37b4bc8b7c371965acbd353d9263f36f7bbc9d94062d4b3dc62fc
|
data/CHANGELOG.md
CHANGED
@@ -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).
|
data/Gemfile.lock
CHANGED
@@ -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
|
72
|
+
@params ||= graphql_request.params.deep_transform_keys { |key| key.to_s.underscore }.with_indifferent_access
|
72
73
|
end
|
73
74
|
|
74
75
|
private
|
@@ -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
|
70
|
-
|
76
|
+
def initialize(controller)
|
77
|
+
@controller = controller
|
71
78
|
end
|
72
|
-
end
|
73
79
|
|
74
|
-
|
75
|
-
|
76
|
-
|
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
|
-
|
79
|
-
|
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
|
-
|
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
|
|
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.
|
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-
|
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
|