{"action":"created","issue":{"url":"https://api.github.com/repos/graphql/graphql-js/issues/19","labels_url":"https://api.github.com/repos/graphql/graphql-js/issues/19/labels{/name}","comments_url":"https://api.github.com/repos/graphql/graphql-js/issues/19/comments","events_url":"https://api.github.com/repos/graphql/graphql-js/issues/19/events","html_url":"https://github.com/graphql/graphql-js/issues/19","id":92925324,"number":19,"title":"No way to get requested fields of the object inside `resolve`","user":{"login":"xslim","id":47062,"avatar_url":"https://avatars.githubusercontent.com/u/47062?v=3","gravatar_id":"","url":"https://api.github.com/users/xslim","html_url":"https://github.com/xslim","followers_url":"https://api.github.com/users/xslim/followers","following_url":"https://api.github.com/users/xslim/following{/other_user}","gists_url":"https://api.github.com/users/xslim/gists{/gist_id}","starred_url":"https://api.github.com/users/xslim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xslim/subscriptions","organizations_url":"https://api.github.com/users/xslim/orgs","repos_url":"https://api.github.com/users/xslim/repos","events_url":"https://api.github.com/users/xslim/events{/privacy}","received_events_url":"https://api.github.com/users/xslim/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/graphql/graphql-js/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":13,"created_at":"2015-07-03T19:28:20Z","updated_at":"2015-07-16T18:42:33Z","closed_at":null,"body":"Let's say I have a Database with User entity with a lot of fields:\r\n\r\n``` js\r\nvar Sequelize = require('sequelize');\r\nvar sequelize = new Sequelize('sqlite://database.db');\r\n\r\nvar User = sequelize.define('User', {\r\n  name: Sequelize.STRING,\r\n  email: Sequelize.STRING,\r\n  otherField: Sequelize.STRING,\r\n});\r\n```\r\n\r\nAnd I have a GraphQL:\r\n\r\n``` js\r\nvar queryType = new GraphQLObjectType({\r\n  name: 'Query',\r\n  fields: () => ({\r\n    user: {\r\n      type: userType,\r\n      args: { id: { type: GraphQLID } },\r\n      resolve: (_, {id}) => User.findById(id)\r\n    },\r\n    users: {\r\n      type: new GraphQLList(userType),\r\n      resolve: (source, args) => {\r\n        User.all(); // How to get the requested fields?\r\n        //User.all({ attributes: args._requestedFields });\r\n      }\r\n    },\r\n  })\r\n});\r\n```\r\n\r\nAnd I do a GraphQL query to get `name` of  all `users`\r\n\r\n```\r\n curl -s -X POST http://localhost:8080/api/graph -d '{ users { name } }' | jq '.'\r\n```\r\n\r\nI don't want to fetch all the fields from the database. I want to know what fields to fetch...\r\n\r\nIs there any way to get a list of fields that were requested in `resolve` method?"},"comment":{"url":"https://api.github.com/repos/graphql/graphql-js/issues/comments/122046263","html_url":"https://github.com/graphql/graphql-js/issues/19#issuecomment-122046263","issue_url":"https://api.github.com/repos/graphql/graphql-js/issues/19","id":122046263,"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":"2015-07-16T18:42:33Z","updated_at":"2015-07-16T18:42:33Z","body":"@mnylen that's a great and terse example! @gyzerok the idea is that function is going to be very different depending on what backend storage system you're using :)"}}