@tenry/graphql-decorators-mongo
This package provides useful TypeScript decorators for creating class-based entities, persisted to a mongo database and queryable and manipulable using the GraphQL query language.
It is based on the @tenry/graphql-decorators
package.
Example
// import the libraries;;; // define an entity // now set everything up;;; // register all available entitiesmanager.registerEntityUser; // get GraphQL schema; // now do whatever you would do with a GraphQL schemagraphqlschema, someAwesomeGraphqlQuery.then; // or (using express and express-graphql):; app.use'/graphql', graphqlHTTP; app.listen8080;
Using this example the library would create the following GraphQL schema:
input MongoFilterInput { field: String operator: String value: JSON} input MongoOrderInput { field: String order: String} type Mutation { addUser(user: UserInput): UserType updateUser(id: ID, user: UserInput): UserType removeUser(id: ID): UserType} type Query { users(filter: [MongoFilterInput], order: [MongoOrderInput], limit: Int, offset: Int): [UserType]} input UserInput { data: JSON friends: [UserInput] id: ID name: String} type UserType { data: JSON friends: [UserType] id: ID name: String}
Installation and Usage
Use npm
to install the package:
$ npm install graphql graphql-type-json mongodb @tenry/graphql-decorators @tenry/graphql-decorators-mongo
Now import the Manager
, the name
decorator along with the decorators from
@tenry/graphql-decorators
:
;; ; ;; ; // define entities here// register entities to the manager via manager.registerEntity(MyEntity); here // retrieve GraphQL schema;
License
@tenry/graphql-decorators-mongo is licensed under the MIT License.