ts-mongo-codegen
TypeScript icon, indicating that this package has built-in type declarations

0.1.8 • Public • Published

TypeScript Mongo Codegen

npm downloads Travis Coverage Status Dev Dependencies Known Vulnerabilities styled with prettier

This project generates types for a seamless integration between GraphQL and MongoDB. Generate All CRUD and Pagination Operations (10 minutes or less)

Usage

yarn add ts-mongo-codegen

./codegen.json

{
  "schema": "http://localhost:8082",
  "generates": {
    "./src/gql/types.ts": {
      "plugins": [
        "typescript",
        "typescript-operations",
        "typescript-resolvers",
        "ts-mongo-codegen",
      ]
    }
  }
}
 

./gql/books.schema

type Book @collection(name: "books") {
  id: ObjectId
  title: String
  author: String
}

./src/stores/mongo.ts

import { connect } from 'ts-mongo-codegen'
import { mongoFactory } from '../gql/types'
 
export async function mongoStore(url: string, name: string) {
  const db = (await connect(url)).db(name)
  const datastore = mongoFactory(db)
  // datastore.books is a mongo collection
  return datastore
}
 

Upcoming Release

  • Augment your schema with CRUD operations for your collections.
  • Generate a changelog to keep a running list of changes to a document
  • Generate subscriptions

Turns This

Example Schema

Into This

Into Tis

Package Sidebar

Install

npm i ts-mongo-codegen

Weekly Downloads

2

Version

0.1.8

License

MIT

Unpacked Size

280 kB

Total Files

29

Last publish

Collaborators

  • rphansen91