{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/graphql/issues/174","repository_url":"https://api.github.com/repos/facebook/graphql","labels_url":"https://api.github.com/repos/facebook/graphql/issues/174/labels{/name}","comments_url":"https://api.github.com/repos/facebook/graphql/issues/174/comments","events_url":"https://api.github.com/repos/facebook/graphql/issues/174/events","html_url":"https://github.com/facebook/graphql/issues/174","id":153895399,"number":174,"title":"Proposal: Flat array syntax","user":{"login":"mnpenner","id":1112998,"avatar_url":"https://avatars.githubusercontent.com/u/1112998?v=3","gravatar_id":"","url":"https://api.github.com/users/mnpenner","html_url":"https://github.com/mnpenner","followers_url":"https://api.github.com/users/mnpenner/followers","following_url":"https://api.github.com/users/mnpenner/following{/other_user}","gists_url":"https://api.github.com/users/mnpenner/gists{/gist_id}","starred_url":"https://api.github.com/users/mnpenner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mnpenner/subscriptions","organizations_url":"https://api.github.com/users/mnpenner/orgs","repos_url":"https://api.github.com/users/mnpenner/repos","events_url":"https://api.github.com/users/mnpenner/events{/privacy}","received_events_url":"https://api.github.com/users/mnpenner/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2016-05-09T23:53:04Z","updated_at":"2016-06-07T01:38:12Z","closed_at":null,"body":"Often times we want to fetch just a single field from a nested relation. e.g.\r\n\r\n```\r\n{\r\n  clients(limit: 5) {\r\n    id\r\n    programs {\r\n      shortName\r\n    }\r\n  }\r\n}\r\n```\r\n\r\nIt would be nice if there was a syntax to allow getting back a flat array of program shortNames instead of an array of objects. e.g.\r\n\r\n```\r\n{\r\n  clients(limit: 5) {\r\n    id\r\n    programs: programs.shortName\r\n  }\r\n}\r\n```\r\n\r\nThis would return something like:\r\n\r\n```\r\n{\r\n  \"data\": {\r\n    \"clients\": [\r\n      {\r\n        \"id\": 2,\r\n        \"programs\": [\"ABC\",\"DEF\"]\r\n      },\r\n      {\r\n        \"id\": 3,\r\n        \"programs\": [\"ABC\", \"XYZ\"]\r\n        ]\r\n      }\r\n    ]\r\n  }\r\n}\r\n```\r\n\r\nGiving it an alias could either be mandatory, or it could default to using the outer field name (default to \"programs\", \"shortName\" would be discarded).\r\n\r\nA library like GraphQL-JS could handle the normalization of array-of-objects to flat-array-of-strings automatically, so there wouldn't be any additional work for someone implementing a schema.\r\n"},"comment":{"url":"https://api.github.com/repos/facebook/graphql/issues/comments/224138272","html_url":"https://github.com/facebook/graphql/issues/174#issuecomment-224138272","issue_url":"https://api.github.com/repos/facebook/graphql/issues/174","id":224138272,"user":{"login":"mnpenner","id":1112998,"avatar_url":"https://avatars.githubusercontent.com/u/1112998?v=3","gravatar_id":"","url":"https://api.github.com/users/mnpenner","html_url":"https://github.com/mnpenner","followers_url":"https://api.github.com/users/mnpenner/followers","following_url":"https://api.github.com/users/mnpenner/following{/other_user}","gists_url":"https://api.github.com/users/mnpenner/gists{/gist_id}","starred_url":"https://api.github.com/users/mnpenner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mnpenner/subscriptions","organizations_url":"https://api.github.com/users/mnpenner/orgs","repos_url":"https://api.github.com/users/mnpenner/repos","events_url":"https://api.github.com/users/mnpenner/events{/privacy}","received_events_url":"https://api.github.com/users/mnpenner/received_events","type":"User","site_admin":false},"created_at":"2016-06-07T01:38:12Z","updated_at":"2016-06-07T01:38:12Z","body":"@r4j4h Those examples are weird. It's creating objects with two properties, `key` and `values`. If anything, I'd want the key to be the *actual* key for the inner object. I'm guessing that's the format needed for the D3 charts? Doesn't seem too useful for general-purpose.\r\n\r\nReformatting on the client isn't terrible difficult, I was just hoping to remove some of the boilerplate from the client and make it a little easier for novices. One of the nice things about GraphQL is that it's easy to read and write, which means you can give it to non-techies and they can pull our some basic data in a without having to hassle you. Having excessive nesting in the output makes it harder to read."}}
{"actor":{"display_login":"mnpenner"}}