Skip to content

Supporting AND/OR/NOT filtering #1116

Answered by ilslv
twiclo asked this question in Q&A
Oct 20, 2022 · 1 comments · 3 replies
Discussion options

You must be logged in to vote

@twiclo GraphQL doesn't have native support for the operations, so your options are:

  1. Accept String! query and parse it on the backend. Shopify does this
{
  products(first: 5, query: "(title:Caramel Apple) OR (inventory_total:>500 inventory_total:<=1000)" ) {
    edges {
      node {
        id
        title
        createdAt
        totalInventory
      }
    }
  }
}
  1. Define your own GraphQL Input Object like in the example you've linked. Also I suggest taking a look at OpenCRUD:
#[derive(GraphQLInputObject)]
struct UserFilter {
    and: Option<Vec<Box<UserFilter>>>,
    or: Option<Vec<Box<UserFilter>>>,
    id: Option<i32>,
    name: Option<String>,
}
Full example
use std::env;

use

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@twiclo
Comment options

@twiclo
Comment options

@ilslv
Comment options

Answer selected by ilslv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants