{"id":19998719,"url":"https://github.com/tenry92/graphql-decorators-mongo","last_synced_at":"2026-05-06T19:40:35.782Z","repository":{"id":57165534,"uuid":"125721473","full_name":"tenry92/graphql-decorators-mongo","owner":"tenry92","description":"Provide mongo access using annotated classes and the GraphQL query language.","archived":false,"fork":false,"pushed_at":"2018-04-04T16:37:28.000Z","size":49,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-13T02:56:52.698Z","etag":null,"topics":["decorators","graphql","mongo","mongodb","object-document-mapper","odm"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tenry92.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-18T12:14:15.000Z","updated_at":"2018-04-04T16:37:29.000Z","dependencies_parsed_at":"2022-08-30T15:21:06.911Z","dependency_job_id":null,"html_url":"https://github.com/tenry92/graphql-decorators-mongo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tenry92%2Fgraphql-decorators-mongo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tenry92%2Fgraphql-decorators-mongo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tenry92%2Fgraphql-decorators-mongo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tenry92%2Fgraphql-decorators-mongo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tenry92","download_url":"https://codeload.github.com/tenry92/graphql-decorators-mongo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241439486,"owners_count":19963095,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["decorators","graphql","mongo","mongodb","object-document-mapper","odm"],"created_at":"2024-11-13T05:09:18.862Z","updated_at":"2025-11-25T22:08:26.695Z","avatar_url":"https://github.com/tenry92.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @tenry/graphql-decorators-mongo\n\nThis package provides useful TypeScript decorators for creating class-based\nentities, persisted to a mongo database and queryable and manipulable using the\nGraphQL query language.\n\nIt is based on the `@tenry/graphql-decorators` package.\n\n\n## Example\n\n~~~ts\n// import the libraries\nimport {MongoClient} from 'mongodb';\nimport {decorators} from '@tenry/graphql-decorators';\nimport {Manager, name} from '@tenry/graphql-decorators-mongo';\n\n// define an entity\n@decorators.entity()\n// define a name; class name is used by default\n@name('user')\nclass User {\n  @decorators.field('ID')\n  id: string;\n\n  // primitive types like string or number is automatically detected,\n  // if the emitDecoratorMetadata flag is enabled\n  @decorators.field()\n  name: string;\n\n  @decorators.field('JSON')\n  data: Object;\n\n  // use this syntax, if the data type is an array of something\n  @decorators.field({list: User})\n  friends: User[];\n}\n\n// now set everything up\nconst mongo = await MongoClient.connect('mongodb://localhost');\nconst db = mongo.db('my_database');\nconst manager = new Manager(db);\n\n// register all available entities\nmanager.registerEntity(User);\n\n// get GraphQL schema\nconst schema = manager.createSchema();\n\n// now do whatever you would do with a GraphQL schema\ngraphql(schema, someAwesomeGraphqlQuery).then(response =\u003e {\n  console.log(response);\n});\n\n// or (using express and express-graphql):\nconst app = express();\n\napp.use('/graphql', graphqlHTTP({\n  schema,\n}));\n\napp.listen(8080);\n~~~\n\nUsing this example the library would create the following GraphQL schema:\n\n~~~graphql\ninput MongoFilterInput {\n  field: String\n  operator: String\n  value: JSON\n}\n\ninput MongoOrderInput {\n  field: String\n  order: String\n}\n\ntype Mutation {\n  addUser(user: UserInput): UserType\n  updateUser(id: ID, user: UserInput): UserType\n  removeUser(id: ID): UserType\n}\n\ntype Query {\n  users(filter: [MongoFilterInput], order: [MongoOrderInput], limit: Int, offset: Int): [UserType]\n}\n\ninput UserInput {\n  data: JSON\n  friends: [UserInput]\n  id: ID\n  name: String\n}\n\ntype UserType {\n  data: JSON\n  friends: [UserType]\n  id: ID\n  name: String\n}\n~~~\n\n\n## Installation and Usage\n\nUse `npm` to install the package:\n\n~~~sh\n$ npm install graphql graphql-type-json mongodb @tenry/graphql-decorators @tenry/graphql-decorators-mongo\n~~~\n\nNow *import* the `Manager`, the `name` decorator along with the decorators from\n`@tenry/graphql-decorators`:\n\n~~~ts\nimport {Manager, name} from '@tenry/graphql-decorators-mongo';\nimport {decorators} from '@tenry/graphql-decorators';\n\nimport {MongoClient} from 'mongodb';\n\nconst mongo = await MongoClient.connect('mongodb://localhost');\nconst db = mongo.db('my_database');\n\nconst manager = new Manager(db);\n\n// define entities here\n// register entities to the manager via manager.registerEntity(MyEntity); here\n\n// retrieve GraphQL schema\nconst schema = manager.createSchema();\n~~~\n\n\n## License\n\n@tenry/graphql-decorators-mongo is licensed under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftenry92%2Fgraphql-decorators-mongo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftenry92%2Fgraphql-decorators-mongo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftenry92%2Fgraphql-decorators-mongo/lists"}