{"_id":"@adamvr/joiql","_rev":"1-07078a24976d039c4a61928e6e8536be","name":"@adamvr/joiql","description":"Make GraphQL schema creation and data validation easy with Joi.","dist-tags":{"latest":"0.1.5"},"versions":{"0.1.5":{"name":"@adamvr/joiql","version":"0.1.5","description":"Make GraphQL schema creation and data validation easy with Joi.","main":"index.js","scripts":{"test":"standard && npm run mocha","mocha":"mocha -r should","b":"browserify script.js -o bundle.js -t [ babelify --presets [ es2015 ] ]"},"author":"","license":"MIT","dependencies":{"graphql":"^0.11.7","lodash":"^4.13.1"},"peerDependencies":{"joi":"^9.0.0"},"devDependencies":{"express":"^4.14.0","express-graphql":"^0.5.3","joi":"^9.2.0","mocha":"^2.5.3","rewire":"^2.5.2","should":"^10.0.0","standard":"^7.1.2","superagent":"^2.1.0"},"gitHead":"2ebcc076d3e014dd3b42541859e4703ef82f7e7c","_id":"@adamvr/joiql@0.1.5","_npmVersion":"5.4.2","_nodeVersion":"8.6.0","_npmUser":{"name":"adamvr","email":"adamvrr+npm@gmail.com"},"dist":{"integrity":"sha512-6oHje7RFzCr5yIvdHMvcD9AmMjKyn1QKRmHRZnrpgns1OBhhUs1uu4l/uYP8JW5wBgU04wj+dymy/HWzw7l/MQ==","shasum":"066ab298c34df643570cb808dcac47fc0b4d3cd9","tarball":"https://registry.npmjs.org/@adamvr/joiql/-/joiql-0.1.5.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDsUPoVQdLwo5Ykuc2oMBDDc/7E61VvhIb9NLRFkrqSTAIhAOvtwWUogZeJkx4mZuHtgalqcfNhLyzy84Bw684owGTP"}]},"maintainers":[{"name":"adamvr","email":"adamvrr+npm@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/joiql-0.1.5.tgz_1507201982680_0.24546129466034472"}}},"readme":"# joiql\n\nMake [GraphQL](http://graphql.org/) schema creation and data validation easy with [Joi](https://github.com/hapijs/joi).\n\n## Example\n\nRun this using `node example`...\n\n````javascript\nconst joiql = require('joiql')\nconst { object, string, number, array, date } = require('joi')\nconst app = require('express')()\nconst graphqlHTTP = require('express-graphql')\n\n// Joi Schemas\nconst Film = object({\n  title: string(),\n  producers: array().items(string()),\n  release_date: date()\n})\n\nconst Person = object({\n  name: string(),\n  films: array().items(Film)\n}).meta({\n  args: { id: number().required() },\n  resolve: (root, args, req, ast) => ({ name: 'Spike Jonze' })\n})\n\n// Convert Joi schemas to GraphQL\nconst schema = joiql({\n  query: {\n    person: Person,\n    film: Film\n  }\n})\n\n// Mount schema to express\napp.use('/', graphqlHTTP({ schema: schema, graphiql: true }))\napp.listen(3000, () => console.log('listening on 3000'))\n````\n\n## Breaking it down\n\nFirst, define some schemas using [Joi](https://github.com/hapijs/joi).\n\n````javascript\nconst { object, string, number, array, date } = require('joi')\n\nconst Film = object({\n  title: string(),\n  producers: array().items(string()),\n  releaseDate: date()\n})\n\nconst Person = object({\n  name: string(),\n  films: array().items(Film)\n})\n````\n\nJoiQL uses the [`meta` property](https://github.com/hapijs/joi/blob/v9.0.4/API.md#anymetameta) to extend GraphQL fields. Use `meta.args` to define GraphQL arguments (adding automatic\ninput validation), and `meta.name` to declare the `GraphQLObjectType` type name (without it JoiQL will automatically\nadd a \"Anon<UID>\" type name).\n\n````javascript\nPerson.meta({\n  name: 'Person',\n  args: { id: number().required() }\n})\n````\n\nThen create a JoiQL `api` object from the Joi schemas and expose a GraphQL.js schema object for mounting into a server like Express.\n\n````javascript\nconst { graphql } = require('graphql')\nconst joiql = require('../')\n\nconst api = joiql({\n  query: {\n    person: Person,\n    film: Film\n  }\n})\n\ngraphql(api.schema, ...)\n````\n\n## TODO\n\n* Figure out how to do circular dependencies (ideally with Joi `lazy`)\n\n## Contributing\n\nPlease fork the project and submit a pull request with tests. Install node modules `npm install` and run tests with `npm test`.\n\n## License\n\nMIT\n","maintainers":[{"name":"adamvr","email":"adamvrr+npm@gmail.com"}],"time":{"modified":"2022-04-04T11:25:41.545Z","created":"2017-10-05T11:13:03.605Z","0.1.5":"2017-10-05T11:13:03.605Z"},"license":"MIT","readmeFilename":"README.md"}