prisma-graphql-type-decimal icon indicating copy to clipboard operation
prisma-graphql-type-decimal copied to clipboard

Unknown decorator

Open apss-pohl opened this issue 1 year ago • 3 comments

Hi,

i tried to use this scalar but it keeps failing with:

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

This is what i did in the gql config:

import { GraphQLDecimal } from 'prisma-graphql-type-decimal';
...
    resolvers: { Decimal: GraphQLDecimal },

And here is the model:

import { GraphQLDecimal } from 'prisma-graphql-type-decimal';
import { Decimal } from '@prisma/client/runtime';
...
    @Field(() => GraphQLDecimal, {nullable:false,defaultValue:0})
    sysVersion: Decimal;

Maybe i missed something but i am stuck right now. Any advice?

apss-pohl avatar Dec 15 '22 10:12 apss-pohl

https://www.google.com/search?q=Cannot+determine+a+GraphQL+output+type+for+the People are saying that is wrong import

Did you run prisma generate?

Actually this package is made for https://github.com/unlight/prisma-nestjs-graphql and in the end field should decorated like this:

  @Field(() => GraphQLDecimal)
  @Type(() => Object)
  @Transform(transformToDecimal)
  money: Decimal;

unlight avatar Dec 15 '22 20:12 unlight

https://www.google.com/search?q=Cannot+determine+a+GraphQL+output+type+for+the People are saying that is wrong import I reviewed most of the comments already but nothing was helpful

Did you run prisma generate? Yes

Actually this package is made for https://github.com/unlight/prisma-nestjs-graphql and in the end field should decorated like this:

  @Field(() => GraphQLDecimal)
  @Type(() => Object)
  @Transform(transformToDecimal)
  money: Decimal;

I am also using "prisma-nestjs-graphql" and i played a lot yesterday. I also had the Field Definition the way you describe it here but the issue persists. I was able to help myself by rewriting a scalar following your approach but using this code as template: https://github.com/nestjs/nest/blob/master/sample/23-graphql-code-first/src/common/scalars/date.scalar.ts Interestingly the description from the nestjs documentation did not work, too: https://docs.nestjs.com/graphql/scalars#create-a-custom-scalar

My scalar looks like this:

import { CustomScalar, Scalar } from '@nestjs/graphql';
import { Decimal } from '@prisma/client/runtime/index.js';
import { Kind, ValueNode } from 'graphql';

@Scalar('Decimal')
export class DecimalScalar implements CustomScalar<string, any> {
  description = 'An arbitrary-precision Decimal type';

  parseValue(value) {
    return new Decimal(value as Decimal.Value);
  }

  serialize = String;

  parseLiteral(ast: ValueNode) {
    if (ast.kind === Kind.INT || ast.kind === Kind.FLOAT || ast.kind === Kind.STRING) {
      return new Decimal(ast.value);
    }

    // eslint-disable-next-line unicorn/no-null
    return null;
  }
}

With:

  graphqlScalars_Decimal_name = "DecimalScalar"
  graphqlScalars_Decimal_specifier = "@m/common/scalars/decimal.scalar"

In schema.prisma.

And i had to add it to the submodule (also like in the example code repo mentioned above). Adding it to the app.module "GraphQLModule.forRootAsync" did not work, too. Maybe the documentation is outdated.

I also use the BigInt scalar from https://the-guild.dev/graphql/scalars, those are working out of the box. I dont know what they are doing differentely but for BigInt i only add

    graphqlScalars_BigInt_name = "GraphQLBigInt"
    graphqlScalars_BigInt_specifier = "graphql-scalars"

No need to add something inside the submodule or app module at all..

apss-pohl avatar Dec 16 '22 06:12 apss-pohl

Hi, i just retried, sorry for the long waiting time. It still fails. Here some relevant code parts.

This is what i did in prisma:

  /// @HideField({ input: true, output: false })
  wage         Decimal?  @db.Decimal(10, 2)

This is the generated output from "prisma-nestjs-graphql" after running prisma generate

import { GraphQLDecimal } from 'prisma-graphql-type-decimal';
import { Decimal } from '@prisma/client/runtime/library';

    @Field(() => GraphQLDecimal, {nullable:true})
    wage!: Decimal | null;

This is the error:

'Error: Cannot determine a GraphQL output type for the "wage". Make sure your class is decorated with an appropriate decorator.\n' +

Did i miss something?

apss-pohl avatar Jun 27 '23 12:06 apss-pohl