{"_id":"@eigenjoy/graffiti-mongoose","_rev":"4-22f4114a1b12d9b209eae6be9a67517d","name":"@eigenjoy/graffiti-mongoose","description":"PERSONAL FORK: Mongoose adapter for graffiti (Node.js GraphQL ORM)","dist-tags":{"latest":"4.3.3"},"versions":{"4.3.2":{"name":"@eigenjoy/graffiti-mongoose","version":"4.3.2","description":"PERSONAL FORK: Mongoose adapter for graffiti (Node.js GraphQL ORM)","main":"lib/index.js","scripts":{"test":"NODE_ENV=test mocha --compilers js:babel/register --require co-mocha 'src/**/*.spec.js'","eslint":"eslint src","prepublish":"npm test && npm run build","build":"rm -rf lib/* && babel src --ignore *.spec.js --out-dir lib","coverage":"NODE_ENV=test babel-istanbul --include-babel-polyfill cover _mocha 'src/**/*.spec.js'"},"author":{"name":"RisingStack"},"repository":{"type":"git","url":"git+ssh://git@github.com/RisingStack/graffiti-mongoose.git"},"bugs":{"url":"https://github.com/RisingStack/graffiti-mongoose/issues"},"homepage":"https://github.com/RisingStack/graffiti-mongoose#readme","license":"MIT","keywords":["GraphQL","graffiti","mongoose","ORM","Relay"],"dependencies":{"graphql-relay":"^0.3.4","lodash":"^3.10.1"},"peerDependencies":{"graphql":"^0.4.13"},"devDependencies":{"babel":"^5.8.29","babel-eslint":"^4.1.3","babel-istanbul":"^0.5.9","chai":"^3.4.0","chai-subset":"^1.1.0","co-mocha":"^1.1.2","eslint":"^1.10.3","eslint-config-airbnb":"^1.0.2","graphql":"^0.4.12","mocha":"^2.3.3","mongoose":"^4.2.8","pre-commit":"^1.1.2","sinon":"^1.17.2","sinon-chai":"^2.8.0"},"pre-commit":["test"],"babel":{"stage":0},"gitHead":"4b0e972dd7f448b87568581e1b5d2168b073cf13","_id":"@eigenjoy/graffiti-mongoose@4.3.2","_shasum":"f3e42c0b178604fc7396292052b7b988c24945fa","_from":".","_npmVersion":"3.3.10","_nodeVersion":"4.1.2","_npmUser":{"name":"eigenjoy","email":"nate@natemurray.com"},"dist":{"shasum":"f3e42c0b178604fc7396292052b7b988c24945fa","tarball":"https://registry.npmjs.org/@eigenjoy/graffiti-mongoose/-/graffiti-mongoose-4.3.2.tgz","integrity":"sha512-JkO51/lp0/lb2Iu9yfiRvHuEZ/JsomnGpzbpJT/OSCQzzFz2LpT9oOW1ducrBkSKF5/HHZXiUuiERw7M9aQd+w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIF0Nrv+TaSV8QHtfkz4xQaR2uVfXR6GACs69Is+hG41FAiAqG6MOKZVS5hEcbZKj8jdEo1tjBvvUTqn1BjSbjXP4OA=="}]},"maintainers":[{"name":"eigenjoy","email":"nate@natemurray.com"}]},"4.3.3":{"name":"@eigenjoy/graffiti-mongoose","version":"4.3.3","description":"PERSONAL FORK: Mongoose adapter for graffiti (Node.js GraphQL ORM)","main":"lib/index.js","scripts":{"test":"NODE_ENV=test mocha --compilers js:babel/register --require co-mocha 'src/**/*.spec.js'","eslint":"eslint src","prepublish":"npm test && npm run build","build":"rm -rf lib/* && babel src --ignore *.spec.js --out-dir lib","coverage":"NODE_ENV=test babel-istanbul --include-babel-polyfill cover _mocha 'src/**/*.spec.js'"},"author":{"name":"RisingStack"},"repository":{"type":"git","url":"git+ssh://git@github.com/RisingStack/graffiti-mongoose.git"},"bugs":{"url":"https://github.com/RisingStack/graffiti-mongoose/issues"},"homepage":"https://github.com/RisingStack/graffiti-mongoose#readme","license":"MIT","keywords":["GraphQL","graffiti","mongoose","ORM","Relay"],"dependencies":{"graphql-relay":"^0.3.4","lodash":"^3.10.1"},"peerDependencies":{"graphql":"^0.4.13"},"devDependencies":{"babel":"^5.8.29","babel-eslint":"^4.1.3","babel-istanbul":"^0.5.9","chai":"^3.4.0","chai-subset":"^1.1.0","co-mocha":"^1.1.2","eslint":"^1.10.3","eslint-config-airbnb":"^1.0.2","graphql":"^0.4.12","mocha":"^2.3.3","mongoose":"^4.2.8","pre-commit":"^1.1.2","sinon":"^1.17.2","sinon-chai":"^2.8.0"},"pre-commit":["test"],"babel":{"stage":0},"gitHead":"0de6dab9802af01004144f7de28e8d0e453d915e","_id":"@eigenjoy/graffiti-mongoose@4.3.3","_shasum":"1b119418e88ae2334145119a628d30770d9f5d43","_from":".","_npmVersion":"3.3.10","_nodeVersion":"4.1.2","_npmUser":{"name":"eigenjoy","email":"nate@natemurray.com"},"dist":{"shasum":"1b119418e88ae2334145119a628d30770d9f5d43","tarball":"https://registry.npmjs.org/@eigenjoy/graffiti-mongoose/-/graffiti-mongoose-4.3.3.tgz","integrity":"sha512-55oisFVGBOZyFMtC1lVOWXJJloQVfLCZaBikJ75h/ciKhzXcDQQPKDvEh2ib5gPH6wA/0fKD/xN83V0X+EzFRg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDMW6i2ja5xwGkwlAv667mxwUN5jinKSYxuC1a/v0GhwgIhAJAybaxNOGOj3DYtKLkBm3nrxG4/F6xBOOZxhiZFw7nR"}]},"maintainers":[{"name":"eigenjoy","email":"nate@natemurray.com"}]}},"readme":"# graffiti-mongoose [![npm version](https://badge.fury.io/js/%40risingstack%2Fgraffiti-mongoose.svg)](https://badge.fury.io/js/%40risingstack%2Fgraffiti-mongoose)\n\n[![Codeship Status for RisingStack/graffiti-mongoose](https://codeship.com/projects/f7a22cd0-5968-0133-d2b0-0e957d4e7dfa/status?branch=master)](https://codeship.com/projects/110028)\n\n[Mongoose](http://mongoosejs.com) (MongoDB) adapter for the [graffiti](https://github.com/RisingStack/graffiti) [GraphQL](https://github.com/graphql/graphql-js) ORM.  \n\n`graffiti-mongoose` generates `GraphQL` types and schemas from your existing `mongoose` models, that's how simple it is. The generated schema is compatible with [Relay](https://facebook.github.io/relay/).\n\nFor quick jump check out the [Usage section](https://github.com/RisingStack/graffiti-mongoose#graffiti-mongoose-1).\n\n## Install\n\n```shell\nnpm install graphql @risingstack/graffiti-mongoose --save\n```\n\n## Example\n\nCheck out the [/example](https://github.com/RisingStack/graffiti-mongoose/tree/master/example) folder.\n\n```shell\ncd graffiti-mongoose\nnpm install # install dependencies in the main folder\ncd example\nnpm install # install dependencies in the example folder\nnpm start # run the example application and open your browser: http://localhost:8080\n```\n\n## Usage\n\nThis adapter is written in `ES6` and `ES7` with [Babel](https://babeljs.io) but it's published as transpiled `ES5` JavaScript code to `npm`, which means you don't need `ES7` support in your application to run it.  \n\n__Example queries can be found in the [example folder](https://github.com/RisingStack/graffiti-mongoose/tree/master/example#example-queries).__\n\n##### usual mongoose model(s)\n```javascript\nimport mongoose from 'mongoose';\n\nconst UserSchema = new mongoose.Schema({\n  name: {\n    type: String,\n    // field description\n    description: 'the full name of the user'\n  },\n  hiddenField: {\n    type: Date,\n    default: Date.now,\n    // the field is hidden, not available in GraphQL\n    hidden: true\n  },\n  age: {\n    type: Number,\n    indexed: true\n  },\n  friends: [{\n    type: mongoose.Schema.Types.ObjectId,\n    ref: 'User'\n  }]\n});\n\nconst User = mongoose.model('User', UserSchema);\nexport default User;\n```\n\n##### graffiti-mongoose\n```javascript\nimport {getSchema} from '@risingstack/graffiti-mongoose';\nimport graphql from 'graphql';\nimport User from './User';\n\nconst options = {\n  mutation: false // mutation fields can be disabled\n};\nconst schema = getSchema([User], options);\n\nconst query = `{\n    users(age: 28) {\n      name\n      friends(first: 2) {\n        edges {\n          cursor\n          node {\n            name\n            age\n          }\n        }\n        pageInfo {\n          startCursor\n          endCursor\n          hasPreviousPage\n          hasNextPage\n        }\n      }\n    }\n  }`;\n\ngraphql(schema, query)\n  .then((result) => {\n    console.log(result);\n  });\n```\n\n## Supported mongoose types\n\n* Number\n* String\n* Boolean\n* Date\n* [Number]\n* [String]\n* [Boolean]\n* [Date]\n* ObjectId with ref (reference to other document, populate)\n* more types coming soon...\n\n## Supported query types\n\n* query\n  * singular: for example `user`\n  * plural: for example `users`\n  * [node](https://facebook.github.io/relay/docs/graphql-object-identification.html): takes a single argument, a unique `!ID`, and returns a `Node`\n  * viewer: singular and plural queries as fields\n\n## Supported query arguments\n\n* indexed fields\n* \"id\" on singular type\n* array of \"id\"s on plural type\n\nWhich means, you are able to filter like below, if the age is indexed in your mongoose model:\n\n```\nusers(age: 19) {}\nuser(id: \"mongoId1\") {}\nuser(id: \"relayId\") {}\nusers(id: [\"mongoId\", \"mongoId2\"]) {}\nusers(id: [\"relayId1\", \"relayId2\"]) {}\n```\n\n## Supported mutation types\n\n* mutation\n  * addX: for example `addUser`\n  * updateX: for example `updateUser`\n  * deleteX: for example `deleteUser`\n\n## Supported mutation arguments\n\n* scalar types\n* arrays\n* references\n\nExamples:\n```\nmutation addX {\n  addUser(input: {name: \"X\", age: 11, clientMutationId: \"1\"}) {\n    id\n    name\n  }\n}\n```\n\n```\nmutation updateX {\n  updateUser(input: {id: \"xpmsdfonasd\", age: 10, clientMutationId: \"2\"}) {\n    id\n    name\n    age\n  }\n}\n```\n\n```\nmutation deleteX {\n  deleteUser(input: {id: \"xpmsdfonasd\", clientMutationId: \"3\"}) {\n    ok\n  }\n}\n```\n\n## Resolve hooks\n\nYou can specify pre- and post-resolve hooks on fields in order to manipulate arguments and data passed in to the database resolve function, and returned by the GraphQL resolve function.\n\nYou can add hooks to type fields and query fields (singular & plural queries, mutations) too.\nBy passing arguments to the `next` function, you can modify the parameters of the next hook or the return value of the `resolve` function.\n\nExamples:\n- Query, mutation hooks (`viewer`, `singular`, `plural`, `mutation`)\n```javascript\nconst hooks = {\n  viewer: {\n    pre: (next, root, args, {rootValue}) => {\n      const {request} = rootValue;\n      // authorize the logged in user based on the request\n      authorize(request);\n      next();\n    },\n    post: (next, value) => {\n      console.log(value);\n      next();\n    }\n  },\n  // singular: {\n  //   pre: (next, root, args, context) => next(),\n  //   post: (next, value, args, context) => next()\n  // },\n  // plural: {\n  //   pre: (next, root, args, context) => next(),\n  //   post: (next, value, args, context) => next()\n  // },\n  // mutation: {\n  //   pre: (next, args, context) => next(),\n  //   post: (next, value, args, context) => next()\n  // }\n};\nconst schema = getSchema([User], {hooks});\n```\n\n- Field hooks\n```javascript\nconst UserSchema = new mongoose.Schema({\n  name: {\n    type: String,\n    hooks: {\n      pre: (next, root, args, {rootValue}) => {\n        const {request} = rootValue;\n\n        // authorize the logged in user based on the request\n        // throws error if the user has no right to request the user names\n        authorize(request);\n        next();\n      },\n      // manipulate response\n      post: [\n        (next, name) => next(`${name} first hook`),\n        (next, name) => next(`${name} & second hook`)\n      ]\n    }\n  }\n});\n```\n```\nquery UsersQuery {\n  viewer {\n    users(first: 1) {\n      edges {\n        node {\n          name\n        }\n      }\n    }\n  }\n}\n```\n```json\n{\n  \"data\": {\n    \"viewer\": {\n      \"users\": {\n        \"edges\": [\n          {\n            \"node\": {\n              \"name\": \"User0 first hook & second hook\"\n            }\n          }\n        ]\n      }\n    }\n  }\n}\n```\n\n## Test\n\n```shell\nnpm test\n```\n\n## License\n\n[MIT](https://github.com/RisingStack/graffiti-mongoose/tree/master/LICENSE)\n","maintainers":[{"name":"eigenjoy","email":"nate@natemurray.com"}],"time":{"modified":"2022-06-12T17:29:45.636Z","created":"2015-12-08T22:15:49.105Z","4.3.2":"2015-12-08T22:15:49.105Z","4.3.3":"2015-12-09T22:16:19.900Z"},"homepage":"https://github.com/RisingStack/graffiti-mongoose#readme","keywords":["GraphQL","graffiti","mongoose","ORM","Relay"],"repository":{"type":"git","url":"git+ssh://git@github.com/RisingStack/graffiti-mongoose.git"},"author":{"name":"RisingStack"},"bugs":{"url":"https://github.com/RisingStack/graffiti-mongoose/issues"},"license":"MIT","readmeFilename":"README.md"}