Hey, guys!
I have a problem with graphql
I created default crud for an entity in the module and wanna add a custom filter for this
I know how to do this via resolver (then i ll have an additional query), but I need to build it inside the default crud
Maybe there is some class that I can extend and add there my service for this custom filter?
#Graphql customisation of default crud
9 messages · Page 1 of 1 (latest)
@misty granite - Have a look at this library (rather set of libraries). https://github.com/tripss/nestjs-query
thank u, Scott, I use this library in my project
I use it inside module like nestjs-query-typeorm and via resolvers create default crud for entity, but I need to extend the default class with new filter (and add service for this filter too)
I can create it as an additional query, but I don't need it ('cause there will be lots of filters)
imports: [NestjsQueryTypeOrmModule.forFeature([Entity])],
resolvers: [
{
EntityClass: Entity,
DTOClass: EntityDto,
create: { disabled: true },
update: { disabled: true },
delete: { disabled: true },
},
],
} as NestjsQueryGraphqlModuleFeatureOpts),
@Resolver(() => EntityDto)
export class ExtendedResolver extends CRUDResolver(EntityDto) {
constructor(
@InjectQueryService(EntityDto)
readonly service: QueryService<EntityDto>,
private readonly serviceE: EntityService,
) {
super(service);
}
async queryMany(
query: QueryType<EntityDto, PagingStrategies>,
authorizeFilter?: Filter<EntityDto> | ExtendedDtoFilter,
resolveInfo?: GraphQLResolveInfoResult<EntityDto, EntityDto>,
opts?: { pagingStrategy?: PagingStrategies },
): Promise<any> {
//custom logic
return super.queryMany(query, authorizeFilter, resolveInfo);
}
}
So, I'm no where certain as to why you need this custom filter. What are you trying to achieve?
I wanna get something I get with additional query
@Query(() => EntityDto)
async queryManyEntities(
@Args('filter', { type: () => ExtendedDtoFilter })
filter: ExtendedDtoFilter,
): Promise<any> {
if (
filter.myCustomStructure &&
filter.myCustomStructure.collection
) {
return this.entityService.customMethod(filter.myCustomStructure);
}
return super.queryMany({ filter });
}
in this case, I will have custom filter inside apollo sandbox, where I can call it like this
{
"filter": {
"myCustomStructure": {
"collection": "",
"attributes": [
{
"name": "",
"values": [""]
}
]
}
}
}
Before I go down this rabbit hole with you, what is missing from the current filtering methodology of nestjs-query that requires you to do this?
I can't give the custom structure for my custom filter via current filtering methodology of nestjs-query
That doesn't really answer my question. You can basically filter for anything AFAIK with the built-in solution. I see the filter above, but it really doesn't explain the type of filter you are looking for. Can you explain in more detail?