Reference type as a default value for a field #871
-
What is the recommended approach when setting a default value that is a reference type on a GraphQLObjectType field @ObjectType()
class Identifier {}
@ObjectType()
@InputType('IDInput')
export class ID {
@Field(() => Identifier)
id = new Identifier(); <----
} versus @ObjectType()
class Identifier {}
const defaultId = new Identifier();
@ObjectType()
@InputType('IDInput')
export class ID {
@Field(() => Identifier)
id = defaultId; <----
} TypeGraphQL does not seem to like the former, and would just like confirmation since the docs don't seem to prescribe an approach? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 8 replies
-
See if your answer isn't in this discussion already. Scott |
Beta Was this translation helpful? Give feedback.
-
Maybe you wanted to have a reference by using foreign key like |
Beta Was this translation helpful? Give feedback.
-
Second things - the default values.
Unfortunately, until #793 is resolved, dynamic default property initializers are used also as the GraphQL schema default values. |
Beta Was this translation helpful? Give feedback.
Second things - the default values.
There are two kinds:
Unfortunately, until #793 is resolved, dynamic default property initializers are used also as the GraphQL schema default values.
So you can't do something like on your snippet, you need to assign new values in your resolvers manually.