'How to handle nullable reference in graphql
Am new to grqphql/mongodb, I have a question which I didn't find a clear answer on the net, which is having the following schema (Nestjs/Graphql):
@ObjectType('CustomerServiceDetails')
@InputType('CustomerServiceDetailsInput')
@Schema({ timestamps: true })
export class CustomerServiceDetails {
@Field(() => UpstreamProvider, { nullable: true })
@Prop({
type: mongoose.Schema.Types.ObjectId,
ref: 'UpstreamProvider',
})
upstreamProvider?: UpstreamProvider;
@Field(() => [ItpcConnection], { nullable: true })
@Prop([{ type: mongoose.Schema.Types.ObjectId, ref: 'ItpcConnection' }])
itpcConnections?: ItpcConnection;
}
Both of the properties are nullable which is working find during insert and update, however it returns error on Query "Cannot return null for non-nullable field Upstream Provider. name.", my question is how to handle nullable foreign keys in grqphql.
{
customerServices {
_id
group
customerServices {
customerServiceDetails {
upstreamProvider {
name
}
itpcConnections {
name
}
}
}
}
}
thanks
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
