{"action":"created","issue":{"url":"https://api.github.com/repos/calebmer/postgraphql/issues/400","repository_url":"https://api.github.com/repos/calebmer/postgraphql","labels_url":"https://api.github.com/repos/calebmer/postgraphql/issues/400/labels{/name}","comments_url":"https://api.github.com/repos/calebmer/postgraphql/issues/400/comments","events_url":"https://api.github.com/repos/calebmer/postgraphql/issues/400/events","html_url":"https://github.com/calebmer/postgraphql/issues/400","id":215160487,"number":400,"title":"Custom hook for process query results","user":{"login":"SDSWanderer","id":1102227,"avatar_url":"https://avatars1.githubusercontent.com/u/1102227?v=3","gravatar_id":"","url":"https://api.github.com/users/SDSWanderer","html_url":"https://github.com/SDSWanderer","followers_url":"https://api.github.com/users/SDSWanderer/followers","following_url":"https://api.github.com/users/SDSWanderer/following{/other_user}","gists_url":"https://api.github.com/users/SDSWanderer/gists{/gist_id}","starred_url":"https://api.github.com/users/SDSWanderer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SDSWanderer/subscriptions","organizations_url":"https://api.github.com/users/SDSWanderer/orgs","repos_url":"https://api.github.com/users/SDSWanderer/repos","events_url":"https://api.github.com/users/SDSWanderer/events{/privacy}","received_events_url":"https://api.github.com/users/SDSWanderer/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-03-18T02:30:00Z","updated_at":"2017-03-18T18:20:17Z","closed_at":null,"body":"I use this awesome project + graphiql to provide extended interface for admins. It's completely what we need, but it's a little bit tricky to mask some sensitive fields in responses like that:\r\n![screen shot 2017-03-18 at 2 39 49 am](https://cloud.githubusercontent.com/assets/1102227/24068182/deef1db2-0b90-11e7-9771-db596813bed1.png)\r\n\r\nI implement this by using low-level interface functions `createPostGraphQLSchema` and `withPostGraphQLContext`. It's ok, but I have lot's of project's and don't want to copy-paste this solution, instead, it will be great to extend `postgraphql`, and pass custom handler in it. \r\n\r\nI think it will be really useful for lot's of users, since`postgraphql` function has super-friendly interface, works as middleware for express and can be combined with other middlewares to pre-process request, so I offer to add ability for post-process response.\r\n"},"comment":{"url":"https://api.github.com/repos/calebmer/postgraphql/issues/comments/287564580","html_url":"https://github.com/calebmer/postgraphql/issues/400#issuecomment-287564580","issue_url":"https://api.github.com/repos/calebmer/postgraphql/issues/400","id":287564580,"user":{"login":"SDSWanderer","id":1102227,"avatar_url":"https://avatars1.githubusercontent.com/u/1102227?v=3","gravatar_id":"","url":"https://api.github.com/users/SDSWanderer","html_url":"https://github.com/SDSWanderer","followers_url":"https://api.github.com/users/SDSWanderer/followers","following_url":"https://api.github.com/users/SDSWanderer/following{/other_user}","gists_url":"https://api.github.com/users/SDSWanderer/gists{/gist_id}","starred_url":"https://api.github.com/users/SDSWanderer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SDSWanderer/subscriptions","organizations_url":"https://api.github.com/users/SDSWanderer/orgs","repos_url":"https://api.github.com/users/SDSWanderer/repos","events_url":"https://api.github.com/users/SDSWanderer/events{/privacy}","received_events_url":"https://api.github.com/users/SDSWanderer/received_events","type":"User","site_admin":false},"created_at":"2017-03-18T18:20:17Z","updated_at":"2017-03-18T18:20:17Z","body":"@benjie no problem, it's pretty trivial and based on this library documentation.\r\n\r\nThis is definition of my middleware, execGraphQL\r\n```javascript\r\nconst Pool = require('pg-pool')\r\nconst { graphql } = require('graphql')\r\nconst { createPostGraphQLSchema, withPostGraphQLContext } = require('postgraphql')\r\n\r\nconst { copyWithoutSecrets } = require('../services/util')\r\n\r\nconst pgOpts = {\r\n  ...\r\n}\r\nconst pgPool = new Pool(pgOpts)\r\nconst createSchema = createPostGraphQLSchema(pgOpts)\r\n\r\nmodule.exports = function(req, res) {\r\n  return createSchema.then(schema => {\r\n    const cb = context => graphql(\r\n      schema,\r\n      req.body.query,\r\n      null,\r\n      req.body.context,\r\n      req.body.variables,\r\n      operationName\r\n    )\r\n\r\n    return withPostGraphQLContext({pgPool}, cb)\r\n  })\r\n  .then(copyWithoutSecrets) // Process result with custom handler\r\n  .then(processedResult => res.json(processedResult))\r\n}\r\n```\r\n\r\nAnd this is how I use it:\r\n```javascript\r\napp.post('/admin/graphql', checkAdminPermissions, execGraphQL)\r\n```\r\n\r\nSo, I want to use `postgraphql` middleware like that:\r\n```javascript\r\napp.post('/admin/graphql', checkAdminPermissions, postgraphql({resultHandler: copyWithoutSecrets}))\r\n```\r\nOr \r\n```javascript\r\napp.post('/admin/graphql', checkAdminPermissions, postgraphql(), copyWithoutSecretsMiddleware)\r\n```"}}
{"actor":{"display_login":"SDSWanderer"}}