8000 addFilterArg does not work when using AND/OR/_operators · Issue #409 · graphql-compose/graphql-compose · GitHub
[go: up one dir, main page]

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 does not work when using AND/OR/_operators #409

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

addFilterArg does not work when using AND/OR/_operators #409

seansabour opened this issue Oct 30, 2024 · 0 comments

Comments

@seansabour
Copy link
seansabour commented Oct 30, 2024
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
0