9 Star 12 Fork 1

Notadd / magnus

Create your Gitee Account
Explore and code with more than 8 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
contribute
Sync branch
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

根据ts自动生成`.graphql`和`.proto`配置文件

install

npm install -g @notadd/magnus

add magnus.json

{
	"inputs": [ "demo/src/app.resolver.ts" ],
	"output": "demo/src/magnus",
	"temp": "demo/src/magnus/temp",
    "debug": true,
    "copyTo": []
}

run magnus

// 开发模式
magnus
// 生产模式 自动复制生成的配置文件到指定的文件夹
magnus --prod

orm

@Magnus({
    entities: [
        User,Post
    ],
})
export class Controller<T> extends MagnusBase<T> {
    // 自动生成 getUser,getPost
    get repository() {
        return getRepository<T>(this.tablename);
    }

    @Query()
    async get(entity: T): Promise<T> {
        return this.repository.findOne({
            where: entity,
        });
    }
    // 自动生成 addUser,addPost
    @Mutation()
    async add(entity: Partial<T>): Promise<T> {
        return {
            id: 1,
        } as any;
    }

    // 自动生成 insertUser,insertPost
    @Mutation()
    async insert(entity: T): Promise<InsertResult<T>> {
        return {
            id: 1,
        } as any;
    }
}

覆盖orm

@Magnus()
export class Controller2 extends MagnusBase<User> {
    tablename: string = 'User';
    /**
     * 覆盖Controller中的getUser,单独处理
     **/
    @Query()
    getUser(): User {
        return {
            id: 1,
        };
    }
}

使用

import { createRunner } from '@notadd/magnus-core';
import { Controller, Controller2 } from './index';
import { join } from 'path';
import { Query } from '../magnus/magnus'
import { parse } from '@notadd/magnus-graphql';
const map = require(join(__dirname, '..', 'magnus/magnus.metadata.json'));
const context = require(join(__dirname, '..', 'magnus/magnus.server.json'));
const run = createRunner(map, context, {
    Controller,
    Controller2,
});
const query: Query = run.query;
async function run2() {
    const res1 = await run(`{
        getUser{
            id
        }
    }`);
    const res = await query.getUser(`{
        id
    }`);
}
run2();

About

根据ts自动生成`.graphql`和`.proto`配置文件 expand collapse
TypeScript and 4 more languages
Cancel

Releases

No release

magnus

Contributors

All

Activities

Load More
can not load any more
TypeScript
1
https://gitee.com/notadd/magnus.git
git@gitee.com:notadd/magnus.git
notadd
magnus
magnus
master

Search