{"action":"created","issue":{"url":"https://api.github.com/repos/sangria-graphql/sangria/issues/63","labels_url":"https://api.github.com/repos/sangria-graphql/sangria/issues/63/labels{/name}","comments_url":"https://api.github.com/repos/sangria-graphql/sangria/issues/63/comments","events_url":"https://api.github.com/repos/sangria-graphql/sangria/issues/63/events","html_url":"https://github.com/sangria-graphql/sangria/issues/63","id":104494595,"number":63,"title":"Deferred, how to avoid N+1 queries","user":{"login":"luisobo","id":825073,"avatar_url":"https://avatars.githubusercontent.com/u/825073?v=3","gravatar_id":"","url":"https://api.github.com/users/luisobo","html_url":"https://github.com/luisobo","followers_url":"https://api.github.com/users/luisobo/followers","following_url":"https://api.github.com/users/luisobo/following{/other_user}","gists_url":"https://api.github.com/users/luisobo/gists{/gist_id}","starred_url":"https://api.github.com/users/luisobo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/luisobo/subscriptions","organizations_url":"https://api.github.com/users/luisobo/orgs","repos_url":"https://api.github.com/users/luisobo/repos","events_url":"https://api.github.com/users/luisobo/events{/privacy}","received_events_url":"https://api.github.com/users/luisobo/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-09-02T14:33:33Z","updated_at":"2015-09-02T18:59:49Z","closed_at":null,"body":"Hi,\r\n\r\nLoving sangria, it made it all the way to production so thanks for that!\r\n\r\nI'm tryind to avoid a N+1 queries. My schema looks something like this:\r\n\r\n```\r\ntype Query {\r\n  articles(first: Int, after: String): ArticleConnection!\r\n}\r\n\r\ntype Article {\r\n  id: ID!\r\n  comments(first: Int, after: String): CommentsConnection!\r\n}\r\n\r\ntype Comment {\r\n  content: String!\r\n}\r\n```\r\n\r\nThe problem happens when requesting multiple articles and their comments:\r\n\r\n```\r\nquery articlesWithComments {\r\n  articles {\r\n    edges {\r\n      node { \r\n        id\r\n        comments {\r\n          edges {\r\n             node {\r\n                 content\r\n              }\r\n            }\r\n         }\r\n       }\r\n     }\r\n   }\r\n}\r\n```\r\n\r\nThe execution goes like this:\r\n1. 1 api call to request the page of articles, it returns 10, for instance\r\n1.  10 api calls to retrieve the comments of each article\r\n\r\nIdeally, I'd have an endpoint that will return the comments of N articles so step number two can be collapsed into one api call and returns a map of articleId -> Page[Comment]\r\n\r\nI've been playing around with Defer and DeferredResolver but I can't get it to work with this case. The documentation covers the case you have a list of comment ids and you retrieve them all at once and not the other way around.\r\n\r\nAny suggestions on how to implement this?\r\n\r\nAgain, thank you so much for sangria and thank you for your time.\r\n"},"comment":{"url":"https://api.github.com/repos/sangria-graphql/sangria/issues/comments/137212842","html_url":"https://github.com/sangria-graphql/sangria/issues/63#issuecomment-137212842","issue_url":"https://api.github.com/repos/sangria-graphql/sangria/issues/63","id":137212842,"user":{"login":"luisobo","id":825073,"avatar_url":"https://avatars.githubusercontent.com/u/825073?v=3","gravatar_id":"","url":"https://api.github.com/users/luisobo","html_url":"https://github.com/luisobo","followers_url":"https://api.github.com/users/luisobo/followers","following_url":"https://api.github.com/users/luisobo/following{/other_user}","gists_url":"https://api.github.com/users/luisobo/gists{/gist_id}","starred_url":"https://api.github.com/users/luisobo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/luisobo/subscriptions","organizations_url":"https://api.github.com/users/luisobo/orgs","repos_url":"https://api.github.com/users/luisobo/repos","events_url":"https://api.github.com/users/luisobo/events{/privacy}","received_events_url":"https://api.github.com/users/luisobo/received_events","type":"User","site_admin":false},"created_at":"2015-09-02T18:59:49Z","updated_at":"2015-09-02T18:59:49Z","body":"You understood everything correctly and yes, it will be possible to retrieve the comments of multiple articles in one just as you described"}}