# @mutix/graphql-phoenix

Latest version **0.1.25** (published 2020-07-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install @mutix/graphql-phoenix
pnpm add @mutix/graphql-phoenix
yarn add @mutix/graphql-phoenix
bun add @mutix/graphql-phoenix
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.25 |
| Published | 2020-07-20 |
| First published | 2020-05-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 8 |
| Unpacked size | 89.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Mutix |
| Maintainers | yutin1987 |

## Links

- npm: https://www.npmjs.com/package/@mutix/graphql-phoenix
- Repository: git@gitlab.com:mutix/lab/graphql-phoenix
- npm.io page: https://npm.io/package/@mutix/graphql-phoenix

## Dependencies (8)

- [pg](https://npm.io/package/pg.md) ^8.2.1
- [lodash](https://npm.io/package/lodash.md) ^4.17.15
- [jw25519](https://npm.io/package/jw25519.md) ^1.2.2
- [pg-cursor](https://npm.io/package/pg-cursor.md) ^2.2.1
- [dataloader](https://npm.io/package/dataloader.md) ^2.0.0
- [graphql-tag](https://npm.io/package/graphql-tag.md) ^2.10.3
- [apollo-server-errors](https://npm.io/package/apollo-server-errors.md) ^2.4.1
- [@graphql-toolkit/schema-merging](https://npm.io/package/@graphql-toolkit/schema-merging.md) ^0.10.5

## Recent versions

- 0.1.25 (latest) — 2020-07-20
- 0.1.24 — 2020-06-03
- 0.1.23 — 2020-06-02
- 0.1.22 — 2020-05-31
- 0.1.21 — 2020-05-31
- 0.1.20 — 2020-05-30
- 0.1.19 — 2020-05-27
- 0.1.18 — 2020-05-27
- 0.1.17 — 2020-05-27
- 0.1.16 — 2020-05-27
- 0.1.15 — 2020-05-25
- 0.1.13 — 2020-05-21
- 0.1.12 — 2020-05-21
- 0.1.11 — 2020-05-21
- 0.1.10 — 2020-05-21
- … 10 more at https://npm.io/package/@mutix/graphql-phoenix/versions

## README

# graphql-phoenix


功能: 
- 檢查 resolvers 必須要 type name (Author) 要有
- 檢查 `implements Node` 必須存在
- 檢查 `id` 欄位為必須
- 用 `hasTimestamp` 設定node是否需要有 timestamp 相關欄位
- 用 `hasOperator`
- 如果欄位是 `node type` 卻沒有寫 `resolver`

```js
export default makeNode({
  softDelete: false,
  hasOperator: false,
  hasTimestamp: false,
  typeDefs: gql`
    union Works = Book | Music

    type Author implements Node {
      id: GlobalID
      name: String
      avatar: Media
      works: [Works]
      numberOfFollowers: Int
      createdAt: DateTime
      createdBy: User
      updatedAt: DateTime
      updatedBy: User
    }

    enum AuthorOrderBy {
      createdAt
      updatedAt
      numberOfFollowers
    }

    input AuthorFilter {
      name: StringArgument
      avatar: GlobalIDArgument
      works: GlobalIDArgument
      numberOfFollowers: IntArgument
      createdAt: DateTimeArgument
      createdBy: GlobalIDArgument
      updatedAt: DateTimeArgument
      updatedBy: GlobalIDArgument
    }

    input AddAuthorInput {
      name: String
      avatar: Media
      works: [Works]
      numberOfFollowers: Int
    }
  
    input UpdateAuthorInput {
      id: GlobalID
      name: String
      avatar: Media
      works: [Works]
      numberOfFollowers: Int
    }
  `,
  resolvers: {
    Author: {
      id: (source) => source.id,
      avatar: (source, args, { models }) => models.load(source.avatar),
      works: (source, args, { models }) => models.loadMany(source.works),
      numberOfFollowers: () => {},
      createdAt: () => {},
      updatedAt: () => {},
      createdBy: (source, args, { models }) => models.load(source.createdBy),
      updatedBy: (source, args, { models }) => models.load(source.updatedBy),
    }
  }
})
```

- 檢查必須要 Query 要有
- 檢查必須要是 `extend type Query`

```js
export default makeQuery({
  typeDefs: gql`
    extend type Query {
      node(id: GlobalID!): Node
    }
  `,
  resolvers: {
    Query: {
      node: (source, args, { models }) => models.load(args.id),
    },
  },
});
```

- 繼承 makeQuery 的功能
- 檢查 `first` 與 `cursor` 為必須
- 檢查 `filter` 與 `orderBy` 為必須
- 檢查 `[name]Pagination` 大駝峰並加上 `Pagination`
- 檢查 `AuthorsPagination` 裡面的必要欄位


```js
export default makeQueryPagination({
  typeDefs: gql`
    extend type Query {
      authors(
        first: First
        cursor: Cursor
        filter: AuthorFilter
        orderBy: AuthorOrderBy
      ): AuthorsPagination
    }

    type AuthorsPagination {
      totalCount: Int
      nodes: [Author]
      pageInfo {
        next: Cursor
        previous: Cursor
      }
    }

    type AuthorFilter {
    }
  `,
  resolvers: {
    Query: {
      authors: (source, args, { models }) => {
        const { AuthorQuery } = models;
        if (args.cursor) {
          AuthorQuery.cursor(args.cursor);
        } else {
          AuthorQuery.filterQL(args.filter);
          AuthorQuery.sortByQL(args.sortBy);
        }
        AuthorQuery.first(args.first);
        AuthorQuery.where(...);
        return AuthorQuery;
      }
    },
    AuthorsPagination: {
      totalCount: (source) => {},
      nodes: (source) => source.find(),
      pageInfo: (source) => ,
    }
  },
});
```

- 檢查 `extend type Mutation`
- 檢查 `[name]MutationPayload`
- 檢查 `status` 必須
- 檢查必須要 Mutation 要有

```js
export default makeMutation({
  typeDefs: gql`
    extend type Mutation {
      addAuthor(input: AddAuthorInput): AddAuthorMutationPayload
    }

    type AddAuthorMutationPayload {
      status: ResponseStatus
      author: Author
    }
  `,
  resolvers: {
    Mutation: {
      addAuthor: () => {}
    },
  },
});
```

```js
export default makeMutation({
  typeDefs: gql`
    extend type Mutation {
      updateAuthor(input: UpdateAuthorInput): UpdateAuthorMutationPayload
    }

    type UpdateAuthorMutationPayload {
      status: ResponseStatus
      author: Author
    }
  `,
  resolvers: {
    Mutation: {
      updateAuthor: () => {}
    },
  },
});
```

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