Skip to content

Commit 791e1ac

Browse files
committed
Small fixes on template and operation initialization
1 parent 79ec655 commit 791e1ac

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

lib/generators/graphql/templates/config.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
# different suffix, change this value to it.
3838
# config.auto_suffix_input_objects = 'Input'
3939

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+
4045
# Introspection is enabled by default. It is recommended to only use
4146
# introspection during development and tests, never in production.
4247
# This can also be set per schema level.

lib/rails/graphql/request/component/operation.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class << self
1919
# Helper method to initialize an operation given the node
2020
def build(request, node)
2121
request.build(const_get(node.type.to_s.classify, false), request, node)
22+
rescue ::NameError
23+
raise NameError, +%[Unable to initialize "#{node.type}" operation.]
2224
end
2325

2426
# Rewrite the kind to always return +:operation+

lib/rails/graphql/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def self.version
1414
module VERSION
1515
MAJOR = 1
1616
MINOR = 0
17-
TINY = 0
17+
TINY = 1
1818
PRE = nil
1919

2020
STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

0 commit comments

Comments
 (0)