graphql_rails 0.4.2 → 0.4.3
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3c30cddc8d921388e200982dc22033da8a3decd449fa44a228d320a52bfd18a
|
4
|
+
data.tar.gz: a783527f323172eac78cf725beea3b931b94f9ad2b8477e59d8cf395c8122c43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f76e5e25f3c1e58c557b8dbeb77d0dba51815c9dd442c6adcd30e82481fb4b999831c2bf8b4beaae05c79e18226d04db6069b35e68bb845a201e171aa9000fb2
|
7
|
+
data.tar.gz: 7ca367ea5bbaf9341f0326f77eef2c515b29f233d8fb3000586cf3f16ecba1cd96f4e93dbe5106750fcd4ca2a99b7e7ca58e3b4aabde7eeab56bd0c94d58be31
|
data/Gemfile.lock
CHANGED
@@ -20,9 +20,25 @@ end
|
|
20
20
|
|
21
21
|
### *permit*
|
22
22
|
|
23
|
+
to define attributes which are accepted by each controller action, you need to call `permit` method, like this:
|
24
|
+
|
23
25
|
```ruby
|
24
26
|
class UsersController < GraphqlRails::Controller
|
25
|
-
action(:create).
|
27
|
+
action(:create).permit(:id!, :some_string_value)
|
28
|
+
|
29
|
+
def create
|
30
|
+
User.create(params)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
permitted values will be available via `params` method in controller action. By default all attributes will have `String` type. Also you can add exclamation mark after attribute name if you want to forbid `nil` value for that attribute.
|
36
|
+
|
37
|
+
If you want to use custom input type, you can define it like this:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
class UsersController < GraphqlRails::Controller
|
41
|
+
action(:create).permit(:id!, some_integer_value: :int!, something_custom: YourGraphqlInputType)
|
26
42
|
|
27
43
|
def create
|
28
44
|
User.create(params)
|
@@ -8,7 +8,7 @@ module GraphqlRails
|
|
8
8
|
class Controller
|
9
9
|
# stores all graphql_rails contoller specific config
|
10
10
|
class ActionConfiguration
|
11
|
-
attr_reader :attributes, :
|
11
|
+
attr_reader :attributes, :pagination_options
|
12
12
|
|
13
13
|
def initialize_copy(other)
|
14
14
|
super
|
@@ -27,6 +27,7 @@ module GraphqlRails
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def paginated(pagination_options = {})
|
30
|
+
@return_type = nil
|
30
31
|
@pagination_options = pagination_options
|
31
32
|
permit(:before, :after, first: :int, last: :int)
|
32
33
|
end
|
@@ -45,8 +46,9 @@ module GraphqlRails
|
|
45
46
|
self
|
46
47
|
end
|
47
48
|
|
48
|
-
def returns(
|
49
|
-
@return_type =
|
49
|
+
def returns(custom_return_type)
|
50
|
+
@return_type = nil
|
51
|
+
@custom_return_type = custom_return_type
|
50
52
|
self
|
51
53
|
end
|
52
54
|
|
@@ -58,8 +60,28 @@ module GraphqlRails
|
|
58
60
|
!!pagination_options # rubocop:disable Style/DoubleNegation
|
59
61
|
end
|
60
62
|
|
63
|
+
def return_type
|
64
|
+
@return_type ||= build_return_type
|
65
|
+
end
|
66
|
+
|
61
67
|
private
|
62
68
|
|
69
|
+
attr_reader :custom_return_type
|
70
|
+
|
71
|
+
def build_return_type
|
72
|
+
return nil if custom_return_type.nil?
|
73
|
+
|
74
|
+
if paginated?
|
75
|
+
type_parser.graphql_model ? type_parser.graphql_model.graphql.connection_type : nil
|
76
|
+
else
|
77
|
+
type_parser.graphql_type
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def type_parser
|
82
|
+
TypeParser.new(custom_return_type)
|
83
|
+
end
|
84
|
+
|
63
85
|
def permit_attribute(name, type = nil)
|
64
86
|
field_name = name.to_s.remove(/!\Z/)
|
65
87
|
attributes[field_name] = Attribute.new(name.to_s, type)
|
@@ -31,7 +31,7 @@ module GraphqlRails
|
|
31
31
|
@unparsed_type = unparsed_type
|
32
32
|
end
|
33
33
|
|
34
|
-
def
|
34
|
+
def graphql_type
|
35
35
|
return unparsed_type if raw_graphql_type?
|
36
36
|
|
37
37
|
if list?
|
@@ -41,6 +41,12 @@ module GraphqlRails
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
+
def graphql_model
|
45
|
+
type_class = inner_type_name.safe_constantize
|
46
|
+
return unless type_class.respond_to?(:graphql)
|
47
|
+
type_class
|
48
|
+
end
|
49
|
+
|
44
50
|
private
|
45
51
|
|
46
52
|
attr_reader :unparsed_type
|
@@ -96,8 +102,8 @@ module GraphqlRails
|
|
96
102
|
end
|
97
103
|
|
98
104
|
def dynamicly_defined_type
|
99
|
-
type_class =
|
100
|
-
return unless type_class
|
105
|
+
type_class = graphql_model
|
106
|
+
return unless type_class
|
101
107
|
|
102
108
|
type_class.graphql.graphql_type
|
103
109
|
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.4.
|
4
|
+
version: 0.4.3
|
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-03-
|
11
|
+
date: 2019-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|