0.1.25 • Published 5 years ago
@mutix/graphql-phoenix v0.1.25
graphql-phoenix
功能:
- 檢查 resolvers 必須要 type name (Author) 要有
- 檢查 implements Node必須存在
- 檢查 id欄位為必須
- 用 hasTimestamp設定node是否需要有 timestamp 相關欄位
- 用 hasOperator
- 如果欄位是 node type卻沒有寫resolver
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
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裡面的必要欄位
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 要有
export default makeMutation({
  typeDefs: gql`
    extend type Mutation {
      addAuthor(input: AddAuthorInput): AddAuthorMutationPayload
    }
    type AddAuthorMutationPayload {
      status: ResponseStatus
      author: Author
    }
  `,
  resolvers: {
    Mutation: {
      addAuthor: () => {}
    },
  },
});export default makeMutation({
  typeDefs: gql`
    extend type Mutation {
      updateAuthor(input: UpdateAuthorInput): UpdateAuthorMutationPayload
    }
    type UpdateAuthorMutationPayload {
      status: ResponseStatus
      author: Author
    }
  `,
  resolvers: {
    Mutation: {
      updateAuthor: () => {}
    },
  },
});0.1.25
5 years ago
0.1.24
5 years ago
0.1.23
5 years ago
0.1.21
5 years ago
0.1.22
5 years ago
0.1.20
5 years ago
0.1.19
5 years ago
0.1.18
5 years ago
0.1.17
5 years ago
0.1.16
5 years ago
0.1.15
5 years ago
0.1.10
5 years ago
0.1.11
5 years ago
0.1.12
5 years ago
0.1.13
5 years ago
0.1.9
5 years ago
0.1.8
5 years ago
0.1.7
5 years ago
0.1.6
5 years ago
0.1.5
5 years ago
0.1.4
5 years ago
0.1.3
5 years ago
0.1.2
5 years ago
0.1.1
5 years ago
0.1.0
5 years ago