#Can't use `graphql-scalars` in the manner the documentation recommends

1 messages · Page 1 of 1 (latest)

strange nimbus
#

Hi,
Sorry, I posted this earlier to the wrong channel, hopefully here is a bit better.

Given the following code-first ObjectType:

import { BigIntResolver } from "graphql-scalars";

@ObjectType()
export class Asset {
  @Field(() => BigIntResolver, {
    nullable: false,
  })
  id!: bigint;
}

and the following in my app.module.ts file:

@Module({
  imports: [
    AssetModule,
    GraphQLModule.forRoot<ApolloDriverConfig>({
      path: "/",
      driver: ApolloDriver,
      autoSchemaFile: true,
      resolvers: { // <-- specifically here
        bigint: BigIntResolver,
      },
      introspection: true,
      debug: true,
    }),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

I get the following error: Error: Cannot determine a GraphQL output type for the "id". Make sure your class is decorated with an appropriate decorator.

What am I missing to ensure this works? This is the approach as laid out in the docs but I feel its missing an important detail to get this to work that I can't figure out myself.

Thank you!

digital mural
#

Did you try with

import { BigInt } from "graphql-scalars";

@ObjectType()
export class Asset {
  @Field(() => BigInt, {
    nullable: false,
  })
  id!: bigint;
}

and

import { BigIntResolver, BigInt } from "graphql-scalars";
...
    GraphQLModule.forRoot<ApolloDriverConfig>({
      path: "/",
      driver: ApolloDriver,
      autoSchemaFile: true,
      resolvers: {
        BigInt: BigIntResolver,
      },
      introspection: true,
      debug: true,
    }),

?

#

The Field decorator takes a type as argument, not resolver.

strange nimbus
#

I did just now and got the same error

#
Error: Cannot determine a GraphQL output type for the "id". Make sure your class is decorated with an appropriate decorator.
    at OutputTypeFactory.create (/Users/lukeshiels/Developer/structure/peripheral-services/node/microservices/assetgw/node_modules/@nestjs/graphql/dist/schema-builder/factories/output-type.factory.js:19:23)
    at /Users/lukeshiels/Developer/structure/peripheral-services/node/microservices/assetgw/node_modules/@nestjs/graphql/dist/schema-builder/factories/object-type-definition.factory.js:81:53
    at Array.forEach (<anonymous>)
    at /Users/lukeshiels/Developer/structure/peripheral-services/node/microservices/assetgw/node_modules/@nestjs/graphql/dist/schema-builder/factories/object-type-definition.factory.js:80:24
    at resolveObjMapThunk (/Users/lukeshiels/Developer/structure/peripheral-services/node/microservices/assetgw/node_modules/graphql/type/definition.js:504:40)
    at defineFieldMap (/Users/lukeshiels/Developer/structure/peripheral-services/node/microservices/assetgw/node_modules/graphql/type/definition.js:766:20)
    at GraphQLObjectType._fields (/Users/lukeshiels/Developer/structure/peripheral-services/node/microservices/assetgw/node_modules/graphql/type/definition.js:691:26)
    at GraphQLObjectType.getFields (/Users/lukeshiels/Developer/structure/peripheral-services/node/microservices/assetgw/node_modules/graphql/type/definition.js:710:27)
    at collectReferencedTypes (/Users/lukeshiels/Developer/structure/peripheral-services/node/microservices/assetgw/node_modules/graphql/type/schema.js:387:51)
    at new GraphQLSchema (/Users/lukeshiels/Developer/structure/peripheral-services/node/microservices/assetgw/node_modules/graphql/type/schema.js:174:9)
#

using:

@ObjectType()
export class EquivalentAsset {
  // @Field(() => BigIntResolver, {
  @Field(() => BigInt)
  id!: bigint;
}
digital mural
#

Just tried locally and the Resolvers were correct:

import { BigIntResolver, CountryCodeResolver } from 'graphql-scalars';

@ObjectType()
export class Status {
  @Field(() => BigIntResolver)
  uptimeMs: bigint

  @Field(() => CountryCodeResolver)
  code: "CZ" | "UK"
}

no other modification was necessary.

twin geode
#

I do this the following way:

const scalars = [
    BigIntResolver,
    CountryCodeResolver,
]

@Module({
    providers: scalars,
    exports: scalars,
})
export class ScalarsModule {}

Then import ScalarsModule in app.module. Not sure if that's the recommended way but it also seems to work fine.

digital mural