{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/graphql/issues/91","repository_url":"https://api.github.com/repos/facebook/graphql","labels_url":"https://api.github.com/repos/facebook/graphql/issues/91/labels{/name}","comments_url":"https://api.github.com/repos/facebook/graphql/issues/91/comments","events_url":"https://api.github.com/repos/facebook/graphql/issues/91/events","html_url":"https://github.com/facebook/graphql/issues/91","id":105766903,"number":91,"title":"Recursively nested objects","user":{"login":"petrbela","id":668124,"avatar_url":"https://avatars.githubusercontent.com/u/668124?v=3","gravatar_id":"","url":"https://api.github.com/users/petrbela","html_url":"https://github.com/petrbela","followers_url":"https://api.github.com/users/petrbela/followers","following_url":"https://api.github.com/users/petrbela/following{/other_user}","gists_url":"https://api.github.com/users/petrbela/gists{/gist_id}","starred_url":"https://api.github.com/users/petrbela/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/petrbela/subscriptions","organizations_url":"https://api.github.com/users/petrbela/orgs","repos_url":"https://api.github.com/users/petrbela/repos","events_url":"https://api.github.com/users/petrbela/events{/privacy}","received_events_url":"https://api.github.com/users/petrbela/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":11,"created_at":"2015-09-10T09:19:37Z","updated_at":"2016-04-07T07:47:08Z","closed_at":"2016-04-07T07:47:08Z","body":"Suppose we have a forum where users can reply to comments recursively:\r\n\r\n```graphql\r\ntype RootQuery {\r\n  message(id: String): Message\r\n  messages: [Message]\r\n}\r\n\r\ntype Message {\r\n  id: String!\r\n  content: String\r\n  comments: [Message]\r\n}\r\n```\r\n\r\nHow could the client query for the nested comments?\r\n\r\nThis only goes three levels deep:\r\n\r\n```graphql\r\n{\r\n  messages {\r\n    comments {\r\n      id\r\n      content\r\n      comments {\r\n        id\r\n        content\r\n        comments {\r\n          id\r\n          content       \r\n        }\r\n      }\r\n    }   \r\n  }\r\n}\r\n```\r\n\r\nWould a consecutive query starting at the last comment be the right solution?\r\n\r\n```graphql\r\n{\r\n  message as comment($commentId) {\r\n    comments {\r\n      id\r\n      content\r\n      comments {\r\n        ...\r\n      }\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n[Original SO post](https://stackoverflow.com/questions/32442814/structuring-graphql-types/32497480#32497480)"},"comment":{"url":"https://api.github.com/repos/facebook/graphql/issues/comments/206743676","html_url":"https://github.com/facebook/graphql/issues/91#issuecomment-206743676","issue_url":"https://api.github.com/repos/facebook/graphql/issues/91","id":206743676,"user":{"login":"leebyron","id":50130,"avatar_url":"https://avatars.githubusercontent.com/u/50130?v=3","gravatar_id":"","url":"https://api.github.com/users/leebyron","html_url":"https://github.com/leebyron","followers_url":"https://api.github.com/users/leebyron/followers","following_url":"https://api.github.com/users/leebyron/following{/other_user}","gists_url":"https://api.github.com/users/leebyron/gists{/gist_id}","starred_url":"https://api.github.com/users/leebyron/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leebyron/subscriptions","organizations_url":"https://api.github.com/users/leebyron/orgs","repos_url":"https://api.github.com/users/leebyron/repos","events_url":"https://api.github.com/users/leebyron/events{/privacy}","received_events_url":"https://api.github.com/users/leebyron/received_events","type":"User","site_admin":false},"created_at":"2016-04-07T07:47:08Z","updated_at":"2016-04-07T07:47:08Z","body":"Closing this issue since I believe it is answered. We explicitly do not allow fragment recursion or the querying of recursive structured since it can result in un-bound results.\r\n\r\nTypically you also never really want to require something of infinite depth anyhow, so it's good to put a bound on these things.\r\n\r\nA pattern I often see using fragments:\r\n\r\n```\r\n{\r\n  messages {\r\n    ...CommentsRecursive\r\n  }\r\n}\r\n\r\nfragment CommentsRecursive on Message {\r\n  comments {\r\n    ...CommentFields\r\n    comments {\r\n      ...CommentFields\r\n      comments {\r\n        ...CommentFields\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nfragment CommentFields on Comment {\r\n  id\r\n  content\r\n}\r\n```\r\n\r\nthis lets you define the fields you want at each depth level in one place, and then also explicitly state the \"recursive\" structure you want - in the above example it's 3 levels deep, but you can see how you could easily add more."}}