# @notadd/ast.ts-graphql

> > TODO: description

Latest version **3.2.0** (published 2021-06-03) · ISC license · 0 weekly downloads

## Install

```sh
npm install @notadd/ast.ts-graphql
pnpm add @notadd/ast.ts-graphql
yarn add @notadd/ast.ts-graphql
bun add @notadd/ast.ts-graphql
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.2.0 |
| Published | 2021-06-03 |
| First published | 2020-06-02 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 271.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | imeepos |
| Maintainers | tian-hun, lei3265018, zuohuadong, imeepos2 |

## Links

- npm: https://www.npmjs.com/package/@notadd/ast.ts-graphql
- Homepage: https://github.com/meepobrother/nger-ast#readme
- Issues: https://github.com/meepobrother/nger-ast/issues
- npm.io page: https://npm.io/package/@notadd/ast.ts-graphql

## Dependencies (4)

- [@notadd/ast.tsc](https://npm.io/package/@notadd/ast.tsc.md) ^3.2.0
- [@notadd/ast.core](https://npm.io/package/@notadd/ast.core.md) ^3.2.0
- [@notadd/ast.proto](https://npm.io/package/@notadd/ast.proto.md) ^3.2.0
- [@notadd/ast.graphql](https://npm.io/package/@notadd/ast.graphql.md) ^3.2.0

## Recent versions

- 3.2.0 (latest) — 2021-06-03
- 3.1.1 — 2020-06-02

## README

# `ts-graphql`

> 根据ts代码自动生成graphql文件

## Usage

```ts
import { Query, Resolver, ResolveProperty } from '@nestjs/graphql';
import { Department } from './entities/Department.entity'
import { User } from './entities/User.entity'
import { IDepartmen, UserDepartment } from './types';
@Resolver('IDepartmen')
export class DemoUnion {
    @ResolveProperty()
    __resolveType(obj: IDepartmen) {
        if (obj instanceof User) {
            return `User`;
        }
        if (obj instanceof Department) {
            return `Department`
        }
        if (obj instanceof UserDepartment) {
            return `UserDepartment`
        }
    }
}
@Resolver()
export class DemoGraphql {
    id: number = 0;
    /**
     * get department
     * @param {User} user 
     */
    @Query()
    async getDepartment(): Promise<IDepartmen> {
        this.id += 1;
        const department = new Department()
        department.title = `title`;
        const user = new User();
        user.password = `password`;
        user.username = `username`;
        if (this.id % 3 === 0) {
            const userDepartment = new UserDepartment();
            userDepartment.user = user;
            userDepartment.department = department;
            return userDepartment;
        }
        if (this.id % 2 === 0) {
            return department;
        }
        return user;
    }
}
```
生成

```graphql
scalar Date

scalar Json

type Department {
  """部门id"""
  id: String!
  """部门名称"""
  title: String!
}

type User {
  """用户uid"""
  uid: String!
  """用户名"""
  username: String!
  """密码"""
  password: String!
}

type UserDepartment {
  user: User!
  department: Department!
}

union IDepartmen = Department | User | UserDepartment

type Query {
  """get department"""
  getDepartment: IDepartmen!
}

```


```graphql
{
	getDepartment{
    ...on User{
      username,
      password
    },
    ...on Department{
      title
    },
    ...on UserDepartment{
      user{
        username,
        password
      }
      department{
        title
      }
    }
  }
}
```

---
_Source: https://npm.io/package/@notadd/ast.ts-graphql · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
