【发布时间】:2020-05-25 20:37:38
【问题描述】:
通常,在 GraphQL/Rails 中,您有一个类似于以下内容的 query_type.rb 文件:
module Types
class QueryType < Types::BaseObject
# Add root-level fields here.
# They will be entry points for queries on your schema.
field :test_field, String, null: false do
description 'Test field'
end
def test_field
'My test field!'
end
end
end
我所有的查询都在这个文件中完全实现了。有没有办法做类似mutation_type.rb 的事情并将查询实现范围扩展到其他文件?也许是这样的?:
query_type.rb:
module Types
class QueryType < Types::BaseObject
# Add root-level fields here.
# They will be entry points for queries on your schema.
field :test_field, String, null: false, query: Types::TestFieldType
end
end
test_field_type.rb:
module Types
class TestFieldType < Types::BaseObject
description 'Test Field'
def test_field
'My Test field!'
end
end
end
【问题讨论】:
-
你的意思是喜欢
field :test_field, Types::TestFieldType, null: false吗? -
我正在寻找一种方法来将我的查询从
query_type.rb提取到他们自己的文件中,就像你对突变所做的那样。在我看来,它使阅读代码更易于管理。
标签: ruby-on-rails ruby graphql graphql-ruby