prisma-nestjs-graphql icon indicating copy to clipboard operation
prisma-nestjs-graphql copied to clipboard

can't use auto generated types in graphql resolvers

Open esmaeilzadeh opened this issue 2 years ago • 8 comments

Hi im using prisma with nestjs and graphql, I am trying to use prisma-nestjs-graphql to auto generate the graphql type and use it inside my resolver:

import { PrismaService } from 'nestjs-prisma';
import {
  Resolver,
  Query,
  Parent,
  Args,
  ResolveField,
  Subscription,
  Mutation,
} from '@nestjs/graphql';
import { findManyCursorConnection } from '@devoxa/prisma-relay-cursor-connection';
import { PubSub } from 'graphql-subscriptions';
import { UseGuards } from '@nestjs/common';
import { PaginationArgs } from '../common/pagination/pagination.args';
import { UserEntity } from '../common/decorators/user.decorator';
import { User } from '../users/models/user.model';
import { GqlAuthGuard } from '../auth/gql-auth.guard';
import { PostIdArgs } from './args/post-id.args';
import { UserIdArgs } from './args/user-id.args';
import { Post } from './models/post.model';
import { PostConnection } from './models/post-connection.model';
import { PostOrder } from './dto/post-order.input';
import { CreatePostInput } from './dto/createPost.input';
import {FindManyPostArgs, PostWhereInput} from "../generated/post";
@Query(() => [Post])
async posts(
  @Args({ name: 'where', nullable: true, type: () => PostWhereInput})
  where?:PostWhereInput
): Promise<Post[]> {
      return this.prisma.post.findMany({
        where:where
      })
}

but I faced this error:

Projects/webnegah/backend_base/dist/generated/user/input/user-where.js:8
        return UserWhereInput;
        ^
ReferenceError: Cannot access 'UserWhereInput' before initialization
    at Object.get [as UserWhereInput] (/home/mohammadreza/Projects/webnegah/backend_base/dist/generated/user/input/user-where.js:8:9)
    at Object.<anonymous> (/home/mohammadreza/Projects/webnegah/backend_base/dist/generated/user/input/user-nullable-relation-filter.js:28:51)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Function.Module._load (node:internal/modules/cjs/loader:960:12)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at Object.<anonymous> (/home/mohammadreza/Projects/webnegah/backend_base/dist/generated/post/input/post-where.js:16:37)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)

do you have any idea how to solve this issue?

esmaeilzadeh avatar Aug 07 '23 12:08 esmaeilzadeh