Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unknown decorator #6

Open
apss-pohl opened this issue Dec 15, 2022 · 3 comments
Open

Unknown decorator #6

apss-pohl opened this issue Dec 15, 2022 · 3 comments

Comments

@apss-pohl
Copy link

apss-pohl commented Dec 15, 2022

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?

@unlight
Copy link
Owner

unlight commented Dec 15, 2022

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;

@apss-pohl
Copy link
Author

apss-pohl commented Dec 16, 2022

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
Copy link
Author

apss-pohl commented Jun 27, 2023

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants