#Handling Partial Errors in NestJS GraphQL Resolver

1 messages · Page 1 of 1 (latest)

signal axle
#

Hi everyone,
I'm working on a NestJS GraphQL resolver and I need some help. I want to return a list of OrganisationType objects, but I also want to include errors in the response if some identifiers don't exist. Here's my current resolver method:

@ResolveField('getList', () => OrganisationType])
async getList(
@Args('where', { type: () => OrganisationTypeGetListInputType })
where:OrganisationTypeGetListInputType,
): Promise<OrganisationType[]> {
return this.dataProductDataloader.dataloaderByDocId.loadMany(where?.identifiers);
}

I know the GraphQL protocol allows for errors, but I don't want to explicitly add them to the schema. How can I modify this method to return both the list of OrganisationType and any errors encountered during the lookup? Thanks in advance!

signal axle
#

Maybe It's possible to add errors through the context. or using another driver. I
I would like to have this kind of response.

{
"data": {"..."},
"errors": [
{
"message": "ID 111 doesn't exist",
"locations": [
{
"line": 3,
"column": 5
}
]
}
]
}