{"action":"created","issue":{"url":"https://api.github.com/repos/mickhansen/graphql-sequelize/issues/107","labels_url":"https://api.github.com/repos/mickhansen/graphql-sequelize/issues/107/labels{/name}","comments_url":"https://api.github.com/repos/mickhansen/graphql-sequelize/issues/107/comments","events_url":"https://api.github.com/repos/mickhansen/graphql-sequelize/issues/107/events","html_url":"https://github.com/mickhansen/graphql-sequelize/issues/107","id":123815189,"number":107,"title":"Couldnt find anything that works with graphql-relay","user":{"login":"MattMcFarland","id":623545,"avatar_url":"https://avatars.githubusercontent.com/u/623545?v=3","gravatar_id":"","url":"https://api.github.com/users/MattMcFarland","html_url":"https://github.com/MattMcFarland","followers_url":"https://api.github.com/users/MattMcFarland/followers","following_url":"https://api.github.com/users/MattMcFarland/following{/other_user}","gists_url":"https://api.github.com/users/MattMcFarland/gists{/gist_id}","starred_url":"https://api.github.com/users/MattMcFarland/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MattMcFarland/subscriptions","organizations_url":"https://api.github.com/users/MattMcFarland/orgs","repos_url":"https://api.github.com/users/MattMcFarland/repos","events_url":"https://api.github.com/users/MattMcFarland/events{/privacy}","received_events_url":"https://api.github.com/users/MattMcFarland/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-12-24T15:46:42Z","updated_at":"2015-12-26T07:49:08Z","closed_at":null,"body":"Your library seems to work with graphql but not graphql-relay, at least not with the examples I saw.\r\n\r\nI was able to write up something pretty light weight that works well with graphql-relay, out of the box.\r\n\r\nI could not figure out how to use your library, I kept getting errors whenever I tried to use it with `graphql-relay` `connectionArgs`, and `connectionFromArray`, etc.  `resolver` does not seem to work.\r\n\r\nSo after spending a couple hours hitting a wall I figured I'd just make something.\r\n\r\n```javascript\r\n**\r\n * Returns a promise that will resolve into an array by using the Model class\r\n * static findAll method.\r\n */\r\nexport const getModelsByClass = (model) => {\r\n  return model.findAll();\r\n};\r\n\r\n\r\n/**\r\n * Returns a new promise containing a new array with only consumable data.\r\n */\r\nexport const getArrayData = (models) => {\r\n  return new Promise((resolve, reject) => {\r\n    try {\r\n      resolve(resolveArrayData(models));\r\n    } catch (error) {\r\n      reject(error);\r\n    }\r\n  });\r\n};\r\n\r\n/**\r\n * Returns a promise that will resolve into a relay-compatible array of the\r\n * given Model Class.\r\n */\r\nexport const getArrayByClass = (model) => {\r\n  return new Promise((resolve, reject) => {\r\n    try {\r\n      resolve(getArrayData(getModelsByClass(model)));\r\n    } catch (error) {\r\n      reject(error);\r\n    }\r\n  });\r\n};\r\n\r\n\r\n/**\r\n * Returns an array of Models by using the Model class static findAll method.\r\n */\r\nexport const resolveModelsByClass = async (model) => {\r\n  return await model.findAll();\r\n};\r\n\r\n\r\n/**\r\n * Returns a new array containing only consumable data from a model array.\r\n * @param models Array<Model>\r\n * @returns Array<Object>\r\n */\r\nexport const resolveArrayData = (models) => {\r\n  let array = models.map(model => {\r\n    return Object.assign({}, {\r\n        type: model.type\r\n      }, {\r\n        ...model.dataValues\r\n      }\r\n    );\r\n  });\r\n  return [].concat(...array);\r\n};\r\n\r\n\r\n/**\r\n * Returns a new array containing only consumable data from a model Class.\r\n * @param model\r\n * @returns Array<Object>\r\n */\r\nexport const resolveArrayByClass = async (model) => {\r\n\r\n  let models = await resolveModelsByClass(model);\r\n  return resolveArrayData(models);\r\n\r\n};\r\n```\r\n\r\nYou can now use `connectionArgs` `nodeConnections` etc\r\n\r\n```javascript\r\n      people: {\r\n        decription: 'People',\r\n        type: personConnection,\r\n        args: connectionArgs,\r\n        resolve: (root, args) =>\r\n          connectionFromPromisedArray(resolveArrayByClass(Person), args)\r\n      },\r\n```\r\n\r\nI even have some unit test that prove it:\r\n\r\n[Imgur](http://i.imgur.com/j9uU0Oj.png)\r\n\r\nI have a separate repo here, https://github.com/MattMcFarland/sequelize-relay - it does not work with mutations yet, at least its not set up to.  I am thinking it might be worth it to maybe modify graphql-sequelize instead"},"comment":{"url":"https://api.github.com/repos/mickhansen/graphql-sequelize/issues/comments/167293627","html_url":"https://github.com/mickhansen/graphql-sequelize/issues/107#issuecomment-167293627","issue_url":"https://api.github.com/repos/mickhansen/graphql-sequelize/issues/107","id":167293627,"user":{"login":"mickhansen","id":699049,"avatar_url":"https://avatars.githubusercontent.com/u/699049?v=3","gravatar_id":"","url":"https://api.github.com/users/mickhansen","html_url":"https://github.com/mickhansen","followers_url":"https://api.github.com/users/mickhansen/followers","following_url":"https://api.github.com/users/mickhansen/following{/other_user}","gists_url":"https://api.github.com/users/mickhansen/gists{/gist_id}","starred_url":"https://api.github.com/users/mickhansen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mickhansen/subscriptions","organizations_url":"https://api.github.com/users/mickhansen/orgs","repos_url":"https://api.github.com/users/mickhansen/repos","events_url":"https://api.github.com/users/mickhansen/events{/privacy}","received_events_url":"https://api.github.com/users/mickhansen/received_events","type":"User","site_admin":false},"created_at":"2015-12-26T07:49:08Z","updated_at":"2015-12-26T07:49:08Z","body":"You can choose to use this library to help you with connectors.\r\nIt provides effective ordered pagination via cursors and prefetching of connections where it makes sense."}}