rails-graphql 1.0.0.rc2 → 1.0.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/Rakefile +1 -1
- data/lib/gql_parser.so +0 -0
- data/lib/rails/graphql/config.rb +5 -0
- data/lib/rails/graphql/type/enum.rb +16 -2
- data/lib/rails/graphql/version.rb +1 -1
- data/test/graphql/type/enum_test.rb +15 -0
- data/test/integration/schemas/mysql.rb +1 -0
- data/test/test_ext.rb +6 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38fafc81ae4e9f8c11c4d1495b8290656dcf388ac0b6d5536829e0f77ee09bb2
|
4
|
+
data.tar.gz: 8a8298e375df5ac6905b24deeacf29ca2fd7b4dc39dfb43601ba2331828ac939
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa92f53a2111c001863967bca893a25bab09f9a9c163af945631a15054c865db2e9102467e8c85ac1c3cbc0591c377a97f98c2439bdc94c72694d72cbef99e05
|
7
|
+
data.tar.gz: d994c9ff91179fbd72ecb3afde6f3bb005805697ebe994cfcc88b2bc9720e30f16ac76f6dab81b65760ad3e61af5db427d9a5e9118f6222b756df00c35b499d7
|
data/Rakefile
CHANGED
data/lib/gql_parser.so
CHANGED
Binary file
|
data/lib/rails/graphql/config.rb
CHANGED
@@ -61,6 +61,11 @@ module Rails
|
|
61
61
|
# different suffix, change this value to it.
|
62
62
|
config.auto_suffix_input_objects = 'Input'
|
63
63
|
|
64
|
+
# Set if the server should allow strings be used as input for ENUM inputs.
|
65
|
+
# It means that operations will support quotes for ENUM values embedded in
|
66
|
+
# the documents (heredoc won't be accepted).
|
67
|
+
config.allow_string_as_enum_input = false
|
68
|
+
|
64
69
|
# Introspection is enabled by default. It is recommended to only use
|
65
70
|
# introspection during development and tests, never in production.
|
66
71
|
# This can also be set per schema level.
|
@@ -39,7 +39,9 @@ module Rails
|
|
39
39
|
# Check if a given value is a valid non-deserialized input
|
40
40
|
def valid_input?(value)
|
41
41
|
(valid_token?(value, :enum) && all_values.include?(value.to_s)) ||
|
42
|
-
(value.is_a?(String) && all_values.include?(value))
|
42
|
+
(value.is_a?(String) && all_values.include?(value)) ||
|
43
|
+
(allow_string_input? && valid_token?(value, :string) &&
|
44
|
+
all_values.include?(value.to_s[1..-2]))
|
43
45
|
end
|
44
46
|
|
45
47
|
# Check if a given value is a valid non-serialized output
|
@@ -62,7 +64,13 @@ module Rails
|
|
62
64
|
|
63
65
|
# Turn a user input of this given type into an ruby object
|
64
66
|
def deserialize(value)
|
65
|
-
|
67
|
+
if valid_token?(value, :enum)
|
68
|
+
new(value.to_s)
|
69
|
+
elsif allow_string_input? && valid_token?(value, :string)
|
70
|
+
new(value[1..-2])
|
71
|
+
elsif valid_input?(value)
|
72
|
+
new(value)
|
73
|
+
end
|
66
74
|
end
|
67
75
|
|
68
76
|
# Use the instance as decorator
|
@@ -142,6 +150,12 @@ module Rails
|
|
142
150
|
#{inspect_directives}
|
143
151
|
INFO
|
144
152
|
end
|
153
|
+
|
154
|
+
private
|
155
|
+
|
156
|
+
def allow_string_input?
|
157
|
+
GraphQL.config.allow_string_as_enum_input
|
158
|
+
end
|
145
159
|
end
|
146
160
|
|
147
161
|
attr_reader :value
|
@@ -17,6 +17,13 @@ class GraphQL_Type_EnumTest < GraphQL::TestCase
|
|
17
17
|
refute(DESCRIBED_CLASS.valid_input?(1))
|
18
18
|
refute(DESCRIBED_CLASS.valid_input?(nil))
|
19
19
|
refute(DESCRIBED_CLASS.valid_input?('abc'))
|
20
|
+
|
21
|
+
str_token = new_token('"A"', :string)
|
22
|
+
refute(DESCRIBED_CLASS.valid_input?(str_token))
|
23
|
+
|
24
|
+
stubbed_config(:allow_string_as_enum_input, true) do
|
25
|
+
assert(DESCRIBED_CLASS.valid_input?(str_token))
|
26
|
+
end
|
20
27
|
end
|
21
28
|
|
22
29
|
def test_valid_output_ask
|
@@ -58,6 +65,14 @@ class GraphQL_Type_EnumTest < GraphQL::TestCase
|
|
58
65
|
test_value = DESCRIBED_CLASS.deserialize('A')
|
59
66
|
assert_instance_of(DESCRIBED_CLASS, test_value)
|
60
67
|
assert_equal('A', test_value.value)
|
68
|
+
|
69
|
+
str_token = new_token('"A"', :string)
|
70
|
+
assert_nil(DESCRIBED_CLASS.deserialize(str_token))
|
71
|
+
stubbed_config(:allow_string_as_enum_input, true) do
|
72
|
+
test_value = DESCRIBED_CLASS.deserialize(str_token)
|
73
|
+
assert_instance_of(DESCRIBED_CLASS, test_value)
|
74
|
+
assert_equal('A', test_value.value)
|
75
|
+
end
|
61
76
|
end
|
62
77
|
|
63
78
|
def test_decorate
|
data/test/test_ext.rb
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
# Core ext methods
|
2
2
|
|
3
3
|
class Object < BasicObject
|
4
|
+
def new_token(value, type)
|
5
|
+
GQLParser::Token.new(value).tap do |token|
|
6
|
+
token.instance_variable_set(:@type, type)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
4
10
|
def stub_ivar(name, value = nil)
|
5
11
|
instance_variable_set(name, value)
|
6
12
|
yield
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-graphql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carlos Silva
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -414,9 +414,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
414
414
|
version: 2.6.3
|
415
415
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
416
416
|
requirements:
|
417
|
-
- - "
|
417
|
+
- - ">="
|
418
418
|
- !ruby/object:Gem::Version
|
419
|
-
version:
|
419
|
+
version: '0'
|
420
420
|
requirements: []
|
421
421
|
rubygems_version: 3.3.26
|
422
422
|
signing_key:
|