rails-graphql 1.0.0.rc2 → 1.0.1

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: 3c29232c14870c44aeab62fba29beda42f8f99a8047bf83f717149e6fc2e5d7c
4
- data.tar.gz: 196468f3151958620774998650fe7a5f70e0b3204fdb5a028b31c634d21a9cb0
3
+ metadata.gz: d610a5ff87d748320cba5705f819c0832146a28be41ffdfe9ebd8d13772b7326
4
+ data.tar.gz: 390b994294e6f7ee5f51feadb8dc0102d4d79816d90615b25ca46994bb62e66a
5
5
  SHA512:
6
- metadata.gz: a17d0f98a0473afd6d221d98b967068ae9d97da363e44e92817729e23a204510768c72bed50a858816e9d7eeda8b0fcdefe83c56d9782e8abe06d71bea6e0f75
7
- data.tar.gz: c4258dfce30c7aedba8a3f2c1a9a6c20b0eca30ae520888efac8dfeb3f5267654d74e2992b9794bdb892a2f84d8f1be68d6d71e637ebaa48ee780d3b019ccf25
6
+ metadata.gz: 738aab60ab153f08f180909a89577cc802c9171b1199763a540094aaf16ebe3169a0a75a49a5de0124383b555ab40d39448201031e71d0caa8ea52b1bc132229
7
+ data.tar.gz: 4f41e879a2501cbca1c1826c0c5e620e3506f156a4bcc4529d342dc9383109efdd33a25201b4959382967a73b6af29db29328db2ea30c31aa0d411c2c446c5c5
data/Rakefile CHANGED
@@ -2,7 +2,7 @@
2
2
  # Rake tasks for development purposes
3
3
 
4
4
  begin
5
- require 'bundler/setup'
5
+ require 'bundler/setup' unless ENV.key?('CI_COMPILE')
6
6
  rescue LoadError
7
7
  puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
8
8
  end
@@ -37,6 +37,11 @@ Rails::GraphQL.configure do |config|
37
37
  # different suffix, change this value to it.
38
38
  # config.auto_suffix_input_objects = 'Input'
39
39
 
40
+ # Set if the server should allow strings be used as input for ENUM inputs.
41
+ # It means that operations will support quotes for ENUM values embedded in
42
+ # the documents (heredoc won't be accepted).
43
+ # config.allow_string_as_enum_input = false
44
+
40
45
  # Introspection is enabled by default. It is recommended to only use
41
46
  # introspection during development and tests, never in production.
42
47
  # This can also be set per schema level.
data/lib/gql_parser.so CHANGED
Binary file
@@ -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.
@@ -19,6 +19,8 @@ module Rails
19
19
  # Helper method to initialize an operation given the node
20
20
  def build(request, node)
21
21
  request.build(const_get(node.type.to_s.classify, false), request, node)
22
+ rescue ::NameError
23
+ raise NameError, +%[Unable to initialize "#{node.type}" operation.]
22
24
  end
23
25
 
24
26
  # Rewrite the kind to always return +:operation+
@@ -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
- new(value.is_a?(::GQLParser::Token) ? value.to_s : value) if valid_input?(value)
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
@@ -14,8 +14,8 @@ module Rails
14
14
  module VERSION
15
15
  MAJOR = 1
16
16
  MINOR = 0
17
- TINY = 0
18
- PRE = 'rc2'
17
+ TINY = 1
18
+ PRE = nil
19
19
 
20
20
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
21
21
  end
@@ -0,0 +1,21 @@
1
+ require 'config'
2
+
3
+ class GraphQL_Request_Component_OperationTest < GraphQL::TestCase
4
+ def test_build
5
+ request = Object.new
6
+ request.define_singleton_method(:build) { |klass, *| klass }
7
+
8
+ assert_equal(klass::Query, klass.build(request, new_token('', :query)))
9
+ assert_equal(klass::Mutation, klass.build(request, new_token('', :mutation)))
10
+ assert_equal(klass::Subscription, klass.build(request, new_token('', :subscription)))
11
+
12
+ assert_raises(Rails::GraphQL::NameError) { klass.build(request, new_token('', '')) }
13
+ assert_raises(Rails::GraphQL::NameError) { klass.build(request, new_token('', :field)) }
14
+ end
15
+
16
+ private
17
+
18
+ def klass
19
+ Rails::GraphQL::Request::Component::Operation
20
+ end
21
+ end
@@ -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
@@ -10,6 +10,7 @@ class MySQLRecord < ActiveRecord::Base
10
10
  database: ENV.fetch('GQL_MYSQL_DATABASE', 'starwars'),
11
11
  username: ENV.fetch('GQL_MYSQL_USERNAME', 'root'),
12
12
  password: ENV['GQL_MYSQL_PASSWORD'],
13
+ port: ENV['GQL_MYSQL_PORT'],
13
14
  )
14
15
  end
15
16
 
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.rc2
4
+ version: 1.0.1
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-02-28 00:00:00.000000000 Z
11
+ date: 2024-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -349,6 +349,7 @@ files:
349
349
  - test/assets/sqlite.gql
350
350
  - test/assets/translate.gql
351
351
  - test/config.rb
352
+ - test/graphql/request/component/operation_test.rb
352
353
  - test/graphql/request/context_test.rb
353
354
  - test/graphql/schema_test.rb
354
355
  - test/graphql/source_test.rb
@@ -414,9 +415,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
414
415
  version: 2.6.3
415
416
  required_rubygems_version: !ruby/object:Gem::Requirement
416
417
  requirements:
417
- - - ">"
418
+ - - ">="
418
419
  - !ruby/object:Gem::Version
419
- version: 1.3.1
420
+ version: '0'
420
421
  requirements: []
421
422
  rubygems_version: 3.3.26
422
423
  signing_key:
@@ -433,6 +434,7 @@ test_files:
433
434
  - test/assets/sqlite.gql
434
435
  - test/assets/translate.gql
435
436
  - test/config.rb
437
+ - test/graphql/request/component/operation_test.rb
436
438
  - test/graphql/request/context_test.rb
437
439
  - test/graphql/schema_test.rb
438
440
  - test/graphql/source_test.rb