graphql-compose-mongoose icon indicating copy to clipboard operation
graphql-compose-mongoose copied to clipboard

addFilterArg not being processed when using AND/OR/_operators

Open seansabour opened this issue 1 year ago • 1 comments

DbinstanceTC.mongooseResolvers
    .pagination({ suffix: "Extended" })
    .addArgs({
      filterNodeInfo: DNSCNameTC.mongooseResolvers
        .pagination()
        .getArg("filter"),
    })
    .addArgs({
      filterEnvironmentLink: EnvironmentTC.mongooseResolvers
        .pagination()
        .getArg("filter"),
    })
    .addFilterArg({
      name: "isDatabaseEmpty",
      type: "Boolean",
      description: "Filter by empty or non-empty databases array",
      query: (rawQuery, value) => {
        if (value !== undefined) {
          rawQuery.databases = value ? { $size: 0 } : { $not: { $size: 0 } };
        }
      },
    })
    .withMiddlewares([authorizeGraphQL([Roles.Admin, Roles.Inventory])])
    .wrapResolve(processChildFilters)
    .wrapResolve(addEnvFilters),

This works fine, when running a query like this:

{
  dbinstancePagination(
    page: 1
    perPage: 50
    filter: {isDatabaseEmpty: true}
  ) {
    items {
      _id
      name
      tenantCount
      databases {
        _id
        name
        type
      }
    }
    pageInfo {
      currentPage
      perPage
      pageCount
      itemCount
      hasNextPage
      hasPreviousPage
    }
  }
}

but when running this it returns non-empty databases:

{
  dbinstancePagination(
    page: 1
    perPage: 50
    filter: {AND: [{isDatabaseEmpty: true}, {name: "mysql" }]}
  ) {
    items {
      _id
      name
      tenantCount
      databases {
        _id
        name
        type
      }
    }
    pageInfo {
      currentPage
      perPage
      pageCount
      itemCount
      hasNextPage
      hasPreviousPage
    }
  }
}

seansabour avatar Oct 31 '24 00:10 seansabour

Having the same issue when trying to query with addRelation filter function with findMany resolver and custom filterArgs.

lalilaloe avatar Jan 10 '25 05:01 lalilaloe