Skip to content

Commit

Permalink
Small fixes on template and operation initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
crashtech committed Jan 5, 2024
1 parent 79ec655 commit 791e1ac
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/generators/graphql/templates/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
# different suffix, change this value to it.
# config.auto_suffix_input_objects = 'Input'

# Set if the server should allow strings be used as input for ENUM inputs.
# It means that operations will support quotes for ENUM values embedded in
# the documents (heredoc won't be accepted).
# config.allow_string_as_enum_input = false

# Introspection is enabled by default. It is recommended to only use
# introspection during development and tests, never in production.
# This can also be set per schema level.
Expand Down
2 changes: 2 additions & 0 deletions lib/rails/graphql/request/component/operation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class << self
# Helper method to initialize an operation given the node
def build(request, node)
request.build(const_get(node.type.to_s.classify, false), request, node)
rescue ::NameError
raise NameError, +%[Unable to initialize "#{node.type}" operation.]
end

# Rewrite the kind to always return +:operation+
Expand Down
2 changes: 1 addition & 1 deletion lib/rails/graphql/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def self.version
module VERSION
MAJOR = 1
MINOR = 0
TINY = 0
TINY = 1
PRE = nil

STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
Expand Down
21 changes: 21 additions & 0 deletions test/graphql/request/component/operation_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'config'

class GraphQL_Request_Component_OperationTest < GraphQL::TestCase
def test_build
request = Object.new
request.define_singleton_method(:build) { |klass, *| klass }

assert_equal(klass::Query, klass.build(request, new_token('', :query)))
assert_equal(klass::Mutation, klass.build(request, new_token('', :mutation)))
assert_equal(klass::Subscription, klass.build(request, new_token('', :subscription)))

assert_raises(Rails::GraphQL::NameError) { klass.build(request, new_token('', '')) }
assert_raises(Rails::GraphQL::NameError) { klass.build(request, new_token('', :field)) }
end

private

def klass
Rails::GraphQL::Request::Component::Operation
end
end

0 comments on commit 791e1ac

Please sign in to comment.