2017-11-11 14 views
2

graphQL-ruby를 사용하면서 기존 ActiveRecod .includes를 연관된 모델로 변환하는 방법에 대한 예제를 찾고 있었지만 찾을 수 없었습니다. 사용 사례로 , 이제 우리는 다음과 같은 모델을 가정 해 봅시다 :은 graphql-ruby로/eager load 관련 모델을 포함합니다.

User 
has_many :books 

Book 
belongs_to :user 
has_many :chapters 

Chapter 
belongs_to :book 
has_many :pages 

Page 
belongs_to :chapter 

우리가 구현할 수있는 방법은 다음과

User.includes(books: {chapters: :pages}) 

실제 중첩 GraphQL 쿼리는 비교적 간단하다; 그러나, 그것은 N + 1에서 실행중인 것 같습니다.

도움을 주시면 감사하겠습니다.

답변

0

우리는 graphql-query를 걷는 것을 포함하는 graphql-ruby를위한 작은 보석을 작성했습니다. 귀하의 예를 들어

https://github.com/thesquarefoot/graphql_includable

당신은 사용자 필드의 해결에 User.includes_from_graphql(ctx)을 부를 것이다.