Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addFilterArg not being processed when using AND/OR/_operators #445

Open
seansabour opened this issue Oct 31, 2024 · 0 comments
Open

addFilterArg not being processed when using AND/OR/_operators #445

seansabour opened this issue Oct 31, 2024 · 0 comments

Comments

@seansabour
Copy link

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
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant