#Graphql customisation of default crud

9 messages · Page 1 of 1 (latest)

misty granite
#

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?

torpid pond
misty granite
misty granite
#
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);
  }
}
torpid pond
#

So, I'm no where certain as to why you need this custom filter. What are you trying to achieve?

misty granite
# torpid pond So, I'm no where certain as to why you need this custom filter. What are you try...

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": [""]
        }
      ]
    }
  }
}

torpid pond
#

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?

misty granite
#

I can't give the custom structure for my custom filter via current filtering methodology of nestjs-query

torpid pond
#

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?