{"action":"created","issue":{"url":"https://api.github.com/repos/graphql/graphql-js/issues/458","repository_url":"https://api.github.com/repos/graphql/graphql-js","labels_url":"https://api.github.com/repos/graphql/graphql-js/issues/458/labels{/name}","comments_url":"https://api.github.com/repos/graphql/graphql-js/issues/458/comments","events_url":"https://api.github.com/repos/graphql/graphql-js/issues/458/events","html_url":"https://github.com/graphql/graphql-js/issues/458","id":168501511,"number":458,"title":"Exposing a simple list of the selection set in the resolve function","user":{"login":"papigers","id":5209100,"avatar_url":"https://avatars.githubusercontent.com/u/5209100?v=3","gravatar_id":"","url":"https://api.github.com/users/papigers","html_url":"https://github.com/papigers","followers_url":"https://api.github.com/users/papigers/followers","following_url":"https://api.github.com/users/papigers/following{/other_user}","gists_url":"https://api.github.com/users/papigers/gists{/gist_id}","starred_url":"https://api.github.com/users/papigers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/papigers/subscriptions","organizations_url":"https://api.github.com/users/papigers/orgs","repos_url":"https://api.github.com/users/papigers/repos","events_url":"https://api.github.com/users/papigers/events{/privacy}","received_events_url":"https://api.github.com/users/papigers/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-07-31T04:52:00Z","updated_at":"2016-07-31T14:40:32Z","closed_at":null,"body":"Hey,\r\nOne of the steps that are required to support querying databases using GraphQL, is to expose the required selectionSet in the resolve functions. That way, users could use that to project only the required fields, thus optimizing the database's query performance and minimizing the network traffic between the GraphQL server and the DB server.\r\n\r\nFor example, for the following query:\r\n```\r\n{\r\n  user(id: 1) {\r\n    name,\r\n    email\r\n  }\r\n}\r\n```\r\n\r\nI would get this as an argument for the resolve function on the user field in the GraphQL Schema: `[ 'name', 'email' ]` (or something similar). This way I could project only those fields from the DB query.\r\n\r\nI realize I can access the \"root\" selectionSet on the fourth paremeter (`operation.selectionSet`) in the resolve function, but this can get a bit messy for complex query. I'm looking for a way to expose only the required selection: under the user's `resolve` I would get only the selected user fields, and under \"whatever\"'s `resolve` I would get only \"whatever\"'s selected fields and so on...\r\n\r\nI realize that supporting databases isn't your top priority right now, but I'm just looking for directions, maybe I'd could implement this on my own somehow."},"comment":{"url":"https://api.github.com/repos/graphql/graphql-js/issues/comments/236433557","html_url":"https://github.com/graphql/graphql-js/issues/458#issuecomment-236433557","issue_url":"https://api.github.com/repos/graphql/graphql-js/issues/458","id":236433557,"user":{"login":"robrichard","id":3814096,"avatar_url":"https://avatars.githubusercontent.com/u/3814096?v=3","gravatar_id":"","url":"https://api.github.com/users/robrichard","html_url":"https://github.com/robrichard","followers_url":"https://api.github.com/users/robrichard/followers","following_url":"https://api.github.com/users/robrichard/following{/other_user}","gists_url":"https://api.github.com/users/robrichard/gists{/gist_id}","starred_url":"https://api.github.com/users/robrichard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robrichard/subscriptions","organizations_url":"https://api.github.com/users/robrichard/orgs","repos_url":"https://api.github.com/users/robrichard/repos","events_url":"https://api.github.com/users/robrichard/events{/privacy}","received_events_url":"https://api.github.com/users/robrichard/received_events","type":"User","site_admin":false},"created_at":"2016-07-31T14:40:32Z","updated_at":"2016-07-31T14:40:32Z","body":"@papigers I created a package called [graphql-fields](https://www.npmjs.com/package/graphql-fields) that does something very similar to what you describe."}}
{"actor":{"display_login":"robrichard"}}