Graphweaver Docs
  • Home
  • Github
Get Started πŸš€
🍲

Filters and Operators

  • Introduction
  • How are Filters Generated?
  • Filter Examples
  • Filtering by ID
  • Filtering by String
  • Filtering by Number
  • Filtering by Date
  • Filter Operators
  • ID Type
  • String Type
  • Number, Date, ISOString Types
  • Conclusion

Introduction

Graphweaver provides powerful GraphQL filtering capabilities that allow you to refine your data queries and retrieve specific information from the API.

Filtering is a crucial aspect of data querying as it allows you to selectively retrieve specific subsets of data that meet certain criteria.

By applying filters, you can narrow down your search results and obtain only the relevant information you need.

Filtering is beneficial in various scenarios, such as retrieving specific records based on their attributes (e.g., filtering users by their age or products by their price range) or searching for data within a specific time frame (e.g., filtering events by their date).

Filters help streamline data retrieval, enhance efficiency, and ensure that you obtain precisely the data you require for analysis, processing, or presentation. In this article, we will delve into how Graphweaver generates filters and explore the operators associated with each filter type. Understanding these operators will allow you to effectively filter and narrow down your data search within Graphweaver.

How are Filters Generated?

When using Graphweaver, filters are automatically generated based on the fields in your GraphQL entities.

Graphweaver automatically analyzes the field types and generates corresponding filter inputs.

These filters enable you to specify conditions and criteria to retrieve the desired data subset.

Let’s look at some examples of how they work.

Filter Examples

Filters are very powerful in Graphweaver and they can be combined to deeply filter nested entities. To get an Idea of their usage here are some examples:

Filtering by ID

Retrieve a specific user by their ID:

{
  user(filter: { id: "12345" }) {
    id
    name
    email
  }
}

Retrieve multiple users by their IDs:

{
  users(filter: { id_in: ["12345", "67890"] }) {
    id
    name
    email
  }
}

Filtering by String

Retrieve all products with a name containing the word "apple":

{
  products(filter: { name_ilike: "%apple%" }) {
    id
    name
    price
  }
}

Retrieve products with a specific status:

{
  products(filter: { status: "active" }) {
    id
    name
    price
  }
}

Filtering by Number

Retrieve orders with a total greater than 100:

{
  orders(filter: { total_gt: 100 }) {
    id
    customer
    total
  }
}

Retrieve transactions within a specific amount range:

{
  transactions(filter: { amount_gte: 500, amount_lte: 1000 }) {
    id
    sender
    recipient
    amount
  }
}

Filtering by Date

Retrieve events that occurred after a certain date:

{
  events(filter: { date_gt: "2023-01-01" }) {
    id
    title
    date
  }
}

Retrieve tasks with a due date between two specific dates:

{
  tasks(filter: { dueDate_gte: "2023-05-01", dueDate_lte: "2023-05-31" }) {
    id
    title
    dueDate
  }
}

Remember, you can combine multiple filters to create more complex queries and further refine your data retrieval process.

Experiment with different operators and filter conditions to suit your specific use cases in Graphweaver.

Filter Operators

Graphweaver generates various operators for different field types to perform filtering operations. Let's explore the commonly generated filter operators and their functions:

ID Type

  • ne (Not Equal): Exclude values that match a specific ID.
  • in (In): Include values that match any of the specified IDs.
  • nin (Not In): Exclude values that match any of the specified IDs.
  • notnull: Include values that are not null.
  • null: Include values that are null.

String Type

  • ne (Not Equal): Exclude values that match a specific string.
  • in (In): Include values that match any of the specified strings.
  • nin (Not In): Exclude values that match any of the specified strings.
  • like: Include values that match a specific pattern (case-sensitive).
  • ilike: Include values that match a specific pattern (case-insensitive).
  • notnull: Include values that are not null.
  • null: Include values that are null.

Number, Date, ISOString Types

  • gt (Greater Than): Include values greater than a specified number or date.
  • gte (Greater Than or Equal): Include values greater than or equal to a specified number or date.
  • lt (Less Than): Include values less than a specified number or date.
  • lte (Less Than or Equal): Include values less than or equal to a specified number or date.
  • ne (Not Equal): Exclude values that match a specific number or date.
  • in (In): Include values that match any of the specified numbers or dates.
  • nin (Not In): Exclude values that match any of the specified numbers or dates.
  • notnull: Include values that are not null.
  • null: Include values that are null.

Conclusion

Understanding how filters work in Graphweaver and the associated operators is essential for efficiently retrieving the desired data subset from your graph database.

By leveraging the generated operators, you can create precise filter conditions to narrow down your data search.

Experiment with different filter combinations to explore and analyze your data.

image
Made with πŸ’œ in Australia

Exogee