{"action":"created","issue":{"url":"https://api.github.com/repos/stems/join-monster/issues/206","repository_url":"https://api.github.com/repos/stems/join-monster","labels_url":"https://api.github.com/repos/stems/join-monster/issues/206/labels{/name}","comments_url":"https://api.github.com/repos/stems/join-monster/issues/206/comments","events_url":"https://api.github.com/repos/stems/join-monster/issues/206/events","html_url":"https://github.com/stems/join-monster/issues/206","id":252473106,"number":206,"title":"lifecycle method before a resolver / queries are executed?","user":{"login":"theogravity","id":855434,"avatar_url":"https://avatars1.githubusercontent.com/u/855434?v=4","gravatar_id":"","url":"https://api.github.com/users/theogravity","html_url":"https://github.com/theogravity","followers_url":"https://api.github.com/users/theogravity/followers","following_url":"https://api.github.com/users/theogravity/following{/other_user}","gists_url":"https://api.github.com/users/theogravity/gists{/gist_id}","starred_url":"https://api.github.com/users/theogravity/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theogravity/subscriptions","organizations_url":"https://api.github.com/users/theogravity/orgs","repos_url":"https://api.github.com/users/theogravity/repos","events_url":"https://api.github.com/users/theogravity/events{/privacy}","received_events_url":"https://api.github.com/users/theogravity/received_events","type":"User","site_admin":false},"labels":[{"id":443302038,"url":"https://api.github.com/repos/stems/join-monster/labels/bug","name":"bug","color":"ee0701","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2017-08-24T02:59:12Z","updated_at":"2017-09-14T03:12:01Z","closed_at":"2017-09-13T19:35:50Z","author_association":"NONE","body":"I have API calls that determine auth for a particular field. This field might be nested deeply. \r\n\r\nI know a common pattern is to call your auth-type APIs within the `resolve` method, but I have a situation where I'm trying to gate against a field that's at a level below root, which is using `sqlBatch`.\r\n\r\nI've tried doing the following, without success:\r\n\r\n```\r\nfields: () => ({\r\n  animals: {\r\n    type: AnimalConnection,\r\n    description: `The owner's animals.`,\r\n    sqlPaginate: true,\r\n    sortKey: {\r\n      order: 'DESC',\r\n      key: 'id'\r\n    },\r\n    sqlBatch: {\r\n       thisKey: 'animal_id',\r\n       parentKey: 'id'\r\n    },\r\n    resolve: async (...) => {\r\n         // my auth API calls\r\n\r\n        /*\r\n        I get a ' Cannot read property 'map' of undefined' in\r\n\r\n\texception in node_modules/join-monster/dist/stringifiers/dialects/pg.js:146\r\n\t 144         pagingWhereConditions.push((yield node.where(`\"${node.as}\"`, node.args || {}, context, node)));\r\n\t 145       }\r\n\t>146       const tempTable = `FROM (VALUES ${batchScope.map(function (val) {\r\n\t 147         return `(${val})`;\r\n\t 148       })}) temp(\"${node.sqlBatch.parentKey.name}\")`;\r\n        */\r\n       \r\n        return joinMonster(...)\r\n    }\r\n  }\r\n})\r\n```\r\n\r\nNote: I have already called `joinMonster` at the root query level, and the above field is a child nested under. \r\n\r\nOmitting `resolve` in the above case will work, but I'm unable inject my auth code in. It'd be nice to have a `beforeQuery` lifecycle method to be able to gate the field (I throw an exception if the user doesn't have the perms in my case).\r\n"},"comment":{"url":"https://api.github.com/repos/stems/join-monster/issues/comments/329357333","html_url":"https://github.com/stems/join-monster/issues/206#issuecomment-329357333","issue_url":"https://api.github.com/repos/stems/join-monster/issues/206","id":329357333,"user":{"login":"theogravity","id":855434,"avatar_url":"https://avatars1.githubusercontent.com/u/855434?v=4","gravatar_id":"","url":"https://api.github.com/users/theogravity","html_url":"https://github.com/theogravity","followers_url":"https://api.github.com/users/theogravity/followers","following_url":"https://api.github.com/users/theogravity/following{/other_user}","gists_url":"https://api.github.com/users/theogravity/gists{/gist_id}","starred_url":"https://api.github.com/users/theogravity/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theogravity/subscriptions","organizations_url":"https://api.github.com/users/theogravity/orgs","repos_url":"https://api.github.com/users/theogravity/repos","events_url":"https://api.github.com/users/theogravity/events{/privacy}","received_events_url":"https://api.github.com/users/theogravity/received_events","type":"User","site_admin":false},"created_at":"2017-09-14T03:12:00Z","updated_at":"2017-09-14T03:12:00Z","author_association":"NONE","body":"The reason  why I was doing it in the child is because when that field is accessed I need to do specific ACL checks before I can say it should proceed to batch\r\n\r\nI also need access to the context to perform the checks "}}
{"actor":{"display_login":"theogravity"}}