nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
67.68k stars 7.63k forks source link

Cannot determine a GraphQL output type for the "query or mutation name". #5199

Closed marticrespi closed 4 years ago

marticrespi commented 4 years ago

Bug Report

Cannot determine a GraphQL output type for the "createProfile". Make sure your class is decorated with an appropriate decorator,

Current behavior

I have defined my code as show above, I do a nest build and its generating ok the dist folder, but when I try nest start

[Nest] 29368   - 2020-08-04 11:51:38 AM   [NestFactory] Starting Nest application...
[Nest] 29368   - 2020-08-04 11:51:38 AM   [InstanceLoader] AppModule dependencies initialized +66ms
[Nest] 29368   - 2020-08-04 11:51:38 AM   [InstanceLoader] GraphqlModule dependencies initialized +5ms
[Nest] 29368   - 2020-08-04 11:51:38 AM   [InstanceLoader] GraphQLSchemaBuilderModule dependencies initialized +9ms
[Nest] 29368   - 2020-08-04 11:51:38 AM   [InstanceLoader] GraphQLModule dependencies initialized +28ms
(node:29368) UnhandledPromiseRejectionWarning: Error: Cannot determine a GraphQL output type for the "createProfile". Make sure your class is decorated with an appropriate decorator.
    at OutputTypeFactory.create (D:\nestjs-social\node_modules\@nestjs\graphql\dist\schema-builder\factories\output-type.factory.js:19:23)
    at handlers.filter.forEach (D:\nestjs-social\node_modules\@nestjs\graphql\dist\schema-builder\factories\root-type.factory.js:36:49)
    at Array.forEach (<anonymous>)
    at RootTypeFactory.generateFields (D:\nestjs-social\node_modules\@nestjs\graphql\dist\schema-builder\factories\root-type.factory.js:34:14)
    at fieldsFactory (D:\nestjs-social\node_modules\@nestjs\graphql\dist\schema-builder\factories\root-type.factory.js:18:101)
    at RootTypeFactory.create (D:\nestjs-social\node_modules\@nestjs\graphql\dist\schema-builder\factories\root-type.factory.js:27:21)
    at MutationTypeFactory.create (D:\nestjs-social\node_modules\@nestjs\graphql\dist\schema-builder\factories\mutation-type.factory.js:15:37)
    at GraphQLSchemaFactory.<anonymous> (D:\nestjs-social\node_modules\@nestjs\graphql\dist\schema-builder\graphql-schema.factory.js:41:52)
    at Generator.next (<anonymous>)
    at D:\nestjs-social\node_modules\tslib\tslib.js:114:75
(node:29368) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:29368) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Input Code

My sumarized model

import * as TypeGraphQL from "type-graphql";
import { Asset } from "../models/Asset";
import { SocialAccount } from "../models/SocialAccount";

@TypeGraphQL.ObjectType({
  isAbstract: true,
  description: undefined,
})
export class Profile {
  @TypeGraphQL.Field(_type => TypeGraphQL.Int, {
    nullable: false,
    description: undefined,
  })
  id!: number;

  @TypeGraphQL.Field(_type => String, {
    nullable: false,
    description: undefined,
  })
  status!: string;

My resolver

import { FindManyProfileArgs, ProfileWhereUniqueInput, ProfileCreateInput, ProfileUpdateInput } from './../../args/args-index';
import { Profile } from './../../models/_index';
import { ProfileService } from '../../services/services-index';

import { Resolver, Args, Query, Mutation } from "@nestjs/graphql";

@Resolver(of => Profile)
export class ProfileResolver {
  constructor(
     private readonly profileService: ProfileService,
  ) {}

  @Query(returns => [Profile], {name: 'profiles'})
  async profiles(@Args() findMany: FindManyProfileArgs): Promise<Profile[]> {
    return await this.profileService.getProfiles(findMany);
  }

  @Query(returns => Profile, {name: 'profile'})
  async profile(@Args('where') where: ProfileWhereUniqueInput) {
    return await this.profileService.getProfile(where);
  }

  @Mutation(returns => Profile)
  async createProfile(@Args('data') data: ProfileCreateInput) {
    return this.profileService.createProfile(data);
  }

  @Mutation(returns => Profile)
  async updateProfile(@Args('data') data: ProfileUpdateInput, @Args('where') where: ProfileWhereUniqueInput) {
    return this.profileService.updateProfile(data, where);
  }

  @Mutation(returns => Profile)
  async deleteProfile(@Args('where') where: ProfileWhereUniqueInput) {
    return this.profileService.deleteProfile(where);
  }  
}

My service

import { FindManyProfileArgs, ProfileWhereUniqueInput, ProfileCreateInput, ProfileUpdateInput } from './../../args/args-index';
import { Injectable, OnModuleInit, OnModuleDestroy } from '@nestjs/common';
import { PrismaClient, Profile } from '@prisma/client';

@Injectable()
export class ProfileService extends PrismaClient
  implements OnModuleInit, OnModuleDestroy {
  constructor() {
    super();
  }

  async onModuleInit() {
    await this.connect();
  }

  async onModuleDestroy() {
    await this.disconnect();
  }

  async getProfiles(findMany: FindManyProfileArgs): Promise<Profile[]> {
    return this.profile.findMany(findMany);    
  }

  async getProfile(where: ProfileWhereUniqueInput): Promise<Profile> {
    return this.profile.findOne({ 'where': where});
  }

    // Mutations
  async createProfile(data: ProfileCreateInput): Promise<Profile> {
    data.createdAt = new Date();
    data.updatedAt = new Date();
    return await this.profile.create({data: data});
  }

  async updateProfile(data: ProfileUpdateInput, where: ProfileWhereUniqueInput): Promise<Profile> {
    data.updatedAt = new Date();
    return await this.profile.update({data: data, where: where});
  }

  async deleteProfile(where: ProfileWhereUniqueInput): Promise<Profile> {
    return await this.profile.delete({'where': where});
  }

}

Expected behavior

I started a few months ago a nestjs project with prisma2 and type-graphql was using the decorators in another way using the desired properties one by one, using the import like this import { Field, Int, ObjectType } from "type-graphql"; instead of import * as TypeGraphQL from "type-graphql"; but I don't know if this library is generating the error, because I'm trying the import one by one and throws the same error... And I have tried to remove the mutations and it throws same error on queries.. Its a bug? Or what I'm doing wrong?

Can someone help me?

Many thanks.

import { Field, Int, ObjectType } from "type-graphql";
import { ItemBillingAccount, Invoice, Partner } from "../models/_models-index";

@ObjectType({
  isAbstract: true,
  description: undefined,
})
export class BillingAccount {
  @Field(_type => String, {
    nullable: false,
    description: undefined,
  })
  businessName!: string;

Environment


Nest version: 7.4.2

For Tooling issues:
- Node version: 10.19.0
- Platform:  Windows

Others:
    "type-graphql": "1.0.0-rc.3",
    "typegraphql-prisma": "0.4.1",
marticrespi commented 4 years ago

Solved, I have to replace on all my args, inputs, models and so on generated by type-graphql library from

import * as TypeGraphQL from "type-graphql";

to

import * as TypeGraphQL from "@nestjs/graphql";