我正在尝试创建一个查询,以从“报价”表返回经过过滤的报价清单。
该代码位于引擎名称“ cpq”内
types / quotation_type.rb
module Cpq
module Types
class QuotationType < ::Cpq::Types::BaseObject
field :id, ID, null: false
field :inc_id, Integer, null: false
field :name, String, null: false
field :description, String, null: true
field :buyer_id, ID, null: true
field :seller_address, String, null: true
field :buyer_address, String, null: true
field :quotation_no, String, null: false
field :updated_at, ::Types::DateTimeType, null: false
end
class QuotationReturnType < ::Cpq::Types::BaseObject
field :success, Boolean, null: false
field :quotation_data, [::Cpq::Types::QuotationType], null: true
field :page, Integer, null: true
field :total, Integer, null: true
field :total_count, Integer, null: true
end
end
end
types / query_type.rb
Cpq::Types::QueryType = GraphQL::ObjectType.define do
name "Query"
field :quotations do
type ::Cpq::Types::QuotationReturnType
argument :id, types.ID
argument :name, types.String
argument :buyer_ids, types[types.ID]
argument :statuses, types[types.String]
argument :page, types.String
argument :page_limit, types.String
argument :sort_by, types.String
...
...
resolve -> (obj, args, ctx) {
quotation_ids = []
quotation_ids << args[:id] if args[:id].present?
name = args[:name]
...
...
return {
success: true,
page: page,
total: total,
total_count: total_count,
data: quotation.as_json(::Cpq::Quotation.as_json_query)
}
}
end
end
但是,在查询“报价”时,出现错误
Traceback (most recent call last):
10: from -e:1:in `<main>'
9: from /Users/sourabhmodi/.rvm/rubies/ruby-2.5.0/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
8: from /Users/sourabhmodi/.rvm/rubies/ruby-2.5.0/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
7: from /Users/sourabhmodi/Documents/workspace/rails/Cogoport-api/bin/rails:9:in `<top (required)>'
6: from /Users/sourabhmodi/.rvm/gems/ruby-2.5.0/gems/railties-5.0.7/lib/rails/commands.rb:18:in `<top (required)>'
5: from /Users/sourabhmodi/.rvm/gems/ruby-2.5.0/gems/railties-5.0.7/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
4: from /Users/sourabhmodi/.rvm/gems/ruby-2.5.0/gems/railties-5.0.7/lib/rails/commands/commands_tasks.rb:78:in `console'
3: from /Users/sourabhmodi/.rvm/gems/ruby-2.5.0/gems/railties-5.0.7/lib/rails/commands/console_helper.rb:9:in `start'
2: from /Users/sourabhmodi/.rvm/gems/ruby-2.5.0/gems/railties-5.0.7/lib/rails/commands/console.rb:65:in `start'
1: from (irb):14
NameError (uninitialized constant Cpq::Types::QuotationReturnType)
在Rails Console上
2.5.0 :023 > ::Cpq::Types::QuotationReturnType
Traceback (most recent call last):
10: from -e:1:in `<main>'
9: from /Users/sourabhmodi/.rvm/rubies/ruby-2.5.0/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
8: from /Users/sourabhmodi/.rvm/rubies/ruby-2.5.0/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
7: from /Users/sourabhmodi/Documents/workspace/rails/Cogoport-api/bin/rails:9:in `<top (required)>'
6: from /Users/sourabhmodi/.rvm/gems/ruby-2.5.0/gems/railties-5.0.7/lib/rails/commands.rb:18:in `<top (required)>'
5: from /Users/sourabhmodi/.rvm/gems/ruby-2.5.0/gems/railties-5.0.7/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
4: from /Users/sourabhmodi/.rvm/gems/ruby-2.5.0/gems/railties-5.0.7/lib/rails/commands/commands_tasks.rb:78:in `console'
3: from /Users/sourabhmodi/.rvm/gems/ruby-2.5.0/gems/railties-5.0.7/lib/rails/commands/console_helper.rb:9:in `start'
2: from /Users/sourabhmodi/.rvm/gems/ruby-2.5.0/gems/railties-5.0.7/lib/rails/commands/console.rb:65:in `start'
1: from (irb):23
NameError (uninitialized constant Cpq::Types::QuotationReturnType)
2.5.0 :024 > ::Cpq::Types::QuotationType
=> Cpq::Types::QuotationType
2.5.0 :025 > ::Cpq::Types::QuotationReturnType
=> Cpq::Types::QuotationReturnType
当我在控制台上尝试时,我意识到,一旦我以前访问过Cpq :: Types :: QuotationType类型,便可以访问QuotationReturnType类。但是,如果我只是尝试访问Cpq :: Types :: QuotationReturnType,则会给我一个错误。可能无法加载它或其他东西。 困惑。请帮忙。 附言我是graphql的新手,因此,如果提到的话,请忽略任何幼稚/多余的代码。