Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/53.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何让graphql ruby在访问子字段时使用连接?_Ruby On Rails_Graphql_Graphql Ruby - Fatal编程技术网

Ruby on rails 如何让graphql ruby在访问子字段时使用连接?

Ruby on rails 如何让graphql ruby在访问子字段时使用连接?,ruby-on-rails,graphql,graphql-ruby,Ruby On Rails,Graphql,Graphql Ruby,我有一个这样的模型 query foos( $offset: Int $sort_by: String $should_paginate: Boolean ) { foos( offset: $offset sort_by: $sort_by should_paginate: $should_paginate ) { id name bars { class-Foo 有很多酒吧吗 结束 像这样的问题 query foos(

我有一个这样的模型

query foos(
  $offset: Int
  $sort_by: String
  $should_paginate: Boolean
) {
  foos(
    offset: $offset
    sort_by: $sort_by
    should_paginate: $should_paginate
  ) {
    id
    name
    bars {
class-Foo
有很多酒吧吗
结束
像这样的问题

query foos(
  $offset: Int
  $sort_by: String
  $should_paginate: Boolean
) {
  foos(
    offset: $offset
    sort_by: $sort_by
    should_paginate: $should_paginate
  ) {
    id
    name
    bars {
当我获取此查询时,我会为集合中的每个条获取一个
select*from“foos”

我怎样才能让这一切变得更加智能,并且更少地执行SQL查询呢


它使用允许您根据需要立即延迟加载关联。

它解决了n+1问题,但没有解决基于关联加载的其他问题,即您将无法按子属性排序/筛选。我发现最好的方法是使用数据库视图,并在GraphQLRuby中为此创建另一个模型/类型view@hedgehogrider试着这样做: