Custom object return type & integration with graphql-scalars
#390
-
I have generated resolver which looks like this: @TypeGraphQL.InputType("EntityUpdateInput", {
isAbstract: true
})
export class EntityUpdateInput {
@TypeGraphQL.Field(_type => String, {
nullable: true
})
color?: string | undefined | null;
} But I wanna change return type to be import { HexColorCodeDefinition, HexColorCodeResolver} from 'graphql-scalars';
@TypeGraphQL.InputType("EntityUpdateInput", {
isAbstract: true
})
export class EntityUpdateInput {
@TypeGraphQL.Field(_type => HexColorType/*? where to get it ?*/, {
nullable: true
})
color?: string | undefined | null;
} I see there is possibility to create custom scalars, but it also says:
So maybe there is some recommended way or example how to use Also I checked graphql-custom-types as described here but |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
May be related to #43 |
Beta Was this translation helpful? Give feedback.
-
For the input type I did find a solution to omit specific fields from input using model someModel {
prop1 String
/// TypeGraphQL.omit(input: true)
prop2 String
@@id(fields: [prop1, prop2])
} and then extend from generated input type and add custom fields with scalars from export class GeneratedInput {
@TypeGraphQL.Field(_type => TypeGraphQL.Int, {
nullable: false
})
prop1!: number;
} custom: import { URLResolver } from 'graphql-scalars';
export class CustomInput extends GeneratedInput {
@TypeGraphQL.Field(_type => URLResolver, {
nullable: false
})
prop2: URL;
} But in cases for validation, we do not necessary need that because we can use |
Beta Was this translation helpful? Give feedback.
For the input type I did find a solution to omit specific fields from input using
TypeGraphQL.omit(input: true)
inschema.prisma
:and then extend from generated input type and add custom fields with scalars from
graphql-scalars
package:custom:
But in cases for val…