Nestjs: создание резольвера из схемы GraphQL - PullRequest
0 голосов
/ 10 июля 2019

Я использую Prisma в Nestjs для создания сервера GraphQL.Я понимаю, что для каждого типа graphql мне нужно создать распознаватель и сгенерировать клиентский код, я должен снова создать запрос и мутацию.Можно ли создать преобразователь, запрос и мутацию для каждого типа?

Предположим, у меня есть тип учетной записи

type Account {
    id
    email
    uid
    nom
    prenom
}

Мне нужно создать преобразователь, запрос и мутацию.

Resolver

@Resolver('Account')
export class AccountResolver {

    constructor(private readonly prisma: PrismaService) { }

    @Query('accounts')
    async accounts(@Args('where') where: AccountWhereInput) {
        return await this.prisma.prisma.accounts({ where });
    }

    @Query('account')
    async account(@Args('where') where: AccountWhereUniqueInput) {
        return await this.prisma.prisma.account(where);
    }

    @Mutation('createAccount')
    async createAccount(@Args('data') data: AccountCreateInput) {
        return await this.prisma.prisma.createAccount(data);
    }

    @Mutation('updateAccount')
    async updateAccount(@Args('data') data: AccountUpdateInput, @Args('where') where: AccountWhereUniqueInput) {
        return await this.prisma.prisma.updateAccount({data, where});
    }

    @Mutation('deleteAccount')
    async deleteAccount(@Args('data') where: AccountWhereUniqueInput) {
        return await this.prisma.prisma.deleteAccount(where);
    }


}

Запрос и мутация

fragment AccountFragment on Account{
    id
    email
    uid
    nom
    prenom
}

query accounts($where: AccountWhereInput) {
  accounts(where: $where) {
    ...AccountFragment
  }
}

query account($where: AccountWhereUniqueInput!) {
  account(where: $where) {
    ...AccountFragment
  }
}

mutation createAccount($data: AccountCreateInput!) {
  createAccount(data: $data) {
    ...AccountFragment
  }
}

mutation updateAccount($where: AccountWhereUniqueInput!, $data: AccountUpdateInput!) {
  updateAccount(data: $data, where: $where) {
    ...AccountFragment
  }
}

Как генерировать эти коды в проекте с 80 типами.Любая помощь, пожалуйста

...