Skip to content

Seems incompatible with graphql-ruby's new runtime #3

@stevenpetryk

Description

@stevenpetryk

Edit: see my next comment for the fix and subsequent problem/observation.


Howdy! Thanks a bunch for forking this into the future. I expect once I get it working it'll be a huge lifesaver.

I'm running into a wee problem where it's as if the preloading is not doing anything. I have a pretty minimal reproduction as I'm just playing around with a new Rails app.

  • rails 6.0.2.2
  • graphql 1.10.5
  • graphql-batch 0.4.2
  • graphql-preload Envek/graphql-preload@5040f7851bca3ce1044f8171b8301a2784720505

Schema

class ExampleSchema < GraphQL::Schema
  use GraphQL::Batch
  enable_preloading

  mutation(Types::MutationType)
  query(Types::QueryType)

  # Opt in to the new runtime (default in future graphql-ruby versions)
  use GraphQL::Execution::Interpreter
  use GraphQL::Analysis::AST

  # Add built-in connections for pagination
  use GraphQL::Pagination::Connections
end

Models

class Author < ApplicationRecord
  has_many :posts
end

class Post < ApplicationRecord
  belongs_to :author
end

Types

module Types
  class AuthorType < Types::BaseObject
    field :name, String, null: false
    field :posts, [PostType], null: false, preload: :posts
    #                                      ^^^^^^^^^^^^^^^
  end

  class PostType < Types::BaseObject
    field :title, String, null: true
    field :author, AuthorType, null: true
    field :author_id, ID, null: false
    field :body, String, null: true
    field :title, String, null: true
  end
end

Query type

module Types
  class QueryType < Types::BaseObject
    field :authors, [AuthorType], null: true
    def authors
      Author.all
    end
  end
end

However, making the following query succeeds, but still leads to a bunch of N+1s:

{
  authors {
    name
    
    posts {
      title
    }
  }
}

image

Is there anything I might be missing? I tried to bring it perfectly in line with the test cases in this repo, and went over the README a few times.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions