menu
announcement

Spectrum is now read-only. Learn more about the decision in our official announcement.

Strapi

Help, talk and share your thoughts about Strapi.

Channels
Team

AND filter for the Graphql endpoint

November 15, 2019 at 3:36pm

AND filter for the Graphql endpoint

November 15, 2019 at 3:36pm (Edited 3 years ago)
Hey, i'm relatively new and sadly the filtering for the graphql is pretty badly documented. Is there a way to do an AND filter?
My query, which only filters OR:
query GET_CLIENT_INVENTORIES($clientId: ID!, $productId: ID!) {
inventories(
where: { client: { id: $clientId }, product: { id: $productId } }
) {
id
amount
product {
id
productFormat {
id
name
}
productName {
id
name
}
}
}
}

November 18, 2019 at 4:46pm
Hello! sadly you didn't find documentation to do that because it's not possible for not. I suggest you to create your own resolver to match this need. Here is the docs https://strapi.io/documentation/3.0.0-beta.x/plugins/graphql.html#customise-the-graphql-schema Then you will have to use custom queries to achieve your AND query. We have a work to do on this part. Thank you for this feedback.

November 21, 2019 at 8:03am
hello , in the same subject i have a problem when putting the resolver and i dont understand why that ?

November 25, 2019 at 11:43am
Hum, I'm not sure to understand what you mean. Can you precise please.

November 26, 2019 at 8:46am
how i can filter only by nom in parameter like that and how can add this parameter in the query graphql

November 28, 2019 at 1:08pm
When you create your own query, you have to specify this param in the query definition.
query: `
productsByCategories(nom: String): [Product]!
`,
Will be something like this.

November 29, 2019 at 9:02am
the params attribute in the function should be obligation a ID ?? because it seeing nom like a ID not string

December 5, 2019 at 1:33pm
Can you show me your query definition please.