strapi icon indicating copy to clipboard operation
strapi copied to clipboard

GraphQl returns "Invalid parameter X" on any filter

Open ChamperNet opened this issue 2 years ago β€’ 40 comments

Bug report

Required System information

Node.js version: v18.17.1 YARN version: 1.22.19 Strapi version: 4.13.3 Database: SQLITE Operating system: Windows 10 Is your project Javascript or Typescript: JavaScript

Describe the bug

Unable to resolve graphql queries having "filter" property

Steps to reproduce the behavior

  1. Trying to get data form table products with this query:
#import "/apollo/fragments/shared/Technical.graphql"

query products(
  $locale: I18NLocaleCode
  $limit: Int!
  $start: Int!
  $brands: [String!]
  $categories: [String!]
  $slug: String
  $id: ID
  $ids: [ID]
  $notSlug: String
  $notId: ID
  $name: String
  $priceMinimal: Float
  $priceMaximal: Float
  $bestseller: Boolean
  $sale: Boolean
  $novelty: Boolean
) {
  products(
    locale: $locale
    pagination: { start: $start, limit: $limit }
    sort: "createdAt:desc"
    filters: {
      id: { eq: $id, in: $ids, ne: $notId }
      slug: { eq: $slug, ne: $notSlug }
      name: { containsi: $name }
      brand: { slug: { in: $brands } }
      categories: { slug: { in: $categories } }
      price: { between: [$priceMinimal, $priceMaximal] }
      active: { eq: true }
      technical: {
        novelty: { eq: $novelty }
        sale: { eq: $sale }
        bestseller: { eq: $bestseller }
      }
    }
  ) {
    data {
      id
      attributes {
        name
        slug
        status
        price
        priceSale
        gallery {
          data {
            attributes {
              formats
              url
              caption
              alternativeText
            }
          }
        }
        picture {
          data {
            attributes {
              formats
              url
              caption
              alternativeText
            }
          }
        }
        brand {
          data {
            attributes {
              name
              slug
            }
          }
        }
        categories {
          data {
            id
            attributes {
              name
              slug
            }
          }
        }
        technical {
          ...Technical
        }
      }
    }
    meta {
      pagination {
        total
        page
        pageCount
        pageSize
      }
    }
  }
}
  1. Sending params in my request:
{
    "limit": 12,
    "start": 0,
    "locale": "en",
    "priceMinimal": 0,
    "priceMaximal": 99999
} 
  1. Getting an error:
"message": "Invalid parameter id",

Expected behavior

Receiving an answer from the server which contains data[] with product information.

Additional context

Then I remove filter { } from the query - everything works fine.

schema.graphql contains the needed fields of course:

input ProductFiltersInput {
    active: BooleanFilterInput
    and: [ProductFiltersInput]
    announcement: StringFilterInput
    brand: BrandFiltersInput
    categories: CategoryFiltersInput
    createdAt: DateTimeFilterInput
    description: StringFilterInput
    features: ComponentSharedFeatureFiltersInput
    id: IDFilterInput
    locale: StringFilterInput
    localizations: ProductFiltersInput
    name: StringFilterInput
    not: ProductFiltersInput
    or: [ProductFiltersInput]
    price: FloatFilterInput
    priceSale: FloatFilterInput
    publishedAt: DateTimeFilterInput
    seo: ComponentSharedSeoFiltersInput
    sitemap_exclude: BooleanFilterInput
    slug: StringFilterInput
    status: StringFilterInput
    technical: ComponentSharedTechnicalFiltersInput
    updatedAt: DateTimeFilterInput
}

ChamperNet avatar Sep 10 '23 14:09 ChamperNet

+1

fuxianwei avatar Sep 11 '23 06:09 fuxianwei

I have managed that issue by downgrading Strapi version to 4.12.4. Same as the @strapi/plugin-graphql.

ChamperNet avatar Sep 11 '23 09:09 ChamperNet

I also have this issue with Strapi version 4.13.4 , I use $notIn filter and provide an empty array

mydesweb avatar Sep 12 '23 08:09 mydesweb

Encountering same issue with filters ($in) and sort

bl96 avatar Sep 12 '23 21:09 bl96

we are also having the same issue. We use 4.13.2. For us, it is a critical bug because pages, that are using the filtering, are not working now.

millsoft avatar Sep 13 '23 09:09 millsoft

Same!

thommorais avatar Sep 13 '23 15:09 thommorais

I guess it's the same bug as mine. https://github.com/strapi/strapi/issues/17945 Strapi needs to solve this

omerkim avatar Sep 14 '23 06:09 omerkim

Hello, everyone. I'm also experiencing issues with the filters. If I include an optional variable but don't send it to the query, it returns as an invalid value. However, in certain situations, such as during the initial rendering of a page, I don't want to apply all the filters. This used to work correctly before the update.

rafikmoreira avatar Sep 17 '23 00:09 rafikmoreira

@derrickmehaffy Are you guys going to solve this? The issue starts to be critical.

omerkim avatar Sep 21 '23 06:09 omerkim

I haven't been able to update Strapi to the latest version for several weeks now because of multiple critical bugs in the updates that break basic functionality such as this. I'm starting to get worried about the future of Strapi. Perhaps it would be a good idea to have some kind of intervention to get these issues fixed. Maybe a freeze on all new feature development until the most critical issues are resolved.

ChrisCrossCrash avatar Sep 21 '23 19:09 ChrisCrossCrash

Could you say something if you are working on it, so many people have this issue. It's a critical bug

galago avatar Sep 25 '23 04:09 galago

Hello !

Same issue here, all our filtered listing are broken with latest version (4.13.7). So we are stuck to 4.12.1 for several weeks.

I hope this critical issue to get solved in priority πŸ™

djacquemard avatar Sep 25 '23 15:09 djacquemard

Could you say something if you are working on it, so many people have this issue. It's a critical bug

Working on it right now. I don't think we will be able to make it into the release tomorrow (though I will try) but it should certainly be in next week's release!

innerdvations avatar Sep 26 '23 11:09 innerdvations

Escalated due to internal tid 4884

derrickmehaffy avatar Sep 26 '23 13:09 derrickmehaffy

Jumping it up to critical based on internal discussion

derrickmehaffy avatar Sep 26 '23 15:09 derrickmehaffy

The reason for this is that queries are being sent with optional variables being used in query params, for example, filters: { id: { eq: $id } } becomes filters: { id: { } } when id is not sent, which is not a valid query. Newer versions of Strapi throw errors on invalid queries to help catch security issues and other bugs in user code. But in this particular instance, params that are optionally not sent, I agree it should work as an exception.

We currently have two solutions, both of which should allow your queries to work again, we are just discussing which one is the best to go with. It would be great if anyone having this problem could test them to see if it resolves your issues.

  1. We can allow empty object params in only GraphQL, which would introduce a subtle difference between the rest API and graphql API
  2. We can allow them everywhere

We're currently deciding the best path and will try to release a fix as soon as we're sure it is the right one and will not introduce any other issues.

innerdvations avatar Sep 27 '23 10:09 innerdvations

The reason for this is that queries are being sent with optional variables being used in query params, for example, filters: { id: { eq: $id } } becomes filters: { id: { } } when id is not sent, which is not a valid query. Newer versions of Strapi throw errors on invalid queries to help catch security issues and other bugs in user code. But in this particular instance, params that are optionally not sent, I agree it should work as an exception.

We currently have two solutions, both of which should allow your queries to work again, we are just discussing which one is the best to go with. It would be great if anyone having this problem could test them to see if it resolves your issues.

  1. We can allow empty object params in only GraphQL, which would introduce a subtle difference between the rest API and graphql API
  2. We can allow them everywhere

We're currently deciding the best path and will try to release a fix as soon as we're sure it is the right one and will not introduce any other issues.

My opinion is allowing empty object params both in GraphQL and REST API would be the right solution.

Great that you finally paid attention to that bug. Hope you'll manage this ASAP.

ChamperNet avatar Sep 28 '23 07:09 ChamperNet

I don't know if you are aware of this, but the issue is still remaining with Boolean filters.

query getPrintrollMeasurement($id: ID!, $rubOffFilter: Boolean) {
  printrollMeasurement(id: $id) {
    data {
      id
      attributes {
        printrollctx(
          pagination: { pageSize: 20 }
          filters: { rubOff: { notNull: $rubOffFilter } }
        ) {
          id
          rubOff
        }
      }
    }
  }
}

In our case, we are using the notNull filter and the answer is still: "message": "Invalid parameter rubOffFilter", After we remove the filter, everything is working fine. We are still using v4.12.1 because in v4.14.4 pages, that are using this filter, are not working now.

Elpichichi avatar Oct 17 '23 09:10 Elpichichi

not just with booleans, I get the same with every other type. In my case String. Nothing has been solved

galago avatar Oct 17 '23 10:10 galago

I'll reopen this since it appears only the original test case was solved but there is still something to solve here.

It should be safe to allow nil values through the validator since they will be either sanitized out or accepted and ignored.

And as a side note, we're currently working on v5 and making this entire process much safer and simpler for everyone πŸš€

innerdvations avatar Oct 25 '23 12:10 innerdvations

hello +1 same issue this several Strapi Versions so we can't upgrade to strapi v13/14/15 so far... please kindly fix it

kevenkiloutou avatar Oct 27 '23 12:10 kevenkiloutou

This issue is also a blocker for us...when can we expect a fix?

Kricket avatar Oct 27 '23 12:10 Kricket

Hello, We are also waiting for this fix. Currently we are still blocked in v4.7 because of this bug fixed in v4.12 but we cannot upgrade to v4.12 because of this issue. Thanks in advance

alex-del-var avatar Oct 28 '23 18:10 alex-del-var

I should have time to work on a fix this week, once I have a PR available I will link it here to keep everyone updated.

innerdvations avatar Oct 30 '23 10:10 innerdvations

I should have time to work on a fix this week, once I have a PR available I will link it here to keep everyone updated.

Thank you. If you would have some troubles with managing this issue - give me a sign. I'll help if been able.

ChamperNet avatar Oct 30 '23 10:10 ChamperNet

#18647 should fix it. I need to confirm the issue is only present with components and not with relations or dynamic zones, and then we can merge :)

innerdvations avatar Nov 02 '23 16:11 innerdvations

I saw this was merged to main. Do we have an eta no when it will be fixed in a versioned release?

gregleeper avatar Nov 07 '23 16:11 gregleeper

I saw this was merged to main. Do we have an eta no when it will be fixed in a versioned release?

Hey, we have releases coming out every Wednesday, this fix should have been shipped in 4.15.2 (two days ago)

Convly avatar Nov 10 '23 07:11 Convly

It seems that problem still exist on 4.15.4

EverettQuebral avatar Dec 11 '23 20:12 EverettQuebral

I wonder why this error reoccurs over and over again. Many people affected by it too. :(

galago avatar Dec 12 '23 03:12 galago